fix: make app language key global, not profile-scoped

The language preference was stored with a profile-scoped key
(selected_app_language_{profileId}), causing it to reset to English
on app restart when the active profile was not profile 1.

During startup, initialize() reads the key with default
activeProfileId=1 before the correct profile is loaded, resulting
in a cache miss and fallback to English.

App language is a device-level preference, not per-profile, so
the key should not be scoped. This also fixes replaceFromSyncPayload
to correctly clear both profile-scoped and global keys.
This commit is contained in:
Leonardo Montemurro 2026-04-27 15:01:08 +02:00
parent 7ef0083a71
commit e15a398f3e
2 changed files with 14 additions and 8 deletions

View file

@ -18,7 +18,8 @@ actual object ThemeSettingsStorage {
private const val selectedThemeKey = "selected_theme"
private const val amoledEnabledKey = "amoled_enabled"
private const val selectedAppLanguageKey = "selected_app_language"
private val syncKeys = listOf(selectedThemeKey, amoledEnabledKey, selectedAppLanguageKey)
private val profileScopedSyncKeys = listOf(selectedThemeKey, amoledEnabledKey)
private val globalSyncKeys = listOf(selectedAppLanguageKey)
private var preferences: SharedPreferences? = null
@ -51,12 +52,12 @@ actual object ThemeSettingsStorage {
}
actual fun loadSelectedAppLanguage(): String? =
preferences?.getString(ProfileScopedKey.of(selectedAppLanguageKey), null)
preferences?.getString(selectedAppLanguageKey, null)
actual fun saveSelectedAppLanguage(languageCode: String) {
preferences
?.edit()
?.putString(ProfileScopedKey.of(selectedAppLanguageKey), languageCode)
?.putString(selectedAppLanguageKey, languageCode)
?.apply()
}
@ -74,7 +75,8 @@ actual object ThemeSettingsStorage {
actual fun replaceFromSyncPayload(payload: JsonObject) {
preferences?.edit()?.apply {
syncKeys.forEach { remove(ProfileScopedKey.of(it)) }
profileScopedSyncKeys.forEach { remove(ProfileScopedKey.of(it)) }
globalSyncKeys.forEach { remove(it) }
}?.apply()
payload.decodeSyncString(selectedThemeKey)?.let(::saveSelectedTheme)

View file

@ -14,7 +14,8 @@ actual object ThemeSettingsStorage {
private const val selectedThemeKey = "selected_theme"
private const val amoledEnabledKey = "amoled_enabled"
private const val selectedAppLanguageKey = "selected_app_language"
private val syncKeys = listOf(selectedThemeKey, amoledEnabledKey, selectedAppLanguageKey)
private val profileScopedSyncKeys = listOf(selectedThemeKey, amoledEnabledKey)
private val globalSyncKeys = listOf(selectedAppLanguageKey)
actual fun loadSelectedTheme(): String? =
NSUserDefaults.standardUserDefaults.stringForKey(ProfileScopedKey.of(selectedThemeKey))
@ -38,10 +39,10 @@ actual object ThemeSettingsStorage {
}
actual fun loadSelectedAppLanguage(): String? =
NSUserDefaults.standardUserDefaults.stringForKey(ProfileScopedKey.of(selectedAppLanguageKey))
NSUserDefaults.standardUserDefaults.stringForKey(selectedAppLanguageKey)
actual fun saveSelectedAppLanguage(languageCode: String) {
NSUserDefaults.standardUserDefaults.setObject(languageCode, forKey = ProfileScopedKey.of(selectedAppLanguageKey))
NSUserDefaults.standardUserDefaults.setObject(languageCode, forKey = selectedAppLanguageKey)
}
actual fun applySelectedAppLanguage(languageCode: String) = Unit
@ -53,9 +54,12 @@ actual object ThemeSettingsStorage {
}
actual fun replaceFromSyncPayload(payload: JsonObject) {
syncKeys.forEach { key ->
profileScopedSyncKeys.forEach { key ->
NSUserDefaults.standardUserDefaults.removeObjectForKey(ProfileScopedKey.of(key))
}
globalSyncKeys.forEach { key ->
NSUserDefaults.standardUserDefaults.removeObjectForKey(key)
}
payload.decodeSyncString(selectedThemeKey)?.let(::saveSelectedTheme)
payload.decodeSyncBoolean(amoledEnabledKey)?.let(::saveAmoledEnabled)