diff --git a/backend/storage/preferences.go b/backend/storage/preferences.go index d0672db..6726672 100644 --- a/backend/storage/preferences.go +++ b/backend/storage/preferences.go @@ -79,6 +79,26 @@ func (p *PreferencesStorage) GetPreferences() (ret map[string]any) { return } +func (p *PreferencesStorage) Value(keys ...string) any { + kv := p.getPreferences() + var ok bool + var a any + total := len(keys) + for i, key := range keys { + if a, ok = kv[key]; !ok { + return nil + } + if i == total-1 { + // last key, return value + return a + } + if kv, ok = a.(map[string]any); !ok { + return nil + } + } + return nil +} + func (p *PreferencesStorage) setPreferences(pf map[string]any, key string, value any) error { keyPath := strings.Split(key, ".") if len(keyPath) <= 0 { diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 9d5cc2d..ee5654e 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -30,7 +30,6 @@ const initializing = ref(false) onMounted(async () => { try { initializing.value = true - i18n.locale.value = prefStore.currentLanguage await connectionStore.initConnections() if (prefStore.autoCheckUpdate) { prefStore.checkForUpdate() @@ -40,10 +39,17 @@ onMounted(async () => { } }) +// watch theme and dynamically switch watch( () => prefStore.isDark, (isDark) => (isDark ? WindowSetDarkTheme() : WindowSetLightTheme()), ) + +// watch language and dynamically switch +watch( + () => prefStore.general.language, + (lang) => (i18n.locale.value = prefStore.currentLanguage), +)