Skip to content

Commit 2874451

Browse files
committed
Add JVM support in shared desktop app
1 parent 2cc8001 commit 2874451

File tree

12 files changed

+36
-41
lines changed

12 files changed

+36
-41
lines changed

demos/supabase-todolist/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
It is a simple to-do list application demonstrating use of the PowerSync Kotlin Mutiplatform SDK together
44
with [Supabase](https://supabase.com/) in a basic Kotlin Multiplatform Compose App.
55

6-
Supported KMP targets: Android and iOS.
6+
Supported KMP targets: Android, iOS and Desktop (JVM).
77

88
## Setting up your development environment
99

demos/supabase-todolist/desktopApp/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ kotlin {
1111
sourceSets {
1212
jvmMain.dependencies {
1313
implementation(compose.desktop.currentOs)
14-
implementation(project(":shared"))
14+
implementation(projects.shared)
1515
}
1616
}
1717
}

demos/supabase-todolist/gradle/libs.versions.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ junit = "4.13.2"
1818

1919
compose = "1.6.11"
2020
compose-preview = "1.7.2"
21+
lifecycle = "2.8.2"
2122

2223
# plugins
2324
android-gradle-plugin = "8.5.1"
@@ -49,13 +50,15 @@ ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "kto
4950
ktor-client-contentnegotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" }
5051
ktor-serialization-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
5152
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
53+
kotlinx-coroutines-swing = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-swing", version.ref = "coroutines" }
5254

5355
androidx-core = { group = "androidx.core", name = "core-ktx", version.ref = "androidx-core" }
5456
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "androidx-appcompat" }
5557
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity-compose" }
5658
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "androidx-espresso-core" }
5759
androidx-material = { group = "com.google.android.material", name = "material", version.ref = "androidx-material" }
5860
compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose-preview" }
61+
compose-lifecycle = { module = "org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "lifecycle" }
5962

6063
[plugins]
6164
androidApplication = { id = "com.android.application", version.ref = "android-gradle-plugin" }

demos/supabase-todolist/iosApp/iosApp.xcodeproj/project.pbxproj

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@
118118
7555FF79242A565900829871 /* Resources */,
119119
F85CB1118929364A9C6EFABC /* Frameworks */,
120120
3C5ACF3A4AAFF294B2A5839B /* [CP] Embed Pods Frameworks */,
121-
79E17356D7D971831C2A4119 /* [CP] Copy Pods Resources */,
122121
);
123122
buildRules = (
124123
);
@@ -231,23 +230,6 @@
231230
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
232231
showEnvVarsInLog = 0;
233232
};
234-
79E17356D7D971831C2A4119 /* [CP] Copy Pods Resources */ = {
235-
isa = PBXShellScriptBuildPhase;
236-
buildActionMask = 2147483647;
237-
files = (
238-
);
239-
inputFileListPaths = (
240-
"${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-resources-${CONFIGURATION}-input-files.xcfilelist",
241-
);
242-
name = "[CP] Copy Pods Resources";
243-
outputFileListPaths = (
244-
"${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-resources-${CONFIGURATION}-output-files.xcfilelist",
245-
);
246-
runOnlyForDeploymentPostprocessing = 0;
247-
shellPath = /bin/sh;
248-
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-resources.sh\"\n";
249-
showEnvVarsInLog = 0;
250-
};
251233
/* End PBXShellScriptBuildPhase section */
252234

253235
/* Begin PBXSourcesBuildPhase section */

demos/supabase-todolist/settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ rootProject.name = "supabase-todolist"
4343

4444
include(":androidApp")
4545
include(":shared")
46-
//include(":desktopApp")
46+
include(":desktopApp")
4747

