Skip to content

Commit 3cc1482

Browse files
committed
feat: Integrate reactive Dark Mode detection for all desktop OS and adaptive top bar on Windows
- Replace the use of isSystemInDarkTheme with isSystemInDarkMode to handle real-time theme changes across all desktop operating systems. - Add Windows top bar configuration using setWindowsAdaptiveTitleBar(). - Currently, the top bar only follows the system theme and does not sync with the user's explicit preferences. more information at https://github.com/kdroidFilter/Platform-Tools?tab=readme-ov-file#-dark-mode-detection-module
1 parent 6194a86 commit 3cc1482

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

application/composeApp/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ kotlin {
6262
implementation(libs.room.runtime)
6363

6464
implementation(libs.compose.navigation)
65+
implementation(libs.platformtools.darkmodedetector)
66+
6567
}
6668
}
6769

application/composeApp/src/jvmMain/kotlin/io/writeopia/desktop/MainDesktop.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import androidx.compose.material.CircularProgressIndicator
66
import androidx.compose.runtime.Composable
77
import androidx.compose.runtime.LaunchedEffect
88
import androidx.compose.runtime.collectAsState
9+
import androidx.compose.runtime.getValue
910
import androidx.compose.runtime.rememberCoroutineScope
1011
import androidx.compose.ui.Alignment
1112
import androidx.compose.ui.Modifier
@@ -18,8 +19,11 @@ import androidx.compose.ui.window.WindowPlacement
1819
import androidx.compose.ui.window.WindowPosition
1920
import androidx.compose.ui.window.application
2021
import androidx.compose.ui.window.rememberWindowState
22+
import io.github.kdroidfilter.platformtools.darkmodedetector.isSystemInDarkMode
23+
import io.github.kdroidfilter.platformtools.darkmodedetector.windows.setWindowsAdaptiveTitleBar
2124
import io.writeopia.common.utils.keyboard.KeyboardCommands
2225
import io.writeopia.common.utils.ui.GlobalToastBox
26+
import io.writeopia.model.isDarkTheme
2327
import io.writeopia.notemenu.di.UiConfigurationInjector
2428
import io.writeopia.notes.desktop.components.DesktopApp
2529
import io.writeopia.resources.CommonImages
@@ -152,7 +156,6 @@ private fun ApplicationScope.App(onCloseRequest: () -> Unit = ::exitApplication)
152156
windowState.placement = WindowPlacement.Floating
153157
}
154158
}
155-
156159
Window(
157160
onCloseRequest = onCloseRequest,
158161
title = "",
@@ -162,6 +165,11 @@ private fun ApplicationScope.App(onCloseRequest: () -> Unit = ::exitApplication)
162165
},
163166
icon = CommonImages.logo()
164167
) {
168+
//Synchronize the topbar on Windows OS with the System Theme
169+
window.setWindowsAdaptiveTitleBar(
170+
dark = isSystemInDarkMode() //TODO Syncrhonize with the selected Theme by the user
171+
)
172+
165173
Box(Modifier.fillMaxSize()) {
166174
LaunchedEffect(window.rootPane) {
167175
with(window.rootPane) {

application/core/theme/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ kotlin {
3737

3838
implementation(compose.material3)
3939
implementation(libs.lifecycle.viewmodel.compose)
40+
implementation(libs.platformtools.darkmodedetector)
4041
}
4142
}
4243

application/core/theme/src/commonMain/kotlin/io/writeopia/model/ColorThemeOption.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.writeopia.model
22

3-
import androidx.compose.foundation.isSystemInDarkTheme
43
import androidx.compose.runtime.Composable
4+
import io.github.kdroidfilter.platformtools.darkmodedetector.isSystemInDarkMode
55

66
enum class ColorThemeOption(val theme: String) {
77
LIGHT("light"),
@@ -20,6 +20,6 @@ fun ColorThemeOption?.isDarkTheme(): Boolean =
2020
when (this) {
2121
ColorThemeOption.LIGHT -> false
2222
ColorThemeOption.DARK -> true
23-
ColorThemeOption.SYSTEM -> isSystemInDarkTheme()
24-
else -> isSystemInDarkTheme()
23+
ColorThemeOption.SYSTEM -> isSystemInDarkMode()
24+
else -> isSystemInDarkMode()
2525
}

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ ktlint = "12.1.2"
1616
ktx = "1.15.0"
1717
appCompat = "1.7.0"
1818
material = "1.12.0"
19+
platformtoolsDarkmodedetector = "0.2.7"
1920
postgresSocketFactory = "1.15.1"
2021
room = "2.7.0-beta01"
2122
compose = "2.8.7"
@@ -85,6 +86,7 @@ ktor-server-websocket = { module = "io.ktor:ktor-server-websockets-jvm" }
8586
ktor-server-netty = { module = "io.ktor:ktor-server-netty-jvm" }
8687
ktor-server-tests = { module = "io.ktor:ktor-server-test-host", version.ref = "ktor" }
8788
#material3-desktop = { module = "org.jetbrains.compose.material3:material3-desktop", version.ref = "material3" }
89+
platformtools-darkmodedetector = { module = "io.github.kdroidfilter:platformtools.darkmodedetector", version.ref = "platformtoolsDarkmodedetector" }
8890
sql-postgres-socket-factory = { module = "com.google.cloud.sql:postgres-socket-factory", version.ref = "postgresSocketFactory" }
8991
room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" }
9092
room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" }

0 commit comments

Comments
 (0)