feat(ui): 开机自启动 + 窗口大小记忆

- win32/autostart: SetAutoStart/IsAutoStartEnabled 操作 HKCU Run 键
- win32/window_size: GetWindowSize 通过 GetWindowRect 获取窗口尺寸
- config: 新增 AutoStart、WindowWidth、WindowHeight 字段
- store: Preferences/SetPreferences 扩展支持 autoStart + windowSize
- dialog_preferences: 新增"开机自启动"复选框
- app.go: 启动时恢复窗口大小,关闭时通过 SetWindowSize 保存
- i18n: label_auto_start / hint_auto_start 三语翻译
This commit is contained in:
2026-06-12 11:10:25 +08:00
parent cb4d88ebdd
commit 1605b5b7ae
11 changed files with 278 additions and 17 deletions
+27 -8
View File
@@ -38,9 +38,20 @@ func Run(configPath string) error {
go func() {
w := new(app.Window)
// Read stored window size or use defaults.
cfg, _ := config.LoadYAML(configPath, nil)
winW, winH := 560, 420
if cfg != nil {
if cfg.WindowWidth > 0 {
winW = cfg.WindowWidth
}
if cfg.WindowHeight > 0 {
winH = cfg.WindowHeight
}
}
w.Option(
app.Title(i18n.T("app_title")),
app.Size(unit.Dp(560), unit.Dp(420)),
app.Size(unit.Dp(winW), unit.Dp(winH)),
)
if err := loop(w, configPath); err != nil {
global.Log.WithField("func", fn).WithError(err).Error("ui loop failed")
@@ -195,7 +206,7 @@ func loop(w *app.Window, configPath string) error {
// Seed the theme cache from the stored preference. Empty / unknown
// values resolve to "system" which buildTheme then maps to light or
// dark via the OS-specific systemPrefersDark probe.
_, themePref, _, _ := state.store.Preferences()
_, themePref, _, _, _, _, _ := state.store.Preferences()
state.themeMode = normalizeThemeMode(themePref)
// Spin up the global hotkey manager and register whatever the user
@@ -208,7 +219,7 @@ func loop(w *app.Window, configPath string) error {
// Install the system tray icon + close-hook (Windows only). HWND
// discovery races the very first FrameEvent, so kick it from a
// goroutine that polls FindWindow for a few hundred ms.
_, _, _, minToTray := state.store.Preferences()
_, _, _, minToTray, _, _, _ := state.store.Preferences()
go func() {
tr := installTrayRuntime(i18n.T("app_title"), minToTray, w.Invalidate)
state.mu.Lock()
@@ -229,6 +240,12 @@ func loop(w *app.Window, configPath string) error {
for {
switch e := w.Event().(type) {
case app.DestroyEvent:
// Persist window size before exiting.
if hwnd := win32.FindWindowByTitle(i18n.T("app_title")); hwnd != 0 {
if w, h, ok := win32.GetWindowSize(hwnd); ok && w > 0 && h > 0 {
state.store.SetWindowSize(w, h)
}
}
global.Log.WithField("func", fn).Info("window closed")
state.tray.Stop()
return e.Err
@@ -267,7 +284,7 @@ func (st *appState) maybeAutoLock() bool {
if !st.store.Encrypted() {
return false
}
_, _, autoLockMinutes, _ := st.store.Preferences()
_, _, autoLockMinutes, _, _, _, _ := st.store.Preferences()
if autoLockMinutes <= 0 {
return false
}
@@ -563,8 +580,8 @@ func drawFrame(gtx layout.Context, th *material.Theme, st *appState, w *app.Wind
case settingsActionRestoreBackup:
st.restoreDlg = newRestoreBackupDialog()
case settingsActionPreferences:
lang, theme, autoLock, minToTray := st.store.Preferences()
st.prefsDialog = newPreferencesDialog(lang, normalizeThemeMode(theme), autoLock, minToTray)
lang, theme, autoLock, minToTray, autoStart, _, _ := st.store.Preferences()
st.prefsDialog = newPreferencesDialog(lang, normalizeThemeMode(theme), autoLock, minToTray, autoStart)
case settingsActionAbout:
st.aboutDialog = newAboutDialog()
}
@@ -577,8 +594,10 @@ func drawFrame(gtx layout.Context, th *material.Theme, st *appState, w *app.Wind
if st.prefsDialog != nil {
return st.prefsDialog.Layout(gtx, th, func(r preferencesResult) {
if !r.cancel {
_, _, _, prevMinToTray := st.store.Preferences()
st.store.SetPreferences(r.language, string(r.theme), r.autoLockMinutes, r.minimizeToTray)
_, _, _, prevMinToTray, _, _, _ := st.store.Preferences()
_, _, _, _, _, winW, winH := st.store.Preferences()
st.store.SetPreferences(r.language, string(r.theme), r.autoLockMinutes, r.minimizeToTray, r.autoStart, winW, winH)
win32.SetAutoStart(r.autoStart)
i18n.SetLanguage(r.language)
st.themeMode = r.theme
st.theme = nil // force rebuild on next frame