4848
includeBuild("../..") {
4949
dependencySubstitution {

demos/supabase-todolist/shared/build.gradle.kts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ version = "1.0-SNAPSHOT"
1515
kotlin {
1616
androidTarget()
1717

18-
// jvm()
18+
jvm()
1919
iosX64()
2020
iosArm64()
2121
iosSimulatorArm64()
@@ -48,16 +48,18 @@ kotlin {
4848
implementation(compose.material)
4949
implementation(compose.components.resources)
5050
implementation(compose.materialIconsExtended)
51+
implementation(libs.compose.lifecycle)
5152
}
5253
androidMain.dependencies {
5354
api(libs.androidx.activity.compose)
5455
api(libs.androidx.appcompat)
5556
api(libs.androidx.core)
5657
}
5758

58-
// jvmMain.dependencies {
59-
// implementation(compose.desktop.common)
60-
// }
59+
jvmMain.dependencies {
60+
implementation(compose.desktop.common)
61+
implementation(libs.kotlinx.coroutines.swing)
62+
}
6163
}
6264
}
6365

demos/supabase-todolist/shared/src/commonMain/kotlin/com/powersync/demos/App.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import androidx.compose.runtime.rememberUpdatedState
1313
import androidx.compose.ui.Modifier
1414
import com.powersync.DatabaseDriverFactory
1515
import com.powersync.PowerSyncDatabase
16+
import com.powersync.bucket.BucketPriority
1617
import com.powersync.connector.supabase.SupabaseConnector
1718
import com.powersync.demos.components.EditDialog
1819
import com.powersync.demos.powersync.ListContent
@@ -36,9 +37,15 @@ fun App(factory: DatabaseDriverFactory, modifier: Modifier = Modifier) {
3637
)
3738
}
3839
val db = remember { PowerSyncDatabase(factory, schema) }
39-
val status = db.currentStatus.asFlow().collectAsState(initial = null)
40-
val hasSynced by remember { derivedStateOf { status.value?.hasSynced } }
41-
40+
val status by db.currentStatus.asFlow().collectAsState(initial = db.currentStatus)
41+
42+
// This assumes that the buckets for lists has a priority of 1 (but it will work fine with sync
43+
// rules not defining any priorities at all too). When giving lists a higher priority than
44+
// items, we can have a consistent snapshot of lists without items. In the case where many items
45+
// exist (that might take longer to sync initially), this allows us to display lists earlier.
46+
val hasSyncedLists by remember {
47+
derivedStateOf { status.statusForPriority(BucketPriority(1)).hasSynced }
48+
}
4249

4350
val navController = remember { NavController(Screen.Home) }
4451
val authViewModel = remember {
@@ -86,14 +93,14 @@ fun App(factory: DatabaseDriverFactory, modifier: Modifier = Modifier) {
8693
HomeScreen(
8794
modifier = modifier.background(MaterialTheme.colors.background),
8895
items = items,
89-
isConnected = status.value?.connected,
96+
isConnected = status.connected,
9097
onSignOutSelected = { handleSignOut() },
9198
inputText = listsInputText,
9299
onItemClicked = handleOnItemClicked,
93100
onItemDeleteClicked = lists.value::onItemDeleteClicked,
94101
onAddItemClicked = lists.value::onAddItemClicked,
95102
onInputTextChanged = lists.value::onInputTextChanged,
96-
hasSynced = hasSynced
103+
hasSynced = hasSyncedLists
97104
)
98105
}
99106

@@ -106,7 +113,7 @@ fun App(factory: DatabaseDriverFactory, modifier: Modifier = Modifier) {
106113
modifier = modifier.background(MaterialTheme.colors.background),
107114
navController = navController,
108115
items = todoItems,
109-
isConnected = status.value?.connected,
116+
isConnected = status.connected,
110117
inputText = todosInputText,
111118
onItemClicked = todos.value::onItemClicked,
112119
onItemDoneChanged = todos.value::onItemDoneChanged,

demos/supabase-todolist/shared/src/commonMain/kotlin/com/powersync/demos/screens/HomeScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ internal fun HomeScreen(
2828
modifier: Modifier = Modifier,
2929
items: List<ListItem>,
3030
inputText: String,
31-
isConnected: Boolean?,
31+
isConnected: Boolean,
3232
hasSynced: Boolean?,
3333
onSignOutSelected: () -> Unit,
3434
onItemClicked: (item: ListItem) -> Unit,
@@ -49,7 +49,7 @@ internal fun HomeScreen(
4949
onSignOutSelected
5050
) },
5151
actions = {
52-
WifiIcon(isConnected ?: false)
52+
WifiIcon(isConnected)
5353
Spacer(modifier = Modifier.width(16.dp))
5454
}
5555
)

demos/supabase-todolist/shared/src/commonMain/kotlin/com/powersync/demos/screens/TodosScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ internal fun TodosScreen(
3232
navController: NavController,
3333
items: List<TodoItem>,
3434
inputText: String,
35-
isConnected: Boolean?,
35+
isConnected: Boolean,
3636
onItemClicked: (item: TodoItem) -> Unit,
3737
onItemDoneChanged: (item: TodoItem, isDone: Boolean) -> Unit,
3838
onItemDeleteClicked: (item: TodoItem) -> Unit,
@@ -53,7 +53,7 @@ internal fun TodosScreen(
5353
}
5454
},
5555
actions = {
56-
WifiIcon(isConnected ?: false)
56+
WifiIcon(isConnected)
5757
Spacer(modifier = Modifier.width(16.dp))
5858
}
5959
)

demos/supabase-todolist/shared/src/desktopMain/kotlin/main.desktop.kt

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)