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.
82 lines
2.8 KiB
Go
82 lines
2.8 KiB
Go
package gui
|
||
|
||
import (
|
||
"time"
|
||
|
||
"github.com/yetone/magpie/internal/agent"
|
||
"github.com/yetone/magpie/internal/settings"
|
||
)
|
||
|
||
// Quitting magpie ends the gateway, and every agent connected to it fails
|
||
// until magpie is opened again, with nothing to say why: Codex retried
|
||
// "unexpected status 502 Bad Gateway: Unknown error" five times and gave
|
||
// up, and its user found magpie's line in ~/.codex/config.toml only after
|
||
// a long search (Aisiverto on X). So a Quit the user chooses (the tray's
|
||
// menu, the panel's Quit, Command-Q on the Mac) while agents are connected
|
||
// opens the window on a question first, naming them (quitask.js): Quit,
|
||
// Disconnect and quit (each one's own settings put back, as its row's
|
||
// Disconnect does), or Cancel, with "Don't ask again" (zhujiu on Discord),
|
||
// which Settings › General › Ask before quitting turns back on
|
||
// (settings.QuitNoAsk). A quit magpie makes itself (a restart to
|
||
// update, Uninstall) and the system's own (logging out, shutting down,
|
||
// the Dock's Quit) don't ask.
|
||
|
||
// quitAgentJSON is an agent a quit would cut off, for the question.
|
||
type quitAgentJSON struct {
|
||
ID string `json:"id"`
|
||
Name string `json:"name"`
|
||
Icon string `json:"icon"`
|
||
}
|
||
|
||
// quitAgents lists the agents connected to the gateway this process
|
||
// serves: none when another magpie serves it, which goes on serving them.
|
||
// A var so tests can say.
|
||
var quitAgents = func() []quitAgentJSON {
|
||
if served.Load() == nil {
|
||
return nil
|
||
}
|
||
return wiredAgents(agent.Detected())
|
||
}
|
||
|
||
// wiredAgents is the agents of as with magpie in their config.
|
||
func wiredAgents(as []*agent.Agent) []quitAgentJSON {
|
||
out := []quitAgentJSON{}
|
||
for _, a := range as {
|
||
if a.Wired() {
|
||
out = append(out, quitAgentJSON{ID: a.ID, Name: a.Name, Icon: a.Icon})
|
||
}
|
||
}
|
||
return out
|
||
}
|
||
|
||
// quitAsker is a host that asks before a quit the user chose (the app's);
|
||
// a browser's page (magpie web) quits at once.
|
||
type quitAsker interface {
|
||
// AskQuit quits, or first asks in the window when agents are connected
|
||
AskQuit()
|
||
}
|
||
|
||
// quitAgain is how long after the question is put a second Quit quits
|
||
// without it.
|
||
const quitAgain = time.Minute
|
||
|
||
// quitNow says whether a Quit chosen at now quits without asking: with no
|
||
// agent connected (wired), or within quitAgain of the question put at
|
||
// asked (unix nanoseconds; 0 when it never was).
|
||
func quitNow(asked int64, now time.Time, wired int) bool {
|
||
if wired == 0 {
|
||
return true
|
||
}
|
||
return asked != 0 && now.Sub(time.Unix(0, asked)) < quitAgain
|
||
}
|
||
|
||
// quitAtOnce says whether a Quit chosen at now quits without asking: the
|
||
// user said not to ask (settings.QuitNoAsk, the question's "Don't ask
|
||
// again"), or quitNow. A settings file that can't be read asks.
|
||
func quitAtOnce(asked int64, now time.Time) bool {
|
||
if s, err := settings.LoadChecked(); err == nil && s.QuitNoAsk {
|
||
return true
|
||
}
|
||
return quitNow(asked, now, len(quitAgents()))
|
||
}
|