desktopMain.com.softartdev.themepref.JvmPreferenceHelper.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of material-theme-prefs Show documentation
Show all versions of material-theme-prefs Show documentation
Kotlin Multiplatform library for easy switching Dark/Light Material themes on Compose.
package com.softartdev.themepref
import androidx.compose.runtime.Composable
import java.util.prefs.Preferences
class JvmPreferenceHelper : PreferenceHelper {
private var preferences: Preferences = Preferences.userNodeForPackage(ThemeEnum::class.java)
override var themeEnum: ThemeEnum
get() = preferences.getInt(THEME_KEY, ThemeEnum.SystemDefault.ordinal).let(ThemeEnum.values()::get)
set(value) = preferences.putInt(THEME_KEY, value.ordinal)
override fun clear() = preferences.clear()
}
@Composable
actual fun obtainPreferenceHelper(): PreferenceHelper = JvmPreferenceHelper()