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.
This commit is contained in:
yetone
2026-11-02 18:53:07 +08:00
parent b58669eb09
commit ed978e560f
17 changed files with 380 additions and 18 deletions
+12 -2
View File
@@ -641,13 +641,23 @@ that one keeps serving the agents and the Quit goes on).
line. With nothing connected any more it quits without drawing.
- A second Quit within a minute of the question (`quitNow`, `quitAgain`)
quits, so a window that can't show the question doesn't trap the user.
- Don't ask again (zhujiu on Discord), a tick above the buttons, unticked
each time, goes with the Quit or Disconnect and quit chosen as
`noAsk=1`: the handler saves `settings.QuitNoAsk` (`SetQuitNoAsk`, that
field alone) before quitting, and a save that fails keeps magpie open.
Cancel saves nothing. With `QuitNoAsk` set, `quitAtOnce` quits without
asking; a settings file that can't be read asks. Settings › General ›
Ask before quitting (`#quitAskRow`, the app's only) shows it as On/Off
and saves `quitNoAsk` through `POST /api/settings`, which keeps it when a
page doesn't send it.
- Not asked: a restart to update, Uninstall, a browser's page (`magpie
web`), logging out or shutting down, and the Dock's Quit (AppKit's
`terminate:`).
See `TestWindowQuitAsksFirst`, `TestQuitListsWiredAgents`,
`TestQuitAPIListsAgents`, `TestQuitNow`, `TestCommandQAsksFirst` and
`quit-ask.test.cjs`.
`TestQuitAPIListsAgents`, `TestQuitNow`, `TestCommandQAsksFirst`,
`TestQuitDontAskAgain`, `TestSetQuitNoAsk`, `TestQuitNoAskKeptUnlessSent`,
`quit-ask.test.cjs` and `quit-ask-setting.test.cjs`.
### A restart to update hands the gateway over
+9
View File
@@ -2528,6 +2528,15 @@ func Handler(w Windows, gw *gateway.Server) http.Handler {
case "main":
w.ShowMain(mainView(r.URL.Query()))
case "quit":
// the question's "Don't ask again" (noAsk=1, zhujiu on
// Discord) is saved before the quit; a save that fails keeps
// magpie open, saying why
if r.URL.Query().Get("noAsk") == "1" {
if err := settings.SetQuitNoAsk(true); err != nil {
fail(rw, err)
return
}
}
// the user's Quit asks first while agents are connected
// (quitask.go); the question's own Quit is now=1
if a, ok := w.(quitAsker); ok && r.URL.Query().Get("now") == "" {
+1
View File
@@ -4674,6 +4674,7 @@ body.window .row + .row.agent.conn > .who { min-height: 41px; } /* the line abov
.quit-ask .quit-agents li { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 13px; }
.quit-ask .quit-agents li > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quit-ask .ag-note { grid-column: 1 / -1; margin: 0 0 10px; font-size: 12px; color: var(--muted); }
.quit-ask .quit-never { grid-column: 1 / -1; margin: 0 0 10px; font-size: 12px; }
@media (max-width: 600px) {
body.window .row.agent.conn { display: flex; }
/* the name beside its logo; the link and the switch wrap under it when short of room */
+7 -6
View File
@@ -19711,7 +19711,7 @@ function renderSettings() {
renderGatewayMode(s);
// a browser tab has its own zoom, and magpie leaves it to it
$("#textSizeRow").hidden = web;
// the keys that do it too, kept in the choices' tooltip, the row saying no more than its name
// the keys that do it too, in the choices' tooltip
$("#textSizeSegs").title = t("Everything in magpie's windows, larger; {keys} too", { keys: textSizeKeys() });
$("#textSizeSegs").replaceChildren(segs(TEXT_SIZES.map((n) => [n, n + "%"]), s.textSize || 100, (n) => setTextSize(n)));
$("#traySegs").replaceChildren(segs(TRAYS.map(([id, name]) => [id, t(name)]), s.tray || "panel", (tray) => savePrefs({ ...keep, tray })));
@@ -19725,16 +19725,18 @@ function renderSettings() {
$("#lightweightRow").hidden = web;
$("#lightweightSegs").replaceChildren(segs([["off", t("Off")], ["on", t("On")]], s.lightweight === true ? "on" : "off",
(v) => savePrefs({ ...keep, lightweight: v === "on" })));
// the display kept on too (#975): an agent recording the screen found it locked
// the display kept on too (#975)
$("#keepAwakeSegs").replaceChildren(segs([["off", t("Off")], ["on", t("On")], ["display", t("Screen on too")]],
!s.keepAwake ? "off" : s.keepAwakeDisplay ? "display" : "on",
(v) => savePrefs({ ...keep, keepAwake: v !== "off", keepAwakeDisplay: v === "display" })));
// its line says what the choice does; data-en keeps a language change on it
// its line says what it does; data-en keeps it on a language change
const awakeSub = $("#keepAwakeRow .sub");
awakeSub.dataset.en = s.keepAwake && s.keepAwakeDisplay
? "Keeps this computer and its screen awake while magpie runs tasks"
: "Keeps this computer awake while magpie runs tasks";
awakeSub.textContent = t(awakeSub.dataset.en);
// quitask.js's question
$("#quitAskSegs").replaceChildren(segs([["off", t("Off")], ["on", t("On")]], s.quitNoAsk ? "off" : "on", (v) => savePrefs({ ...keep, quitNoAsk: v === "off" })));
// WSL's distros, looked in on Windows unless turned off (#1264)
$("#wslAgentsRow").hidden = !s.wsl;
$("#wslAgentsSegs").replaceChildren(segs([["off", t("Off")], ["on", t("On")]], s.noWSLAgents ? "off" : "on",
@@ -19749,8 +19751,7 @@ function renderSettings() {
$("#loginSegs").replaceChildren(segs([["off", t("Off")], ["on", t("On")]], s.login ? "on" : "off", (v) =>
prefWrite(api("settings/login", { on: v === "on" }))));
renderLoginAllow(s);
// Codex's and Claude Code's warm-ups and WorkBuddy's check-in, one tab
// each over one card, the rows' names not saying the service again.
// the warm-ups and check-in, one tab each over one card
// A ChatGPT account's next window started as soon as the last resets
$("#warmSegs").replaceChildren(segs([["off", t("Off")], ["week", t("Weekly")], ["all", t("Weekly and 5-hour")]],
s.codexWarmup || "off", (v) => savePrefs({ ...keep, codexWarmup: v === "off" ? "" : v })));
@@ -22650,7 +22651,7 @@ function dockChoice(s) {
// prefsKeep is what the settings page sends of s, all of it each time.
function prefsKeep(s) {
return { theme: s.theme, colorblind: !!s.colorblind, reduceMotion: !!s.reduceMotion, noBird: !!s.noBird, lang: s.lang, tray: s.tray, dock: !!s.dock, dockWindow: !!s.dockWindow, dockNever: !!s.dockNever, lightweight: s.lightweight, keepAwake: !!s.keepAwake, keepAwakeDisplay: !!s.keepAwakeDisplay, noWSLAgents: !!s.noWSLAgents, proxy: s.proxy || "",
return { theme: s.theme, colorblind: !!s.colorblind, reduceMotion: !!s.reduceMotion, noBird: !!s.noBird, lang: s.lang, tray: s.tray, dock: !!s.dock, dockWindow: !!s.dockWindow, dockNever: !!s.dockNever, lightweight: s.lightweight, keepAwake: !!s.keepAwake, keepAwakeDisplay: !!s.keepAwakeDisplay, noWSLAgents: !!s.noWSLAgents, quitNoAsk: !!s.quitNoAsk, proxy: s.proxy || "",
sessionTerminal: s.sessionTerminal || "",
uiFont: s.uiFont || null, codeFont: s.codeFont || null,
otel: s.otel || {},
+16
View File
@@ -617,6 +617,10 @@ const I18N = {
"Closing the window keeps magpie running in the menu bar.": "关闭窗口时 magpie 会继续在菜单栏中运行。",
"Closing the window keeps magpie running in the system tray.": "关闭窗口时 magpie 会继续在系统托盘中运行。",
"Disconnect and quit": "断开并退出",
"Ask before quitting": "退出前询问",
"While agents go through magpie, Quit names them and asks first": "有 Agent 通过 magpie 连接时,退出前先列出它们并询问",
"Don't ask again": "不再提示",
"Settings › General › Ask before quitting turns it back on": "可在 设置 › 常规 › 退出前询问 里重新打开",
"Puts back each agent's own settings first, so they work without magpie": "先恢复每个 Agent 自己的设置,让它们不经过 magpie 也能使用",
"magpie takes out everything it wrote into {agent}'s config — its endpoint, key, models and effort — and puts back the settings {agent} had before. magpie's providers and accounts stay as they are.": "移除 magpie 写入 {agent} 配置的所有内容(接口地址、密钥、模型和推理强度),还原 {agent} 之前的设置。magpie 的供应商和账号不受影响。",
"Disconnect": "断开",
@@ -5033,6 +5037,10 @@ const I18N = {
"Closing the window keeps magpie running in the menu bar.": "關閉視窗時 magpie 會繼續在選單列中執行。",
"Closing the window keeps magpie running in the system tray.": "關閉視窗時 magpie 會繼續在系統匣中執行。",
"Disconnect and quit": "斷開並退出",
"Ask before quitting": "退出前詢問",
"While agents go through magpie, Quit names them and asks first": "有 Agent 透過 magpie 連線時,退出前先列出它們並詢問",
"Don't ask again": "不再提示",
"Settings › General › Ask before quitting turns it back on": "可在 設定 › 常規 › 退出前詢問 裡重新開啟",
"Puts back each agent's own settings first, so they work without magpie": "先還原每個 Agent 自己的設定,讓它們不經過 magpie 也能使用",
"magpie takes out everything it wrote into {agent}'s config — its endpoint, key, models and effort — and puts back the settings {agent} had before. magpie's providers and accounts stay as they are.": "移除 magpie 寫入 {agent} 設定的所有內容(介面位址、金鑰、模型和推理強度),還原 {agent} 之前的設定。magpie 的供應商和帳號不受影響。",
"Disconnect": "斷開",
@@ -9414,6 +9422,10 @@ const I18N = {
"Closing the window keeps magpie running in the menu bar.": "ウインドウを閉じても magpie はメニューバーで動作し続けます。",
"Closing the window keeps magpie running in the system tray.": "ウインドウを閉じても magpie はシステムトレイで動作し続けます。",
"Disconnect and quit": "切断して終了",
"Ask before quitting": "終了前に確認",
"While agents go through magpie, Quit names them and asks first": "エージェントが magpie を経由しているとき、終了前にそれらを示して確認します",
"Don't ask again": "今後は確認しない",
"Settings › General › Ask before quitting turns it back on": "設定 › 一般 › 終了前に確認 でもう一度オンにできます",
"Puts back each agent's own settings first, so they work without magpie": "まず各エージェント自身の設定に戻し、magpie なしでも動作するようにします",
"magpie takes out everything it wrote into {agent}'s config — its endpoint, key, models and effort — and puts back the settings {agent} had before. magpie's providers and accounts stay as they are.": "magpie は {agent} の設定に書き込んだ内容(エンドポイント、キー、モデル、推論レベル)をすべて削除し、{agent} を以前の設定に戻します。magpie のプロバイダとアカウントはそのままです。",
"Disconnect": "切断",
@@ -13813,6 +13825,10 @@ const I18N = {
"Closing the window keeps magpie running in the menu bar.": "Wenn du das Fenster schließt, läuft magpie in der Menüleiste weiter.",
"Closing the window keeps magpie running in the system tray.": "Wenn du das Fenster schließt, läuft magpie im Infobereich weiter.",
"Disconnect and quit": "Trennen und beenden",
"Ask before quitting": "Vor dem Beenden fragen",
"While agents go through magpie, Quit names them and asks first": "Solange Agenten über magpie laufen, nennt Beenden sie und fragt zuerst nach",
"Don't ask again": "Nicht mehr fragen",
"Settings › General › Ask before quitting turns it back on": "Einstellungen › Allgemein › Vor dem Beenden fragen schaltet es wieder ein",
"Puts back each agent's own settings first, so they work without magpie": "Stellt zuerst die eigenen Einstellungen jedes Agenten wieder her, damit er ohne magpie funktioniert",
"magpie takes out everything it wrote into {agent}'s config — its endpoint, key, models and effort — and puts back the settings {agent} had before. magpie's providers and accounts stay as they are.": "magpie entfernt alles, was es in die Konfiguration von {agent} geschrieben hat — Endpunkt, Schlüssel, Modelle und Reasoning-Effort — und stellt die vorherigen Einstellungen von {agent} wieder her. Anbieter und Konten in magpie bleiben unverändert.",
"Disconnect": "Trennen",
+4
View File
@@ -232,6 +232,10 @@
<div class="who"><div class="name" data-t>Open at login</div></div>
<div id="loginSegs"></div>
</div>
<div class="row pref app-only" id="quitAskRow">
<div class="who"><div class="name" data-t>Ask before quitting</div><div class="sub" data-t>While agents go through magpie, Quit names them and asks first</div></div>
<div id="quitAskSegs"></div>
</div>
<div class="row pref" id="dockRow" hidden>
<div class="who"><div class="name" data-t>Show in Dock</div></div>
<div id="dockSegs"></div>
+12 -4
View File
@@ -3,7 +3,9 @@
// 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. app.js imports this when the
// 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;
@@ -30,19 +32,25 @@ window.askQuitSheet = async function () {
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]) x.disabled = 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 api("window/quit?now=1", {}); } catch (err) { busy(quit, false); statusErr(err); }
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
@@ -58,7 +66,7 @@ window.askQuitSheet = async function () {
return;
}
}
try { await api("window/quit?now=1", {}); } catch (err) { busy(off, false); statusErr(err); }
try { await bye(); } catch (err) { busy(off, false); statusErr(err); }
};
cancel.onclick = cancelAsk;
if (agents) bar.append(off);
+14 -1
View File
@@ -4,6 +4,7 @@ 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
@@ -14,7 +15,9 @@ import (
// 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. A quit magpie makes itself (a restart to
// 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.
@@ -66,3 +69,13 @@ func quitNow(asked int64, now time.Time, wired int) bool {
}
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()))
}
+2 -2
View File
@@ -16,11 +16,11 @@ const (
)
// AskQuit is a Quit the user chose: at once while no agent is connected to
// the gateway this process serves, else the window comes up and asks
// 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 quitNow(h.quitAt.Load(), time.Now(), len(quitAgents())) {
if quitAtOnce(h.quitAt.Load(), time.Now()) {
h.app.Quit()
return
}
+42
View File
@@ -7,6 +7,7 @@ import (
"time"
"github.com/yetone/magpie/internal/agent"
"github.com/yetone/magpie/internal/settings"
)
// A Quit the user chose while agents go through magpie asks first
@@ -128,3 +129,44 @@ func TestQuitNow(t *testing.T) {
}
}
}
// "Don't ask again" (zhujiu on Discord): the question's Quit sent with
// noAsk=1 saves settings.QuitNoAsk and quits; from then on a Quit with
// agents connected quits at once, until Settings › General › Ask before
// quitting turns the question back on.
func TestQuitDontAskAgain(t *testing.T) {
sandboxHome(t)
old := quitAgents
t.Cleanup(func() { quitAgents = old })
quitAgents = func() []quitAgentJSON { return []quitAgentJSON{{ID: "codex", Name: "Codex", Icon: "openai"}} }
now := time.Now()
if quitAtOnce(0, now) {
t.Fatal("with Codex connected, the first Quit quit without asking")
}
quits := 0
h := Handler(askingHost{webHost{quit: func() { quits++ }}, make(chan struct{}, 1)}, nil)
r := httptest.NewRecorder()
h.ServeHTTP(r, httptest.NewRequest("POST", "/api/window/quit?now=1&noAsk=1", nil))
if r.Code != 204 || quits != 1 {
t.Fatalf("the question's Quit with Don't ask again: %d %s, %d quits", r.Code, r.Body, quits)
}
if !settings.Load().QuitNoAsk {
t.Fatal("Don't ask again wasn't saved")
}
if !quitAtOnce(0, now) {
t.Fatal("after Don't ask again, a Quit with Codex connected still asks")
}
if err := settings.SetQuitNoAsk(false); err != nil {
t.Fatal(err)
}
if quitAtOnce(0, now) {
t.Fatal("with Ask before quitting on again, a Quit didn't ask")
}
// a plain Quit from the question saves nothing
h.ServeHTTP(httptest.NewRecorder(), httptest.NewRequest("POST", "/api/window/quit?now=1", nil))
if settings.Load().QuitNoAsk {
t.Fatal("the question's Quit without Don't ask again saved it")
}
}
@@ -0,0 +1,138 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// zhujiu on Discord: the Quit question (quit-ask.test.cjs) wants a way not
// to be asked again, and a switch to have it back. Settings › General ›
// Ask before quitting is On by default, says when it asks, and Off saves
// quitNoAsk with the rest of the settings kept; a quitNoAsk the question's
// Don't ask again saved shows Off, and On saves it false. The app's only:
// a browser's page (magpie web) quits without asking, so the row isn't
// there. In every language, both engines, 1100 and 420 wide; segments,
// never a native <select>, and the click moves nothing.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const { watchSettingsReads, settingsDrawn } = require("./reader.cjs");
const assets = path.resolve(__dirname, "../assets");
const words = {
en: { name: "Ask before quitting", off: "Off", on: "On", sub: "Quit names them and asks first" },
zh: { name: "退出前询问", off: "关闭", on: "开启", sub: "退出前先列出它们并询问" },
"zh-TW": { name: "退出前詢問", off: "關閉", on: "開啟", sub: "退出前先列出它們並詢問" },
ja: { name: "終了前に確認", off: "オフ", on: "オン", sub: "終了前にそれらを示して確認します" },
de: { name: "Vor dem Beenden fragen", off: "Aus", on: "An", sub: "nennt Beenden sie und fragt zuerst nach" },
};
function serve(lang, saved, own, web) {
const settings = { lang, theme: "light", redact: true, keepAwake: true, ...own };
const state = { agents: [], profiles: [], settings };
return async (r) => {
const url = new URL(r.request().url());
const json = (data) => r.fulfill({ json: data });
if (url.pathname === "/boot.js") return r.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:${web}};` });
if (url.pathname === "/wails/runtime.js") return r.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return json(state);
if (url.pathname === "/api/settings") {
if (r.request().method() === "POST") {
saved.push(JSON.parse(r.request().postData()));
Object.assign(settings, saved.at(-1));
}
return json(settings);
}
if (url.pathname === "/api/groups") return json({ models: [], groups: [], pools: [] });
if (url.pathname === "/api/plugins") return json({ plugins: [] });
if (url.pathname === "/api/usage/quotas") return json([]);
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true, url: "http://127.0.0.1:3999" } });
if (url.pathname.startsWith("/api/")) return json({});
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
await r.fulfill({ body: await fs.readFile(file), contentType });
};
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of Object.keys(words)) for (const width of [1100, 420]) {
const w = words[lang];
const open = async (t, own = {}, web = false) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const page = await (await browser.newContext({ viewport: { width, height: 900 } })).newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
t.after(() => assert.deepEqual(errors, []));
const saved = [];
await page.route("**/*", serve(lang, saved, own, web));
await watchSettingsReads(page);
await page.goto("http://magpie.test/?view=settings&tab=general");
await settingsDrawn(page);
return { page, saved };
};
// scrolled to as a reader does, with the wheel
const reach = async (page, row) => {
await page.mouse.move(width / 2, 450);
for (let i = 0; i < 40; i++) {
const box = await row.boundingBox();
if (box && box.y >= 0 && box.y + box.height <= 900) break;
await page.mouse.wheel(0, 120);
await page.waitForTimeout(50);
}
};
const press = async (page, button) => {
const b = await button.boundingBox();
await page.mouse.click(b.x + b.width / 2, b.y + b.height / 2);
};
const until = async (f) => { for (let i = 0; i < 100 && !f(); i++) await new Promise((r) => setTimeout(r, 50)); };
test(`${engine} ${lang} ${width}: Ask before quitting is On, and Off saves quitNoAsk`, async (t) => {
const { page, saved } = await open(t);
const row = page.locator("#setPage-general #quitAskRow");
await row.waitFor();
await reach(page, row);
assert.equal(await row.locator(".name").textContent(), w.name);
assert.ok((await row.locator(".sub").textContent()).includes(w.sub));
for (const part of [".name", ".sub", ".segs"]) {
const fit = await row.locator(part).first().evaluate((e) => {
const r = e.getBoundingClientRect();
return e.scrollWidth <= e.clientWidth + 1 && r.width > 0 && r.left >= 0 && r.right <= innerWidth + 1;
});
assert.ok(fit, `${part} fits at ${width}`);
}
assert.equal(await row.locator("select").count(), 0, "no native <select>");
const on = row.locator(".segs button", { hasText: w.on });
const off = row.locator(".segs button", { hasText: w.off });
assert.equal(await on.getAttribute("aria-pressed"), "true", "On by default");
const before = await page.evaluate(() => [scrollX, scrollY, document.querySelector("#view-settings")?.scrollTop]);
await press(page, off);
await until(() => saved.length);
assert.equal(saved.length, 1, "saved once");
assert.equal(saved[0].quitNoAsk, true);
assert.equal(saved[0].keepAwake, true, "the row near it kept");
assert.equal(saved[0].redact, true, "the rest kept");
assert.equal(saved[0].lang, lang);
assert.deepEqual(await page.evaluate(() => [scrollX, scrollY, document.querySelector("#view-settings")?.scrollTop]), before, "the click moved nothing");
});
test(`${engine} ${lang} ${width}: after Don't ask again it shows Off, and On asks again`, async (t) => {
const { page, saved } = await open(t, { quitNoAsk: true });
const row = page.locator("#setPage-general #quitAskRow");
await row.waitFor();
await reach(page, row);
const on = row.locator(".segs button", { hasText: w.on });
assert.equal(await row.locator(".segs button", { hasText: w.off }).getAttribute("aria-pressed"), "true", "Off, as the question left it");
await press(page, on);
await until(() => saved.length);
assert.equal(saved.length, 1, "saved once");
assert.equal(saved[0].quitNoAsk, false);
assert.equal(saved[0].keepAwake, true, "the rest kept");
});
if (width === 420) test(`${engine} ${lang}: a browser's page has no Ask before quitting`, async (t) => {
const { page } = await open(t, {}, true);
await page.locator("#setPage-general #langPick").waitFor({ state: "attached" });
assert.equal(await page.locator("#quitAskRow").isVisible(), false);
});
}
}
+44 -1
View File
@@ -9,7 +9,10 @@
// and Cancel. Cancel posts nothing; Quit posts window/quit?now=1, which
// quits without asking again; Disconnect and quit disconnects each agent
// in turn and then quits, and a disconnect that fails keeps magpie open.
// With nothing connected any more it quits at once. In every language and
// With nothing connected any more it quits at once. Don't ask again
// (zhujiu on Discord), above the buttons and unticked, goes with the Quit
// chosen as noAsk=1 (the server saves settings.QuitNoAsk), and its tooltip
// names Settings › General › Ask before quitting. In every language and
// both engines; no backend, the API is faked here.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
@@ -32,6 +35,8 @@ const keys = [
"Puts back each agent's own settings first, so they work without magpie",
"Quit",
"Cancel",
"Don't ask again",
"Settings › General › Ask before quitting turns it back on",
];
// until waits for f to hold (the posts the page makes), at most 5s
@@ -137,6 +142,44 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.deepEqual(posts, ["/api/agents/disconnect/codex", "/api/agents/disconnect/claude", "/api/window/quit?now=1"]);
});
test(`${engine} ${lang}: Don't ask again goes with the Quit, narrow too`, async (t) => {
const { page, posts, tr } = await open(t, { agents: two }, "Win32", "/?ask=quit", 420);
const ask = page.locator(".editor.quit-ask");
await ask.waitFor();
const never = ask.locator("label.quit-never");
assert.equal((await never.textContent()).trim(), await tr("Don't ask again"));
assert.equal(await never.getAttribute("title"), await tr("Settings › General › Ask before quitting turns it back on"));
const box = never.locator("input[type=checkbox]");
assert.equal(await box.isChecked(), false, "unticked at first");
const [sheet, line, bar] = await Promise.all([ask.boundingBox(), never.boundingBox(), ask.locator(".bar").boundingBox()]);
assert.ok(line.x >= sheet.x - 1 && line.x + line.width <= sheet.x + sheet.width + 1, "it fits a narrow window");
assert.ok(line.y + line.height <= bar.y + 1, "above the buttons");
// ticked then Cancel saves nothing
await never.click();
assert.equal(await box.isChecked(), true);
await ask.locator(".bar button", { hasText: await tr("Cancel") }).click();
await ask.waitFor({ state: "detached" });
assert.deepEqual(posts, []);
// asked again, it is unticked; ticked, the Quit carries it
await page.evaluate(() => window.askQuit());
await ask.waitFor();
assert.equal(await box.isChecked(), false, "a new question starts unticked");
await never.click();
await ask.locator(".bar button.primary").click();
await until(() => posts.length);
assert.deepEqual(posts, ["/api/window/quit?now=1&noAsk=1"]);
});
test(`${engine} ${lang}: Don't ask again goes with Disconnect and quit too`, async (t) => {
const { page, posts, tr } = await open(t, { agents: two.slice(0, 1) });
const ask = page.locator(".editor.quit-ask");
await ask.waitFor();
await ask.locator("label.quit-never").click();
await ask.locator(".bar button", { hasText: await tr("Disconnect and quit") }).click();
await until(() => posts.length >= 2);
assert.deepEqual(posts, ["/api/agents/disconnect/codex", "/api/window/quit?now=1&noAsk=1"]);
});
test(`${engine} ${lang}: a disconnect that fails keeps magpie open`, async (t) => {
const { page, posts, tr } = await open(t, { agents: two, fail: "codex" });
const ask = page.locator(".editor.quit-ask");
+1 -1
View File
@@ -32,7 +32,7 @@ const system = { en: "System", zh: "跟随系统", "zh-TW": "跟隨系統", ja:
// the rows whose name says enough, found by the control they hold
const bare = ["#themeSegs", "#colorblindSegs", "#reduceMotionSegs", "#birdSegs", "#langPick", "#textSizeSegs", "#traySegs", "#plainNamesSegs", "#loginSegs", "#dockSegs"];
// the rows that keep a line, one each
const kept = ["#lightweightSegs", "#keepAwakeSegs", "#sessionTerminalRow .sess-pick"];
const kept = ["#lightweightSegs", "#keepAwakeSegs", "#quitAskSegs", "#sessionTerminalRow .sess-pick"];
function serve(lang, posted, st) {
const settings = () => ({ lang, theme: "light", searchVendors: [], searchAPIs: [], ...st });
+30
View File
@@ -0,0 +1,30 @@
package settings
import "testing"
// A Quit asks first by default (zhujiu on Discord asked for a way not to
// be asked again); the question's "Don't ask again" sets QuitNoAsk alone,
// keeping what the user set elsewhere, and turns back off the same way.
func TestSetQuitNoAsk(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
if Load().QuitNoAsk {
t.Fatal("a Quit doesn't ask by default")
}
s := Load()
s.Theme, s.NoBird = "dark", true
if err := Save(s); err != nil {
t.Fatal(err)
}
if err := SetQuitNoAsk(true); err != nil {
t.Fatal(err)
}
if got := Load(); !got.QuitNoAsk || got.Theme != "dark" || !got.NoBird {
t.Fatalf("after SetQuitNoAsk(true): quitNoAsk %v, theme %q, noBird %v", got.QuitNoAsk, got.Theme, got.NoBird)
}
if err := SetQuitNoAsk(false); err != nil {
t.Fatal(err)
}
if got := Load(); got.QuitNoAsk || got.Theme != "dark" {
t.Fatalf("after SetQuitNoAsk(false): quitNoAsk %v, theme %q", got.QuitNoAsk, got.Theme)
}
}
+19
View File
@@ -565,6 +565,12 @@ type Settings struct {
// opening was too slow to have by default (the owner, 10-21: "太卡");
// one who turned it on keeps it on (LightweightOn).
Lightweight *bool `json:"lightweight,omitempty"`
// QuitNoAsk lets a Quit the user chooses quit at once while agents go
// through magpie, without the question that names them (gui's
// quitask.go). Off by default, it asks; the question's "Don't ask
// again" sets it, and Settings › General › Ask before quitting turns
// it back off (zhujiu on Discord).
QuitNoAsk bool `json:"quitNoAsk,omitempty"`
// KeepAwake keeps this computer from going to sleep by itself while
// agents work through the gateway and for a while after (xiao_wang24004
// on X; internal/awake). This computer's own (KeepOwn).
@@ -1801,6 +1807,19 @@ func SetGatewayConversations(on bool) error {
return save(s, true)
}
// SetQuitNoAsk sets QuitNoAsk alone, from what the file holds now (the
// Quit question's "Don't ask again"). A settings file that can't be read
// is left as it is, with the error.
func SetQuitNoAsk(on bool) error {
defer lockFile()()
s, err := loadChecked()
if err != nil {
return err
}
s.QuitNoAsk = on
return save(s, false)
}
// RouterNoteMost is how many characters RouterNote keeps: a few words,
// said before every tool's description.
const RouterNoteMost = 80
+6 -1
View File
@@ -31,7 +31,7 @@ var Keys = []string{
"theme", "colorblind", "reduceMotion", "noBird", "lang", "uiFont", "codeFont",
// the tray, the Dock and this computer
"tray", "dock", "dockWindow", "dockNever", "lightweight", "keepAwake", "keepAwakeDisplay",
"noWSLAgents", "sessionTerminal", "signInLinkOnly",
"noWSLAgents", "sessionTerminal", "signInLinkOnly", "quitNoAsk",
// the menu bar's allowance cards
"trayUsages", "trayUsage", "trayUsageEvery", "trayNoLogos", "trayNoBird", "trayNoNumber", "trayPace", "trayNoCost", "trayWindows",
// usage and alerts
@@ -214,6 +214,11 @@ func Merge(body []byte, cur settings.Settings, web bool) (settings.Settings, err
if _, sent := fields["noBird"]; !sent {
in.NoBird = cur.NoBird
}
// nor whether a Quit asks first while agents go through magpie
// (zhujiu on Discord), which the Quit question sets too
if _, sent := fields["quitNoAsk"]; !sent {
in.QuitNoAsk = cur.QuitNoAsk
}
// nor whether a value masked for the first time is told (Must2333)
if _, sent := fields["maskAlert"]; !sent {
in.MaskAlert = cur.MaskAlert
+23
View File
@@ -213,3 +213,26 @@ func TestRefusedValueWritesNothing(t *testing.T) {
t.Error("Body took port, which has a route of its own")
}
}
// "Don't ask again" on the Quit question (zhujiu on Discord) holds across
// a save from a page that doesn't send quitNoAsk (the tray panel, or a
// page from before it), and Settings › General's Ask before quitting
// sending it false turns the question back on.
func TestQuitNoAskKeptUnlessSent(t *testing.T) {
cur := settings.Defaults()
cur.QuitNoAsk = true
in, err := Merge([]byte(`{"theme":"dark"}`), cur, false)
if err != nil {
t.Fatal(err)
}
if !in.QuitNoAsk {
t.Error("a save that didn't send quitNoAsk turned the Quit question back on")
}
in, err = Merge([]byte(`{"theme":"dark","quitNoAsk":false}`), cur, false)
if err != nil {
t.Fatal(err)
}
if in.QuitNoAsk {
t.Error("quitNoAsk sent false left the Quit question off")
}
}