Files
magpie/internal/gui/assets/quitask.js
T
yetone ed978e560f gui: the Quit question's Don't ask again, and Settings › General › Ask before quitting (zhujiu on Discord)
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/main f95bacdfb), 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, from e87140242, 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.
2026-11-02 18:53:07 +08:00

80 lines
3.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// The question a Quit the user chose puts while agents are connected to
// magpie's gateway (quitask.go; Aisiverto on X: Codex failed with 502s
// after magpie was quit, and nothing said why). It names the agents that
// stop working, says that closing the window keeps magpie running, and
// offers Quit, Disconnect and quit (each agent's own settings put back,
// as its row's Disconnect does), or Cancel, with Don't ask again above
// them (zhujiu on Discord), which Settings › General › Ask before quitting
// turns back on. app.js imports this when the
// question is put, so it weighs nothing on the core.
window.askQuitSheet = async function () {
let agents;
try { ({ agents } = await api("quit")); } catch { agents = null; }
// nothing connected any more (disconnected meanwhile): the Quit goes on
if (agents && !agents.length) return api("window/quit?now=1", {});
const ed = el("div", "editor quit-ask");
const head = el("div", "ehead");
head.append(el("b", "", t("Quit magpie?")));
ed.append(head);
const one = agents?.length === 1;
ed.append(el("p", "lib-confirm", one
? t("{agent} goes through magpie, so it stops working while magpie is closed.", { agent: agents[0].name })
: t("These agents go through magpie, so they stop working while magpie is closed.")));
if (agents) {
const list = el("ul", "quit-agents");
for (const a of agents) {
const li = el("li");
li.append(icon(a.icon), el("span", "", a.name));
list.append(li);
}
ed.append(list);
}
const mac = document.body.classList.contains("mac");
ed.append(el("p", "ag-note", mac ? t("Closing the window keeps magpie running in the menu bar.")
: t("Closing the window keeps magpie running in the system tray.")));
// Don't ask again goes with the Quit chosen (noAsk=1 saves it), not with a Cancel
const [never, box] = tick(t("Don't ask again"), false);
never.classList.add("quit-never");
never.title = t("Settings › General › Ask before quitting turns it back on");
ed.append(never);
const bye = () => api("window/quit?now=1" + (box.checked ? "&noAsk=1" : ""), {});
const bar = el("div", "bar");
const quit = el("button", "text primary", t("Quit"));
const off = el("button", "text", t("Disconnect and quit"));
off.title = t("Puts back each agent's own settings first, so they work without magpie");
const cancel = el("button", "text", t("Cancel"));
const busy = (b, on) => {
for (const x of [quit, off, cancel, box]) x.disabled = on;
b.classList.toggle("busy", on);
};
quit.onclick = async (e) => {
e.stopPropagation();
busy(quit, true);
try { await bye(); } catch (err) { busy(quit, false); statusErr(err); }
};
// each agent put back as its row's Disconnect puts it back; one that
// can't be leaves magpie open, with the rest still listed
off.onclick = async (e) => {
e.stopPropagation();
busy(off, true);
for (const a of agents || []) {
try {
state = await api("agents/disconnect/" + a.id, {});
} catch (err) {
busy(off, false);
status(a.name + ": " + t(err.message), "err");
return;
}
}
try { await bye(); } catch (err) { busy(off, false); statusErr(err); }
};
cancel.onclick = cancelAsk;
if (agents) bar.append(off);
bar.append(el("span", "grow"), cancel, quit);
ed.append(bar);
confirmAsk = ed;
openModal(ed);
$("#modal").classList.add("lib");
quit.focus(NO_SCROLL);
};