feat(ui): 主题切换 + 语言持久化 + About 对话框
- 新增 light/dark 主题调色板与 Windows 注册表系统主题探测 - 偏好设置对话框:主题三选一 + 语言下拉(en/zh-CN/de),即时生效 - 持久化 Language/Theme/AutoLockMinutes/MinimizeToTray 至 YAML 顶层 - 启动时按 config 中保存的语言初始化 i18n - About 对话框展示 version/runtime/项目地址/许可证 - 全部硬编码颜色迁移到 themePalette,为深色模式做准备
This commit is contained in:
+26
-2
@@ -6,10 +6,12 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"git.wxccs.org/iceking2nd/winauth-go/internal/config"
|
||||
"git.wxccs.org/iceking2nd/winauth-go/internal/global"
|
||||
"git.wxccs.org/iceking2nd/winauth-go/internal/i18n"
|
||||
"git.wxccs.org/iceking2nd/winauth-go/internal/logging"
|
||||
"git.wxccs.org/iceking2nd/winauth-go/internal/ui"
|
||||
"git.wxccs.org/iceking2nd/winauth-go/internal/version"
|
||||
"git.wxccs.org/iceking2nd/winauth-go/internal/win32"
|
||||
)
|
||||
|
||||
@@ -53,7 +55,8 @@ func main() {
|
||||
}
|
||||
|
||||
const fn = "cmd.winauth.main"
|
||||
global.Log.WithField("func", fn).Info("winauth-go starting")
|
||||
global.Log.WithField("func", fn).
|
||||
WithField("version", version.String()).Info("winauth-go starting")
|
||||
|
||||
release, alreadyRunning, err := win32.AcquireInstanceLock(singleInstanceMutex)
|
||||
if err != nil {
|
||||
@@ -70,7 +73,12 @@ func main() {
|
||||
defer release()
|
||||
}
|
||||
|
||||
if err := i18n.Init(""); err != nil {
|
||||
// Peek the config (without password) to recover the user's
|
||||
// last language choice before initialising i18n. Encrypted
|
||||
// configs still expose Language at the YAML top level so we
|
||||
// can localise the password prompt itself.
|
||||
lang := preferredLanguage(configPath)
|
||||
if err := i18n.Init(lang); err != nil {
|
||||
global.Log.WithField("func", fn).WithError(err).Warn("i18n init failed; falling back to keys")
|
||||
}
|
||||
|
||||
@@ -91,3 +99,19 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// preferredLanguage reads the user's saved language tag out of the YAML
|
||||
// config without requiring a passphrase. We resolve the default config
|
||||
// path when configPath is blank and silently return "" on any failure;
|
||||
// callers fall back to the i18n default in that case. Encrypted configs
|
||||
// still expose the top-level Language field so this works for them too.
|
||||
func preferredLanguage(configPath string) string {
|
||||
if configPath == "" {
|
||||
configPath = config.DefaultPath()
|
||||
}
|
||||
cfg, _ := config.LoadYAML(configPath, nil)
|
||||
if cfg == nil {
|
||||
return ""
|
||||
}
|
||||
return cfg.Language
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user