Files
magpie/internal/gui/assets/cfgblocked.js
T
yetone 6aac51ac11 gui: Repair's dialog loads when needed, the core-script budget back to 1,530,861
5be581a1c raised the core-script budget by 1,112 bytes for the Repair
dialog (a magpie folder the user can't write, YouWhat). A raise bounds
nothing, so this takes it back. The budget is 1,530,861 again, and the
note beside it is gone.

The dialog moves out of app.js into cfgblocked.js. app.js imports that
file only when /api/state names a blocked folder or a save fails with
config_blocked, the way it imports webfonts.js. app.js keeps a one-line
stub (configBlockedAsk) and the api() mapping. The core scripts are now
1,530,628 bytes (budget 1,530,861) and app.js is 1,309,900 (budget
1,311,735). old-webkit's "loaded by index.html" check exempts
cfgblocked.js as it does webfonts.js. Its Safari 15 syntax and built-in
checks still read the file.

Run on mote, at this tree, based on 5be581a1c:
- gofmt -l: empty.
- node --test config-blocked, cli-behind, i18n-keys, old-webkit
  (Chromium and WebKit): 18/18 ok. config-blocked opens the dialog at
  load and over a failed save, through the lazy import, and Not now goes
  back to the editor.
- go test -timeout 45m ./internal/gui: TestCoreScriptBudget ok. The only
  red is TestMainWindowCorners/macOS_26_SDK, which is the same on
  origin/main on mote (#3949).
2026-10-29 22:14:41 +08:00

40 lines
2.0 KiB
JavaScript

// The Repair dialog for a folder on the way to magpie's own that isn't the
// user's, most often a ~/.config a command run with sudo made root's
// (YouWhat on Discord: adding a provider said "mkdir ~/.config/magpie:
// permission denied"). app.js imports this only when /api/state names such
// a folder or a save fails for it (configBlockedAsk), so it weighs nothing
// on the core. Repair makes the folder the user's again, after the system's
// password prompt; asked once a load, and again over whatever save failed,
// which "Not now" goes back to as it was left.
window.cfgBlockedAsk = function (path) {
if (confirmAsk?.classList.contains("cfg-blocked")) return;
configBlockedAsked = true;
const m = $("#modal"), under = !m.hidden && !m.classList.contains("out") && !confirmAsk && m.firstElementChild.firstElementChild;
const ed = el("div", "editor cfg-blocked"), head = el("div", "ehead"), bar = el("div", "bar");
head.append(el("b", "", t("magpie can't save its settings")));
ed.append(head, el("p", "lib-confirm", t("{path} belongs to another user, often after a command was run with sudo, so magpie can't save providers or settings there. Repair makes it yours again; the system may ask for your password.", { path })));
const later = el("button", "text", t("Not now")), go = el("button", "text primary", t("Repair"));
later.onclick = cancelAsk;
go.onclick = async (e) => {
e.stopPropagation();
go.disabled = true;
try {
if ((await api("config/repair", {}))?.canceled) return;
if (state) state.configBlocked = "";
closeConfirmAsk();
status(t("Repaired: magpie can save again"), "ok");
} catch (err) {
status(err.message, "err", 12000);
} finally {
go.disabled = false;
}
};
bar.append(el("span", "grow"), later, go);
ed.append(bar);
if (under) ed.back = () => openModal(under); // the editor whose save failed, as it was left
confirmAsk = ed;
openModal(ed);
m.classList.add("lib");
go.focus({ preventScroll: true });
};