desktop: changing language without reload (#2896)
* desktop: changing language without reload * comment --------- Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
This commit is contained in:
parent
7a41957d7b
commit
1bc880877d
@ -214,7 +214,7 @@ object AppearanceScope {
|
|||||||
"ru" to "Русский",
|
"ru" to "Русский",
|
||||||
"zh-CN" to "简体中文"
|
"zh-CN" to "简体中文"
|
||||||
)
|
)
|
||||||
val values by remember { mutableStateOf(supportedLanguages.map { it.key to it.value }) }
|
val values by remember(ChatController.appPrefs.appLanguage.state.value) { mutableStateOf(supportedLanguages.map { it.key to it.value }) }
|
||||||
ExposedDropDownSettingRow(
|
ExposedDropDownSettingRow(
|
||||||
generalGetString(MR.strings.settings_section_title_language).lowercase().replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.US) else it.toString() },
|
generalGetString(MR.strings.settings_section_title_language).lowercase().replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.US) else it.toString() },
|
||||||
values,
|
values,
|
||||||
@ -228,7 +228,9 @@ object AppearanceScope {
|
|||||||
@Composable
|
@Composable
|
||||||
private fun ThemeSelector(state: State<String>, onSelected: (String) -> Unit) {
|
private fun ThemeSelector(state: State<String>, onSelected: (String) -> Unit) {
|
||||||
val darkTheme = chat.simplex.common.ui.theme.isSystemInDarkTheme()
|
val darkTheme = chat.simplex.common.ui.theme.isSystemInDarkTheme()
|
||||||
val values by remember { mutableStateOf(ThemeManager.allThemes(darkTheme).map { it.second.name to it.third }) }
|
val values by remember(ChatController.appPrefs.appLanguage.state.value) {
|
||||||
|
mutableStateOf(ThemeManager.allThemes(darkTheme).map { it.second.name to it.third })
|
||||||
|
}
|
||||||
ExposedDropDownSettingRow(
|
ExposedDropDownSettingRow(
|
||||||
generalGetString(MR.strings.theme),
|
generalGetString(MR.strings.theme),
|
||||||
values,
|
values,
|
||||||
|
@ -14,6 +14,7 @@ import androidx.compose.ui.unit.dp
|
|||||||
import androidx.compose.ui.window.*
|
import androidx.compose.ui.window.*
|
||||||
import chat.simplex.common.model.ChatController
|
import chat.simplex.common.model.ChatController
|
||||||
import chat.simplex.common.model.ChatModel
|
import chat.simplex.common.model.ChatModel
|
||||||
|
import chat.simplex.common.platform.defaultLocale
|
||||||
import chat.simplex.common.platform.desktopPlatform
|
import chat.simplex.common.platform.desktopPlatform
|
||||||
import chat.simplex.common.ui.theme.SimpleXTheme
|
import chat.simplex.common.ui.theme.SimpleXTheme
|
||||||
import chat.simplex.common.views.helpers.FileDialogChooser
|
import chat.simplex.common.views.helpers.FileDialogChooser
|
||||||
@ -34,6 +35,8 @@ fun showApp() = application {
|
|||||||
val width = if (desktopPlatform.isLinux()) 1376.dp else 1366.dp
|
val width = if (desktopPlatform.isLinux()) 1376.dp else 1366.dp
|
||||||
val windowState = rememberWindowState(placement = WindowPlacement.Floating, width = width, height = 768.dp)
|
val windowState = rememberWindowState(placement = WindowPlacement.Floating, width = width, height = 768.dp)
|
||||||
simplexWindowState.windowState = windowState
|
simplexWindowState.windowState = windowState
|
||||||
|
// Reload all strings in all @Composable's after language change at runtime
|
||||||
|
if (remember { ChatController.appPrefs.appLanguage.state }.value != "") {
|
||||||
Window(state = windowState, onCloseRequest = ::exitApplication, onKeyEvent = {
|
Window(state = windowState, onCloseRequest = ::exitApplication, onKeyEvent = {
|
||||||
if (it.key == Key.Escape && it.type == KeyEventType.KeyUp) {
|
if (it.key == Key.Escape && it.type == KeyEventType.KeyUp) {
|
||||||
simplexWindowState.backstack.lastOrNull()?.invoke() != null
|
simplexWindowState.backstack.lastOrNull()?.invoke() != null
|
||||||
@ -101,7 +104,7 @@ fun showApp() = application {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
window.addWindowFocusListener(object : WindowFocusListener {
|
window.addWindowFocusListener(object: WindowFocusListener {
|
||||||
override fun windowGainedFocus(p0: WindowEvent?) {
|
override fun windowGainedFocus(p0: WindowEvent?) {
|
||||||
windowFocused = true
|
windowFocused = true
|
||||||
AppLock.recheckAuthState()
|
AppLock.recheckAuthState()
|
||||||
@ -114,6 +117,7 @@ fun showApp() = application {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SimplexWindowState {
|
class SimplexWindowState {
|
||||||
|
Loading…
Reference in New Issue
Block a user