Skip to content

Commit

Permalink
Implement Desktop app setup for ComposeMultiplatform (openMF#1716)
Browse files Browse the repository at this point in the history
* Implement DesktopSetup for ComposeMultiplatform

* Configure windows DesktopSetup
  • Loading branch information
AdityaKumdale authored Aug 14, 2024
1 parent 15d47f7 commit 62993d3
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class AndroidFeatureConventionPlugin : Plugin<Project> {
add("implementation", project(":core:ui"))
add("implementation", project(":core:designsystem"))
add("implementation", project(":shared"))
add("implementation", project(":desktop"))

add("implementation", libs.findLibrary("androidx.material.navigation").get())
add("implementation", libs.findLibrary("androidx.hilt.navigation.compose").get())
Expand Down
43 changes: 43 additions & 0 deletions desktop/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import org.jetbrains.compose.desktop.application.dsl.TargetFormat

plugins {
kotlin("multiplatform")
alias(libs.plugins.jetbrainsCompose)
}


kotlin {
jvm {
jvmToolchain(17)
withJava()
}

sourceSets {
val jvmMain by getting {
dependencies {
implementation(project(":shared"))
implementation(compose.desktop.currentOs)
}
}
}
}

compose.desktop {
application {
mainClass = "MainKt"
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "org.mifospay.desktop"
packageVersion = "1.0.0"
windows {
// a version for all Windows distributables
packageVersion = "1.0.0"
// a version only for the msi package
msiPackageVersion = "1.0.0"
// a version only for the exe package
exePackageVersion = "1.0.0"
menu = true
}
}
}
}
17 changes: 17 additions & 0 deletions desktop/src/jvmMain/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import androidx.compose.ui.window.rememberWindowState
import org.mifospay.shared.MainView

fun main() {
application {
val windowState = rememberWindowState()
Window(
onCloseRequest = ::exitApplication,
state = windowState,
title = "MifosWallet"
) {
MainView()
}
}
}
10 changes: 6 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ androidxHilt = "1.2.0"
androidxLifecycle = "2.8.4"
hilt = "2.51.1"
junit = "4.13.2"
kotlin = "1.9.25"
ksp = "1.9.25-1.0.20"
firebaseCrashlyticsPlugin = "3.0.2"
gmsPlugin = "4.4.2"
kotlin = "1.9.22"
compose-plugin = "1.6.1"
ksp = "1.9.22-1.0.18"
firebaseCrashlyticsPlugin = "2.9.9"
gmsPlugin = "4.4.1"
butterknifePlugin = "10.2.3"
secrets = "2.0.1"
lifecycleVersion = "2.8.4"
Expand Down Expand Up @@ -198,6 +199,7 @@ spotless-gradle = { group = "com.diffplug.spotless", name = "spotless-plugin-gra


[plugins]
jetbrainsCompose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" }
android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }
android-library = { id = "com.android.library", version.ref = "androidGradlePlugin" }
gms = { id = "com.google.gms.google-services", version.ref = "gmsPlugin" }
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ include(":feature:upi-setup")
include(":feature:qr")
include(":feature:home")
include(":shared")
include(":desktop")
17 changes: 16 additions & 1 deletion shared/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
kotlin("multiplatform")
id("com.android.library")
alias(libs.plugins.jetbrainsCompose)
}

kotlin {
Expand All @@ -11,7 +12,11 @@ kotlin {
}
}
}


jvm("desktop"){
jvmToolchain(17)
}

listOf(
iosX64(),
iosArm64(),
Expand All @@ -26,6 +31,16 @@ kotlin {
sourceSets {
commonMain.dependencies {
//put your multiplatform dependencies here
implementation(compose.material)
implementation(compose.material3)
}

val desktopMain by getting {
dependencies {
// Desktop specific dependencies
implementation(compose.desktop.currentOs)
implementation(compose.desktop.common)
}
}
}
task("testClasses")
Expand Down
26 changes: 26 additions & 0 deletions shared/src/commonMain/kotlin/org/mifospay/shared/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.mifospay.shared

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.Text
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight


@Composable
fun App() {
Box(
modifier = Modifier
.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Text(
text = "MifosWallet",
style = MaterialTheme.typography.titleLarge.copy(fontWeight = FontWeight.Bold),
color = MaterialTheme.colorScheme.onSurface,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.mifospay.shared

import androidx.compose.runtime.Composable

@Composable
fun MainView() = App()

class JVMPlatform: Platform {
override val name: String ="Windows"
}

actual fun getPlatform(): Platform = JVMPlatform()

0 comments on commit 62993d3

Please sign in to comment.