mirror of
https://github.com/Suwayomi/TachideskJUI.git
synced 2025-12-10 06:42:05 +01:00
Add support for detecting the system theme
This commit is contained in:
@@ -10,7 +10,7 @@ import kotlinx.serialization.Serializable
|
|||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
enum class ThemeMode {
|
enum class ThemeMode {
|
||||||
/*System,*/
|
System,
|
||||||
Light,
|
Light,
|
||||||
Dark,
|
Dark,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
package ca.gosyer.ui.base.theme
|
package ca.gosyer.ui.base.theme
|
||||||
|
|
||||||
import androidx.compose.desktop.DesktopMaterialTheme
|
import androidx.compose.desktop.DesktopMaterialTheme
|
||||||
|
import androidx.compose.foundation.isSystemInDarkTheme
|
||||||
import androidx.compose.material.Colors
|
import androidx.compose.material.Colors
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
@@ -83,11 +84,11 @@ private class AppThemeViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return when (themeMode) {
|
return when (themeMode) {
|
||||||
/*ThemeMode.System -> if (!isSystemInDarkTheme()) {
|
ThemeMode.System -> if (!isSystemInDarkTheme()) {
|
||||||
getTheme(lightTheme, true)
|
getTheme(lightTheme, true)
|
||||||
} else {
|
} else {
|
||||||
getTheme(darkTheme, false)
|
getTheme(darkTheme, false)
|
||||||
}*/
|
}
|
||||||
ThemeMode.Light -> getTheme(lightTheme, true)
|
ThemeMode.Light -> getTheme(lightTheme, true)
|
||||||
ThemeMode.Dark -> getTheme(darkTheme, false)
|
ThemeMode.Dark -> getTheme(darkTheme, false)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ import com.github.zsoltk.compose.savedinstancestate.Bundle
|
|||||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
|
import org.jetbrains.skiko.SystemTheme
|
||||||
|
import org.jetbrains.skiko.currentSystemTheme
|
||||||
import toothpick.configuration.Configuration
|
import toothpick.configuration.Configuration
|
||||||
import toothpick.ktp.KTP
|
import toothpick.ktp.KTP
|
||||||
import toothpick.ktp.extension.getInstance
|
import toothpick.ktp.extension.getInstance
|
||||||
@@ -98,6 +100,10 @@ suspend fun main() {
|
|||||||
return@getAsFlow
|
return@getAsFlow
|
||||||
}
|
}
|
||||||
val theme = when (it) {
|
val theme = when (it) {
|
||||||
|
ThemeMode.System -> when (currentSystemTheme) {
|
||||||
|
SystemTheme.LIGHT, SystemTheme.UNKNOWN -> IntelliJTheme()
|
||||||
|
SystemTheme.DARK -> DarculaTheme()
|
||||||
|
}
|
||||||
ThemeMode.Light -> IntelliJTheme()
|
ThemeMode.Light -> IntelliJTheme()
|
||||||
ThemeMode.Dark -> DarculaTheme()
|
ThemeMode.Dark -> DarculaTheme()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ fun SettingsAppearance(navController: BackStack<Route>) {
|
|||||||
ChoicePreference(
|
ChoicePreference(
|
||||||
preference = vm.themeMode,
|
preference = vm.themeMode,
|
||||||
choices = mapOf(
|
choices = mapOf(
|
||||||
// ThemeMode.System to R.string.follow_system_settings,
|
ThemeMode.System to stringResource("theme_follow_system"),
|
||||||
ThemeMode.Light to stringResource("theme_light"),
|
ThemeMode.Light to stringResource("theme_light"),
|
||||||
ThemeMode.Dark to stringResource("theme_dark")
|
ThemeMode.Dark to stringResource("theme_dark")
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -110,6 +110,7 @@
|
|||||||
|
|
||||||
<!-- Appearance Settings -->
|
<!-- Appearance Settings -->
|
||||||
<string name="theme">Theme</string>
|
<string name="theme">Theme</string>
|
||||||
|
<string name="theme_follow_system">Follow system settings</string>
|
||||||
<string name="theme_light">Light</string>
|
<string name="theme_light">Light</string>
|
||||||
<string name="theme_dark">Dark</string>
|
<string name="theme_dark">Dark</string>
|
||||||
<string name="theme_text">Text</string>
|
<string name="theme_text">Text</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user