From b0edb189b97c1a65c649e340fd1c25adeba7f5d0 Mon Sep 17 00:00:00 2001 From: chun_qiu Date: Fri, 31 Jul 2026 21:45:28 +0800 Subject: [PATCH] Fix settings window lifecycle --- app.go | 3 +-- settings.go | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app.go b/app.go index 5be598b..36c7216 100644 --- a/app.go +++ b/app.go @@ -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() diff --git a/settings.go b/settings.go index a02df6c..aca085a 100644 --- a/settings.go +++ b/settings.go @@ -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) {