Fix settings window lifecycle

This commit is contained in:
2026-07-31 21:45:28 +08:00
parent 983c3e1dfd
commit b0edb189b9
2 changed files with 23 additions and 4 deletions
+1 -2
View File
@@ -31,6 +31,7 @@ type App struct {
previousAction *walk.Action
nextAction *walk.Action
settingsAction *walk.Action
settingsDialog *walk.Dialog
timerMu sync.Mutex
timer *time.Timer
busy atomic.Bool
@@ -194,8 +195,6 @@ func (a *App) refresh(automatic bool) {
a.setBusy(false)
if err != nil {
a.notifyError("刷新壁纸失败:" + err.Error())
} else {
_ = a.notifyIcon.ShowInfo(appName, "壁纸已刷新。")
}
if automatic {
a.scheduleTimer()
+22 -2
View File
@@ -25,6 +25,12 @@ var styleOptions = []struct {
}
func (a *App) showSettings() {
if a.settingsDialog != nil {
a.settingsDialog.Show()
_ = a.settingsDialog.Activate()
return
}
var dlg *walk.Dialog
var apiEdit, intervalEdit, cacheEdit *walk.LineEdit
var autoCheck, startupCheck *walk.CheckBox
@@ -39,7 +45,7 @@ func (a *App) showSettings() {
}
}
_, err := Dialog{
err := Dialog{
AssignTo: &dlg,
Title: "GoWallpaper 设置",
MinSize: Size{520, 300},
@@ -93,15 +99,29 @@ func (a *App) showSettings() {
return
}
dlg.Accept()
if cfg.APIURL == "" {
a.notifyInfo("配置已保存。刷新壁纸前需要先设置随机图片 API 地址。")
} else {
a.notifyInfo("配置已保存。")
}
}},
PushButton{Text: "取消", OnClicked: func() { dlg.Cancel() }},
},
},
},
}.Run(a.mw)
}.Create(nil)
if err != nil {
a.notifyError("无法打开设置窗口:" + err.Error())
return
}
a.settingsDialog = dlg
dlg.Closing().Attach(func(_ *bool, _ walk.CloseReason) {
if a.settingsDialog == dlg {
a.settingsDialog = nil
}
})
dlg.Show()
_ = dlg.Activate()
}
func parsePositiveInt(value, field string) (int, error) {