Files
magpie/internal/gui/assets/quitask.js
T
yetone 261f482260 gui: Disconnect and quit puts the agents back for the next start, which connects them again (jtbbtnt54249 on X)
jtbbtnt54249, on LolingVerse's agy thread: "很多都这样,退出有时候又要重新开启".
Several agents' switches were off after quitting magpie and had to be
turned on again by hand.

Looked for a shared path that flips agents off. The row's switch is
Wired() alone, and nothing automatic disconnects an agent except a
removed plugin, the gateway pause (which reconnects on resume) and
Put agents back when quitting (which reconnects at start). The quit
question's Disconnect and quit, though, ran each row's Disconnect,
which leaves the disconnectedKey mark: every agent it listed stayed off
at every start after, and RewireOnStart skips a marked agent. Users
choose it so their agents work while magpie is closed, not to leave
magpie for good.

Now Disconnect and quit posts quit/disconnect (quitDisconnect), which
runs agent.RestoreOnQuit on the agents the question lists: their own
files back, no mark, recorded in quit.restored, so the next start's
RewireOnStart connects them again, the setting on or off. This covers
every agent the question lists: every detected agent wired to magpie,
built-in, plugin and WSL ones alike. A failure answers an error naming
the agent and magpie stays open. Its tooltip says magpie connects them
again when it opens (en, zh, zh-TW, ja, de).

Run at this tree (parent 99a54fa87, origin/main just fetched):
- TestQuitDisconnectComesBackOnStart red on the old api.go and
  restoreonquit.go (404 on POST /api/quit/disconnect), green after.
- mote: go test -count=1 ./internal/gui ok (145s).
- mica: node --test quit-ask, quit-ask-setting, restore-on-quit,
  i18n-keys, i18n-en-no-cjk: 178 of 178 pass, chromium and webkit,
  every language.
- gofmt -l clean; go vet ./internal/gui on darwin and GOOS=windows ok.
  Linux vet of internal/gui needs GTK/WebKitGTK headers, which neither
  mote nor magpie-desktop has; not run.

Not tried: a real quit of the app with real agents; the agent-level
RestoreOnQuit then RewireOnStart path is covered by
TestRestoreOnQuitAndRewireOnStart. Agents disconnected this way by an
older magpie keep their mark and stay off until switched on once.
2026-11-15 23:30:05 +08:00

79 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
// until magpie opens again, which connects them again), 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; magpie connects them again when it opens");
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 Put agents back when quitting puts it back, so
// the next start connects it again (a row's Disconnect kept it off for
// good: jtbbtnt54249 on X); one that can't be leaves magpie open
off.onclick = async (e) => {
e.stopPropagation();
busy(off, true);
try {
state = await api("quit/disconnect", {});
} catch (err) {
busy(off, false);
statusErr(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);
};