diff --git a/docs/subsystems/gui-shell.md b/docs/subsystems/gui-shell.md
index a82fb53ff..9f9aa99a1 100644
--- a/docs/subsystems/gui-shell.md
+++ b/docs/subsystems/gui-shell.md
@@ -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
diff --git a/internal/gui/api.go b/internal/gui/api.go
index cad76dc65..1a6a09a40 100644
--- a/internal/gui/api.go
+++ b/internal/gui/api.go
@@ -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") == "" {
diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css
index 03b7eb10a..545a49001 100644
--- a/internal/gui/assets/app.css
+++ b/internal/gui/assets/app.css
@@ -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 */
diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js
index 0dce76e95..86f6928d0 100644
--- a/internal/gui/assets/app.js
+++ b/internal/gui/assets/app.js
@@ -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 || {},
diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js
index 055058b97..199386d1e 100644
--- a/internal/gui/assets/i18n.js
+++ b/internal/gui/assets/i18n.js
@@ -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",
diff --git a/internal/gui/assets/index.html b/internal/gui/assets/index.html
index b969843d6..b8be41653 100644
--- a/internal/gui/assets/index.html
+++ b/internal/gui/assets/index.html
@@ -232,6 +232,10 @@
Open at login
+
+
Ask before quitting
While agents go through magpie, Quit names them and asks first
+
+
Show in Dock
diff --git a/internal/gui/assets/quitask.js b/internal/gui/assets/quitask.js
index a96cc9e10..3bbbb2389 100644
--- a/internal/gui/assets/quitask.js
+++ b/internal/gui/assets/quitask.js
@@ -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);
diff --git a/internal/gui/quitask.go b/internal/gui/quitask.go
index cc7282dbc..4d34c0963 100644
--- a/internal/gui/quitask.go
+++ b/internal/gui/quitask.go
@@ -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()))
+}
diff --git a/internal/gui/quitask_app.go b/internal/gui/quitask_app.go
index 5b673fa8f..192e6ecb4 100644
--- a/internal/gui/quitask_app.go
+++ b/internal/gui/quitask_app.go
@@ -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
}
diff --git a/internal/gui/quitask_test.go b/internal/gui/quitask_test.go
index a068eb4ee..b65090a0f 100644
--- a/internal/gui/quitask_test.go
+++ b/internal/gui/quitask_test.go
@@ -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")
+ }
+}
diff --git a/internal/gui/tests/quit-ask-setting.test.cjs b/internal/gui/tests/quit-ask-setting.test.cjs
new file mode 100644
index 000000000..bbaa37fb0
--- /dev/null
+++ b/internal/gui/tests/quit-ask-setting.test.cjs
@@ -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