diff --git a/shared/src/commonMain/kotlin/net/newpipe/app/viewmodel/settings/AppearanceSettingsViewModel.kt b/shared/src/commonMain/kotlin/net/newpipe/app/viewmodel/settings/AppearanceSettingsViewModel.kt index bc02c56d6..c6602dd50 100644 --- a/shared/src/commonMain/kotlin/net/newpipe/app/viewmodel/settings/AppearanceSettingsViewModel.kt +++ b/shared/src/commonMain/kotlin/net/newpipe/app/viewmodel/settings/AppearanceSettingsViewModel.kt @@ -9,11 +9,16 @@ import androidx.lifecycle.ViewModel import com.russhwolf.settings.Settings import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow +import net.newpipe.app.platform.AppearanceActions import net.newpipe.app.preferences.AppearancePreferences import org.koin.core.annotation.KoinViewModel @KoinViewModel +class AppearanceSettingsViewModel( + private val settings: Settings, + private val appearanceActions: AppearanceActions, +) : ViewModel() { val theme: StateFlow field = MutableStateFlow( @@ -63,11 +68,13 @@ import org.koin.core.annotation.KoinViewModel fun setTheme(value: String) { settings.putString(AppearancePreferences.KEY_THEME, value) theme.value = value + appearanceActions.applyThemeChange(value) } fun setNightTheme(value: String) { settings.putString(AppearancePreferences.KEY_NIGHT_THEME, value) nightTheme.value = value + appearanceActions.applyThemeChange(theme.value) } fun setHoldToAppend(value: Boolean) { diff --git a/shared/src/jvmMain/kotlin/net/newpipe/app/platform/JVMAppearanceActions.kt b/shared/src/jvmMain/kotlin/net/newpipe/app/platform/JVMAppearanceActions.kt index 376f6a134..e30360d45 100644 --- a/shared/src/jvmMain/kotlin/net/newpipe/app/platform/JVMAppearanceActions.kt +++ b/shared/src/jvmMain/kotlin/net/newpipe/app/platform/JVMAppearanceActions.kt @@ -5,49 +5,11 @@ package net.newpipe.app.platform -import co.touchlab.kermit.Logger import org.koin.core.annotation.Singleton -import java.io.IOException @Singleton(binds = [AppearanceActions::class]) class JVMAppearanceActions : AppearanceActions { - - private val captionSettingsCommand: List? = when (currentOs()) { - DesktopOs.WINDOWS -> - // Closed-caption styling page - listOf("cmd", "/c", "start", "", "ms-settings:easeofaccess-closedcaptioning") - - // Subtitles & captions styling pane. This is community-documented,so on newer macOS it may open the Accessibility pane without directing to Captions. - DesktopOs.MAC -> - listOf("open", "x-apple.systempreferences:com.apple.preference.universalaccess?Captions") - - // Nothing for Linux yet - DesktopOs.LINUX, - DesktopOs.UNKNOWN -> null - } - - override fun isCaptionSettingsAvailable() = captionSettingsCommand != null - - override fun openCaptionSettings() { - val command = captionSettingsCommand ?: return - try { - ProcessBuilder(command).start() - } catch (exception: IOException) { - Logger.e(messageString = "Could not open caption settings", throwable = exception) - } - } + override fun openCaptionSettings() = Unit override fun applyThemeChange(theme: String) = Unit - - private enum class DesktopOs { WINDOWS, MAC, LINUX, UNKNOWN } - - private fun currentOs(): DesktopOs { - val osName = System.getProperty("os.name").orEmpty().lowercase() - return when { - osName.startsWith("windows") -> DesktopOs.WINDOWS - osName.startsWith("mac") -> DesktopOs.MAC - osName.contains("nux") || osName.contains("nix") || osName.contains("aix") -> DesktopOs.LINUX - else -> DesktopOs.UNKNOWN - } - } }