-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #496 from icerockdev/develop
Release 0.22.3
- Loading branch information
Showing
10 changed files
with
252 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
samples/compose-resources-gallery/macosApp/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink | ||
import java.io.File | ||
import kotlin.reflect.full.declaredMemberProperties | ||
|
||
plugins { | ||
kotlin("multiplatform") | ||
id("org.jetbrains.compose") | ||
id("dev.icerock.mobile.multiplatform-resources") | ||
} | ||
|
||
version = "0.1.0" | ||
|
||
kotlin { | ||
macosX64 { | ||
binaries { | ||
executable { | ||
entryPoint = "main" | ||
freeCompilerArgs += listOf( | ||
"-linker-option", "-framework", "-linker-option", "Metal" | ||
) | ||
} | ||
} | ||
} | ||
|
||
macosArm64 { | ||
binaries { | ||
executable { | ||
entryPoint = "main" | ||
freeCompilerArgs += listOf( | ||
"-linker-option", "-framework", "-linker-option", "Metal" | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Suppress("UNUSED_VARIABLE") | ||
sourceSets { | ||
val commonMain by getting { | ||
dependencies { | ||
api(project(":shared")) | ||
} | ||
} | ||
} | ||
} | ||
|
||
compose.desktop.nativeApplication { | ||
targets(kotlin.targets.getByName("macosX64"), kotlin.targets.getByName("macosArm64")) | ||
distributions { | ||
targetFormats(org.jetbrains.compose.desktop.application.dsl.TargetFormat.Dmg) | ||
packageName = "dev.icerock.moko.resources.sample" | ||
packageVersion = "0.1.0" | ||
} | ||
} | ||
|
||
kotlin { | ||
targets.withType<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget> { | ||
binaries.all { | ||
// TODO: the current compose binary surprises LLVM, so disable checks for now. | ||
freeCompilerArgs += "-Xdisable-phases=VerifyBitcode" | ||
} | ||
} | ||
} | ||
|
||
multiplatformResources { | ||
multiplatformResourcesPackage = "dev.icerock.moko.resources.sample" | ||
} | ||
|
||
// TODO move to moko-resources gradle plugin | ||
// copy .bundle from all .klib to .kexe | ||
tasks.withType<KotlinNativeLink>() | ||
.configureEach { | ||
val linkTask: KotlinNativeLink = this | ||
val outputDir: File = this.outputFile.get().parentFile | ||
|
||
@Suppress("ObjectLiteralToLambda") // lambda broke up-to-date | ||
val action = object : Action<Task> { | ||
override fun execute(t: Task) { | ||
(linkTask.libraries + linkTask.sources) | ||
.filter { library -> library.extension == "klib" } | ||
.filter(File::exists) | ||
.forEach { inputFile -> | ||
val klibKonan = org.jetbrains.kotlin.konan.file.File(inputFile.path) | ||
val klib = org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl( | ||
klib = klibKonan, | ||
component = "default" | ||
) | ||
val layout = klib.extractingToTemp | ||
|
||
// extracting bundles | ||
layout | ||
.resourcesDir | ||
.absolutePath | ||
.let(::File) | ||
.listFiles { file: File -> file.extension == "bundle" } | ||
// copying bundles to app | ||
?.forEach { | ||
logger.info("${it.absolutePath} copying to $outputDir") | ||
it.copyRecursively( | ||
target = File(outputDir, it.name), | ||
overwrite = true | ||
) | ||
} | ||
} | ||
} | ||
} | ||
doLast(action) | ||
} | ||
|
||
// TODO move to moko-resources gradle plugin | ||
// copy .bundle from .kexe to .app | ||
tasks.withType<org.jetbrains.compose.experimental.uikit.tasks.ExperimentalPackComposeApplicationForXCodeTask>() | ||
.configureEach { | ||
val packTask: org.jetbrains.compose.experimental.uikit.tasks.ExperimentalPackComposeApplicationForXCodeTask = | ||
this | ||
|
||
val kclass = | ||
org.jetbrains.compose.experimental.uikit.tasks.ExperimentalPackComposeApplicationForXCodeTask::class | ||
val kotlinBinaryField = | ||
kclass.declaredMemberProperties.single { it.name == "kotlinBinary" } | ||
val destinationDirField = | ||
kclass.declaredMemberProperties.single { it.name == "destinationDir" } | ||
val executablePathField = | ||
kclass.declaredMemberProperties.single { it.name == "executablePath" } | ||
|
||
@Suppress("ObjectLiteralToLambda") // lambda broke up-to-date | ||
val action = object : Action<Task> { | ||
override fun execute(t: Task) { | ||
val kotlinBinary: RegularFile = | ||
(kotlinBinaryField.get(packTask) as RegularFileProperty).get() | ||
val destinationDir: Directory = | ||
(destinationDirField.get(packTask) as DirectoryProperty).get() | ||
val executablePath: String = | ||
(executablePathField.get(packTask) as Provider<*>).get().toString() | ||
|
||
val outputDir: File = File(destinationDir.asFile, executablePath).parentFile | ||
|
||
val bundleSearchDir: File = kotlinBinary.asFile.parentFile | ||
bundleSearchDir | ||
.listFiles { file: File -> file.extension == "bundle" } | ||
?.forEach { file -> | ||
file.copyRecursively(File(outputDir, file.name), true) | ||
} | ||
} | ||
} | ||
doLast(action) | ||
} |
35 changes: 35 additions & 0 deletions
35
samples/compose-resources-gallery/macosApp/src/commonMain/kotlin/Main.macos.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import androidx.compose.ui.window.Window | ||
import com.icerockdev.library.MR | ||
import dev.icerock.moko.resources.desc.desc | ||
import kotlinx.cinterop.staticCFunction | ||
import platform.AppKit.NSApplication | ||
import platform.AppKit.NSApplicationActivationPolicy | ||
import platform.AppKit.NSApplicationDelegateProtocol | ||
import platform.darwin.NSObject | ||
import platform.objc.objc_setUncaughtExceptionHandler | ||
|
||
@Suppress("UNUSED_PARAMETER") | ||
fun main(args: Array<String>) { | ||
setUnhandledExceptionHook { | ||
it.printStackTrace() | ||
} | ||
|
||
objc_setUncaughtExceptionHandler(staticCFunction<Any?, Unit> { | ||
println(it) | ||
}) | ||
|
||
val app = NSApplication.sharedApplication() | ||
app.setActivationPolicy(NSApplicationActivationPolicy.NSApplicationActivationPolicyRegular) | ||
|
||
app.delegate = object : NSObject(), NSApplicationDelegateProtocol { | ||
override fun applicationShouldTerminateAfterLastWindowClosed(sender: NSApplication): Boolean { | ||
return true | ||
} | ||
} | ||
|
||
Window(MR.strings.hello_world.desc().localized()) { | ||
MacosApp() | ||
} | ||
|
||
app.run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,3 +40,4 @@ include(":androidApp") | |
include(":shared") | ||
include(":desktopApp") | ||
include(":webApp") | ||
include(":macosApp") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
samples/compose-resources-gallery/shared/src/macosMain/kotlin/main.macos.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import androidx.compose.runtime.Composable | ||
|
||
actual fun getPlatformName(): String = "macOS" | ||
|
||
@Composable | ||
fun MacosApp() { | ||
App() | ||
} |