From b59917c9688075cb25d4bd824f5f133940d805fd Mon Sep 17 00:00:00 2001 From: Michael Rittmeister Date: Sun, 29 Sep 2024 03:00:23 +0200 Subject: [PATCH] Use new resource library --- app/desktop/build.gradle.kts | 16 ++++++++++++++-- .../drawable}/logo.png | Bin app/desktop/src/main/kotlin/Main.kt | 5 ++--- 3 files changed, 16 insertions(+), 5 deletions(-) rename app/desktop/src/main/{resources => composeResources/drawable}/logo.png (100%) diff --git a/app/desktop/build.gradle.kts b/app/desktop/build.gradle.kts index e5b59471..6e8315f8 100644 --- a/app/desktop/build.gradle.kts +++ b/app/desktop/build.gradle.kts @@ -17,8 +17,9 @@ dependencies { implementation(project.dependencies.compose.materialIconsExtended) implementation(project.dependencies.compose.material3) implementation(libs.logback) + implementation(compose.components.resources) - if(windowsBuild) { + if (windowsBuild) { implementation(projects.app.desktop.uwpHelper) } else { implementation(libs.ktor.server.netty) @@ -28,7 +29,9 @@ dependencies { sourceSets { main { - if(windowsBuild) { + kotlin.srcDir("build/generated/compose/resourceGenerator/kotlin/commonResClass") + kotlin.srcDir("build/generated/compose/resourceGenerator/kotlin/mainResourceAccessors") + if (windowsBuild) { kotlin.srcDir("src/windowsMain/kotlin") } else { kotlin.srcDir("src/nonWindowsMain/kotlin") @@ -92,6 +95,15 @@ compose.desktop { } } +compose.resources { + publicResClass = false + packageOfResClass = "dev.schlaubi.tonbrett.app.desktop" + customDirectory( + sourceSetName = "main", + directoryProvider = provider { layout.projectDirectory.dir("src/main/composeResources") } + ) +} + tasks { register("packageDistributable") { from(named("createReleaseDistributable")) diff --git a/app/desktop/src/main/resources/logo.png b/app/desktop/src/main/composeResources/drawable/logo.png similarity index 100% rename from app/desktop/src/main/resources/logo.png rename to app/desktop/src/main/composeResources/drawable/logo.png diff --git a/app/desktop/src/main/kotlin/Main.kt b/app/desktop/src/main/kotlin/Main.kt index ad082725..ef73e897 100644 --- a/app/desktop/src/main/kotlin/Main.kt +++ b/app/desktop/src/main/kotlin/Main.kt @@ -16,8 +16,6 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.painter.BitmapPainter -import androidx.compose.ui.res.loadImageBitmap -import androidx.compose.ui.res.useResource import androidx.compose.ui.window.* import cafe.adriel.lyricist.LocalStrings import dev.schlaubi.tonbrett.app.ColorScheme @@ -29,6 +27,7 @@ import dev.schlaubi.tonbrett.app.desktop.Platform.start import dev.schlaubi.tonbrett.app.title import io.github.oshai.kotlinlogging.KotlinLogging import io.ktor.serialization.* +import org.jetbrains.compose.resources.imageResource import java.net.URI import java.awt.Window as AWTWindow @@ -103,7 +102,7 @@ private fun ApplicationScope.startActualApplication( fun ApplicationScope.TonbrettWindow(content: @Composable FrameWindowScope.() -> Unit) = Window( onCloseRequest = ::exitApplication, title = title, - icon = BitmapPainter(useResource("logo.png", ::loadImageBitmap)), + icon = BitmapPainter(imageResource(Res.drawable.logo)) ) { ProvideLocalWindow(window) { content()