theme changes rebuild host activity

This commit is contained in:
Ida Delphine
2026-10-07 16:59:43 +08:00
committed by Aayush Gupta
parent 24fc4d1194
commit 800d175aa2
2 changed files with 8 additions and 39 deletions
@@ -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<String>
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) {
@@ -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<String>? = 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
}
}
}