From 8512178a24d4b8f67b7dfb1e4c2c83db44cff587 Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Fri, 29 Mar 2024 11:45:15 -0700 Subject: [PATCH] Restore the desktop target. - We are not targetting desktop for the time being, but unfortunately the IDE previews (which are very useful when developing UI) are only available for the Desktop target for now. It is worth keeping the desktop target just for that. We won't be spending much time focusing on desktop though. - Updated Compose multiplatform plugin and Kotlin versions. - Added coroutines swing dependency to be ablet o run the desktop app. --- composeApp/build.gradle.kts | 25 ++++++++++++++++++- .../importaccount/ImportAccountScreen.kt | 2 +- .../kotlin/net/agorise/kee/Platform.jvm.kt | 7 ++++++ .../kotlin/net/agorise/kee/main.kt | 20 +++++++++++++++ gradle/libs.versions.toml | 7 +++--- shared/preferences/build.gradle.kts | 2 ++ .../shared/preferences/KeePreferences.kt | 4 +-- shared/stargate/build.gradle.kts | 2 ++ .../agorise/shared/stargate/StargateBridge.kt | 4 +-- 9 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 composeApp/src/desktopMain/kotlin/net/agorise/kee/Platform.jvm.kt create mode 100644 composeApp/src/desktopMain/kotlin/net/agorise/kee/main.kt diff --git a/composeApp/build.gradle.kts b/composeApp/build.gradle.kts index fa6cdfa..c0f0453 100644 --- a/composeApp/build.gradle.kts +++ b/composeApp/build.gradle.kts @@ -1,3 +1,5 @@ +import org.jetbrains.compose.desktop.application.dsl.TargetFormat + plugins { alias(libs.plugins.kotlinMultiplatform) alias(libs.plugins.androidApplication) @@ -12,7 +14,9 @@ kotlin { } } } - + + jvm("desktop") + listOf( iosX64(), iosArm64(), @@ -49,6 +53,12 @@ kotlin { } } + val desktopMain by getting + desktopMain.dependencies { + implementation(compose.desktop.currentOs) + implementation(libs.coroutines.swing) + } + val iosX64Main by getting val iosArm64Main by getting val iosSimulatorArm64Main by getting @@ -95,3 +105,16 @@ android { debugImplementation(libs.compose.ui.tooling) } } + +compose.desktop { + application { + mainClass = "MainKt" + + nativeDistributions { + targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) + packageName = "net.agorise.kee" + packageVersion = "1.0.0" + } + } +} + diff --git a/composeApp/src/commonMain/kotlin/net/agorise/kee/ui/screen/importaccount/ImportAccountScreen.kt b/composeApp/src/commonMain/kotlin/net/agorise/kee/ui/screen/importaccount/ImportAccountScreen.kt index 8eeb496..3bb0a91 100644 --- a/composeApp/src/commonMain/kotlin/net/agorise/kee/ui/screen/importaccount/ImportAccountScreen.kt +++ b/composeApp/src/commonMain/kotlin/net/agorise/kee/ui/screen/importaccount/ImportAccountScreen.kt @@ -95,5 +95,5 @@ private fun ImportAccountScreenContentLightPreview() = KeeTheme(useDarkTheme = f @Preview @Composable private fun ImportAccountScreenContentDarkPreview() = KeeTheme(useDarkTheme = true) { - ImportAccountScreenContent(ImportAccountScreenModel.State()) + ImportAccountScreenContent(ImportAccountScreenModel.State(blockCount = 265482)) } diff --git a/composeApp/src/desktopMain/kotlin/net/agorise/kee/Platform.jvm.kt b/composeApp/src/desktopMain/kotlin/net/agorise/kee/Platform.jvm.kt new file mode 100644 index 0000000..90a123b --- /dev/null +++ b/composeApp/src/desktopMain/kotlin/net/agorise/kee/Platform.jvm.kt @@ -0,0 +1,7 @@ +package net.agorise.kee + +class JVMPlatform: Platform { + override val name: String = "Java ${System.getProperty("java.version")}" +} + +actual fun getPlatform(): Platform = JVMPlatform() diff --git a/composeApp/src/desktopMain/kotlin/net/agorise/kee/main.kt b/composeApp/src/desktopMain/kotlin/net/agorise/kee/main.kt new file mode 100644 index 0000000..7f907ae --- /dev/null +++ b/composeApp/src/desktopMain/kotlin/net/agorise/kee/main.kt @@ -0,0 +1,20 @@ +package net.agorise.kee + + import androidx.compose.ui.unit.DpSize +import androidx.compose.ui.unit.dp +import androidx.compose.ui.window.Window +import androidx.compose.ui.window.WindowPosition +import androidx.compose.ui.window.application +import androidx.compose.ui.window.rememberWindowState +import cafe.adriel.voyager.navigator.Navigator +import net.agorise.kee.ui.screen.home.HomeScreen + +fun main() = application { + val state = rememberWindowState( + size = DpSize(420.dp, 880.dp), + position = WindowPosition(300.dp, 300.dp) + ) + Window(title = "Kee", onCloseRequest = ::exitApplication, state = state) { + Navigator(HomeScreen()) + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f5842ba..e7b5f62 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -5,9 +5,9 @@ android-minSdk = "26" android-targetSdk = "34" androidx-activityCompose = "1.8.2" compose = "1.6.4" -compose-plugin = "1.6.0" +compose-plugin = "1.6.1" coroutines = "1.8.0" -kotlin = "1.9.22" +kotlin = "1.9.23" ktor = "2.3.9" multiplatform-settings = "1.1.1" voyager = "1.0.0" @@ -16,7 +16,8 @@ voyager = "1.0.0" androidx-activity-compose = { group = "androidx.activity", name ="activity-compose", version.ref = "androidx-activityCompose" } compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling", version.ref = "compose" } compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview", version.ref = "compose" } -coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" } +coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "coroutines" } +coroutines-swing = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-swing", version.ref = "coroutines" } ktor-client-cio = { group = "io.ktor", name = "ktor-client-cio", version.ref = "ktor" } ktor-client-core = { group = "io.ktor", name = "ktor-client-core", version.ref = "ktor" } ktor-client-websockets = { group = "io.ktor", name = "ktor-client-websockets", version.ref = "ktor" } diff --git a/shared/preferences/build.gradle.kts b/shared/preferences/build.gradle.kts index b9a1478..c7cf725 100644 --- a/shared/preferences/build.gradle.kts +++ b/shared/preferences/build.gradle.kts @@ -12,6 +12,8 @@ kotlin { } } + jvm() + iosX64() iosArm64() iosSimulatorArm64() diff --git a/shared/preferences/src/commonMain/kotlin/net/agorise/shared/preferences/KeePreferences.kt b/shared/preferences/src/commonMain/kotlin/net/agorise/shared/preferences/KeePreferences.kt index 1835212..b719a00 100644 --- a/shared/preferences/src/commonMain/kotlin/net/agorise/shared/preferences/KeePreferences.kt +++ b/shared/preferences/src/commonMain/kotlin/net/agorise/shared/preferences/KeePreferences.kt @@ -8,10 +8,10 @@ import com.russhwolf.settings.Settings object KeePreferences { // TODO Use a stronger implementation that allows encryption private val settings: Settings = Settings() - + // Keys used to store/retrieve preferences private const val KEY_RECOVERY_WORDS = "key_recovery_words" - + fun isAccountActive(): Boolean { return settings.hasKey(KEY_RECOVERY_WORDS) } diff --git a/shared/stargate/build.gradle.kts b/shared/stargate/build.gradle.kts index e367c06..5a47abe 100644 --- a/shared/stargate/build.gradle.kts +++ b/shared/stargate/build.gradle.kts @@ -12,6 +12,8 @@ kotlin { } } + jvm() + iosX64() iosArm64() iosSimulatorArm64() diff --git a/shared/stargate/src/commonMain/kotlin/net/agorise/shared/stargate/StargateBridge.kt b/shared/stargate/src/commonMain/kotlin/net/agorise/shared/stargate/StargateBridge.kt index 211eb52..12ae331 100644 --- a/shared/stargate/src/commonMain/kotlin/net/agorise/shared/stargate/StargateBridge.kt +++ b/shared/stargate/src/commonMain/kotlin/net/agorise/shared/stargate/StargateBridge.kt @@ -52,7 +52,7 @@ class StargateBridge { incoming.receiveAsFlow().collect { message -> (message as? Frame.Text)?.let { textFrame -> val text = textFrame.readText() - println(text) + println("Received -> $text") if (text.contains("\"method\":\"Block\"")) { blockBroadcastChannel.send(true) } else if (text.contains("\"count\":")) { @@ -68,7 +68,7 @@ class StargateBridge { private suspend fun DefaultClientWebSocketSession.writeMessages() { blockBroadcastChannel.receiveAsFlow().onEach { val blockCountRequest = getBlockCountRequest() - println("Requesting: $blockCountRequest") + println("Sent -> $blockCountRequest") outgoing.send(Frame.Text(blockCountRequest)) }.launchIn(this) }