Fix settings window lifecycle
This commit is contained in:
+22
-2
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user