zhujiu (Discord #feedback) asked for a 不再提示 on the question a tray Quit asks while agents go through magpie (8826a15ea), and a switch in Settings to turn it on and off again. - The question (quitask.js, an in-app sheet) has a "Don't ask again" checkbox above its buttons, unticked each time. It goes with the Quit chosen: Quit and Disconnect and quit post window/quit?now=1&noAsk=1, which saves settings.quitNoAsk (settings.SetQuitNoAsk, under the file lock) before quitting; a failed save keeps magpie open. Cancel saves nothing. - AskQuit quits at once when quitNoAsk is set (quitAtOnce); otherwise as before. The default is unchanged: it asks. - Settings › General has "Ask before quitting" On/Off (segs, app-only), after Open at login. settingsapi.Keys lists quitNoAsk, and Merge carries it when a save doesn't send it, so the tray panel or an older page can't turn the question back on. - zh, zh-TW, ja, de strings. Five app.js comments shortened to stay in the core script budget (no raise). Run at the pushed head (on origin/mainf95bacdfb), on mote: - gofmt clean; go vet darwin, linux, windows (nogui too). - go test internal/settings, internal/settingsapi ok; internal/gui -run "Budget|Quit" ok. - internal/cli: TestEveryRouteHasACommandOrIsNamed red for POST /api/usage/checkin-account, frome87140242, filed as #4826; this change adds no route. - GUI, chromium and webkit: quit-ask-setting (25: en, zh, zh-TW, ja, de at 1100 and 420), quit-ask (35), settings-general, settings-sections, settings-search, settings-tabs-stick, wsl-agents-setting, agent-prefs, i18n-keys, old-webkit, auto-backup, all pass. Broken by hand, each red: - api.go's noAsk ignored: TestQuitDontAskAgain "wasn't saved". - quitAtOnce not reading the setting: TestQuitDontAskAgain "still asks". - Merge carry dropped: TestQuitNoAskKeptUnlessSent. - SetQuitNoAsk saving false: TestSetQuitNoAsk. - quitask.js without &noAsk=1: quit-ask's two Don't ask again tests. Not tried: a real tray Quit with the box ticked in the built app on macOS, Windows or Linux; only the sheet in Playwright and the handler in Go. Not the whole GUI suite.
53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
//go:build !nogui
|
|
|
|
package gui
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/wailsapp/wails/v3/pkg/application"
|
|
)
|
|
|
|
// askQuitJS has the window's page put the question; askQuitURL opens a
|
|
// window made again on it.
|
|
const (
|
|
askQuitJS = "window.askQuit?.()"
|
|
askQuitURL = "/?ask=quit"
|
|
)
|
|
|
|
// AskQuit is a Quit the user chose: at once while no agent is connected to
|
|
// the gateway this process serves or the user said not to ask, else the window comes up and asks
|
|
// (quitask.go). A second Quit within quitAgain of the question quits: the
|
|
// user has been told, and it is the way out should the window not show it.
|
|
func (h *host) AskQuit() {
|
|
if quitAtOnce(h.quitAt.Load(), time.Now()) {
|
|
h.app.Quit()
|
|
return
|
|
}
|
|
h.quitAt.Store(time.Now().UnixNano())
|
|
application.InvokeSync(func() {
|
|
if h.main == nil || h.loading[h.main] {
|
|
h.openMain(askQuitURL + h.query)
|
|
return
|
|
}
|
|
h.openMain("")
|
|
h.main.ExecJS(askQuitJS)
|
|
})
|
|
}
|
|
|
|
// askingQuit puts an item of label in place of the Quit item of menu's
|
|
// app menu, with Command-Q, that calls ask; nil when menu has none.
|
|
func askingQuit(menu *application.Menu, label string, ask func()) *application.MenuItem {
|
|
app := menu.FindByRole(application.AppMenu)
|
|
if app == nil || app.GetSubmenu() == nil {
|
|
return nil
|
|
}
|
|
sub := app.GetSubmenu()
|
|
old := sub.FindByRole(application.Quit)
|
|
if old == nil {
|
|
return nil
|
|
}
|
|
sub.RemoveMenuItem(old)
|
|
return sub.Add(label).SetAccelerator("CmdOrCtrl+q").OnClick(func(*application.Context) { ask() })
|
|
}
|