Skip to content

Commit cd91000

Browse files
authored
feat: Integrate reactive Dark Mode detection for all desktop OS (#368)
* 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 * Update dependencies for dark mode detector and AGP. Bumped platformtoolsDarkmodedetector to 0.2.8 and downgraded AGP to 8.6.1 to ensure compatibility and stability. Changes help maintain synchronization between dependencies. * Update dark mode detection to use platformtools library Replaced `isSystemInDarkTheme()` with `isSystemInDarkMode()` for dark mode detection using the `platformtools` library. Updated dependency version to `0.2.9` and replaced references in theme configuration and desktop app setup. Ensure compatibility and alignment with the updated library API.
1 parent 015520c commit cd91000

6 files changed

Lines changed: 19 additions & 12 deletions

File tree

application/composeApp/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ kotlin {
6464
implementation(libs.room.runtime)
6565

6666
implementation(libs.compose.navigation)
67+
implementation(libs.platformtools.darkmodedetector)
6768
}
6869
}
6970

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@ import androidx.compose.ui.Alignment
1111
import androidx.compose.ui.Modifier
1212
import androidx.compose.ui.input.key.KeyEvent
1313
import androidx.compose.ui.unit.dp
14-
import androidx.compose.ui.window.ApplicationScope
15-
import androidx.compose.ui.window.Window
16-
import androidx.compose.ui.window.WindowPlacement
17-
import androidx.compose.ui.window.WindowPosition
18-
import androidx.compose.ui.window.application
19-
import androidx.compose.ui.window.rememberWindowState
14+
import androidx.compose.ui.window.*
15+
import io.github.kdroidfilter.platformtools.darkmodedetector.isSystemInDarkMode
16+
import io.github.kdroidfilter.platformtools.darkmodedetector.windows.setWindowsAdaptiveTitleBar
2017
import io.writeopia.common.utils.keyboard.KeyboardCommands
2118
import io.writeopia.common.utils.keyboard.isMultiSelectionTrigger
2219
import io.writeopia.common.utils.ui.GlobalToastBox
@@ -167,7 +164,6 @@ private fun ApplicationScope.App(onCloseRequest: () -> Unit = ::exitApplication)
167164
windowState.placement = WindowPlacement.Floating
168165
}
169166
}
170-
171167
Window(
172168
onCloseRequest = onCloseRequest,
173169
title = "",
@@ -177,6 +173,12 @@ private fun ApplicationScope.App(onCloseRequest: () -> Unit = ::exitApplication)
177173
},
178174
icon = CommonImages.logo()
179175
) {
176+
// Synchronize the topbar on Windows OS with the System Theme
177+
window.setWindowsAdaptiveTitleBar(
178+
dark = isSystemInDarkMode()
179+
// TODO Syncrhonize with the selected Theme by the user
180+
)
181+
180182
Box(Modifier.fillMaxSize()) {
181183
LaunchedEffect(window.rootPane) {
182184
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
}

application/core/theme/src/commonMain/kotlin/io/writeopia/theme/Theme.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.writeopia.theme
22

3-
import androidx.compose.foundation.isSystemInDarkTheme
43
import androidx.compose.material3.MaterialTheme
54
import androidx.compose.material3.darkColorScheme
65
import androidx.compose.material3.lightColorScheme
@@ -9,6 +8,7 @@ import androidx.compose.runtime.CompositionLocalProvider
98
import androidx.compose.runtime.Immutable
109
import androidx.compose.runtime.staticCompositionLocalOf
1110
import androidx.compose.ui.graphics.Color
11+
import io.github.kdroidfilter.platformtools.darkmodedetector.isSystemInDarkMode
1212

1313
private val DarkColorPalette = darkColorScheme(
1414
primary = LIGHT_PURPLE,
@@ -71,7 +71,7 @@ val LocalWriteopiaColors = staticCompositionLocalOf {
7171

7272
@Composable
7373
fun WrieopiaTheme(
74-
darkTheme: Boolean = isSystemInDarkTheme(),
74+
darkTheme: Boolean = isSystemInDarkMode(),
7575
content: @Composable () -> Unit
7676
) {
7777
val globalBackground = if (darkTheme) Color(0xFF252525) else Color(0xFFF8F0F9)

gradle/libs.versions.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ktor = "3.0.3"
1515
ktlint = "12.1.2"
1616
ktx = "1.15.0"
1717
material = "1.12.0"
18+
platformtools = "0.2.9"
1819
postgresSocketFactory = "1.15.1"
1920
r2dbcDriver = "2.0.2"
2021
room = "2.7.0-rc03"
@@ -78,6 +79,8 @@ ktor-server-core = { module = "io.ktor:ktor-server-core-jvm" }
7879
ktor-server-websocket = { module = "io.ktor:ktor-server-websockets-jvm" }
7980
ktor-server-netty = { module = "io.ktor:ktor-server-netty-jvm" }
8081
ktor-server-tests = { module = "io.ktor:ktor-server-test-host", version.ref = "ktor" }
82+
#material3-desktop = { module = "org.jetbrains.compose.material3:material3-desktop", version.ref = "material3" }
83+
platformtools-darkmodedetector = { module = "io.github.kdroidfilter:platformtools.darkmodedetector", version.ref = "platformtools" }
8184
r2dbc-driver = { module = "app.cash.sqldelight:r2dbc-driver", version.ref = "r2dbcDriver" }
8285
sql-postgres-socket-factory = { module = "com.google.cloud.sql:postgres-socket-factory", version.ref = "postgresSocketFactory" }
8386
room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" }

0 commit comments

Comments
 (0)