gui: About's licenses dialog and Sync's Restore and Upload asks load when opened, so the core is back in its budget (#5720)

TestCoreScriptBudget was red on main since 4436b7d98 (Make first under
Smart, CryptoSarom on X), which added 1,080 bytes to app.js and took the
core's scripts to 1,534,166, 364 over 1,533,802 (its parent was at
1,533,086). The budget is not raised (LESSONS: a budget raised whenever a
change reaches it bounds nothing); code that only runs when a dialog opens
moves out instead:

- Settings > About's Open-source licenses dialog (showNotices) is now
  notices.js, imported when View is pressed.
- Sync's Restore from the server and Upload asks (askRestore, askUpload)
  join Sync's forms in syncfiles.js; syncFile imports it for them when
  pressed, and an import that fails says so in the status line.

app.js is 1,307,923 bytes (was 1,311,541) and the core 1,530,548, 3,254
under its budget. old-webkit's list of lazily loaded files names
notices.js; the budget's comment records this.

Run on mote at this tree (on origin/main ed0ab567c):
- gofmt -l internal/gui: nothing; node --check app.js, notices.js,
  syncfiles.js: ok.
- go test -tags nogui -run TestCoreScriptBudget ./internal/gui: PASS
  (red at ed0ab567c, per #5720).
- go test -tags nogui -timeout 45m ./internal/gui: ok (80.9s).
- node --test, chromium and webkit, every language and width the files
  have: about-notices, old-webkit, i18n-keys, auto-backup, github-sync,
  s3-sync and every sync-*.test.cjs: 210 of 212 pass. sync-auto-restore
  and sync-not-backup press Restore and Upload through the new import;
  about-notices opens the licenses. The 2 reds are red the same way at
  origin/main ed0ab567c in a clean worktree, alone: i18n-keys "a plugin's
  words are its own" (#5332, #5426, #5482) and s3-sync webkit en "picking
  S3 must not scroll the page", 3 of 3 (#3413); both commented there.

Not tried: the real app; the whole GUI suite.
This commit is contained in:
yetone
2026-11-09 04:37:47 +08:00
parent ed0ab567cb
commit 192d2eda81
5 changed files with 117 additions and 109 deletions
+9 -103
View File
@@ -18297,23 +18297,8 @@ async function askReset(q) {
window.askQuit = () => import("./quitask.js").then(() => askQuitSheet(), () => api("window/quit?now=1", {}));
// closes a confirmation, nothing more (its Cancel, or an OK that only dismisses)
function cancelAsk(e) { e.stopPropagation(); closeConfirmAsk(); }
// THIRD_PARTY_NOTICES, which every build carries
async function showNotices() {
let text;
try { text = (await api("notices")).text; } catch (e) { statusErr(e); return; }
const ed = el("div", "editor wide notices");
const head = el("div", "ehead");
head.append(el("b", "", t("Open-source licenses")));
const bar = el("div", "bar");
const ok = el("button", "text primary", t("Done"));
ok.onclick = cancelAsk;
bar.append(el("span", "grow"), ok);
ed.append(head, el("pre", "notices-text", text), bar);
confirmAsk = ed;
openModal(ed);
$("#modal").classList.add("lib");
ok.focus(NO_SCROLL);
}
// About's licenses (notices.js, loaded when opened)
const showNotices = () => import("./notices.js").then(() => noticesSheet(), statusErr);
function closeConfirmAsk() {
if (!confirmAsk) return;
// Escape and the backdrop must not expose row actions while a bulk write
@@ -20258,7 +20243,7 @@ async function renderSync(v) {
// computer's setup can go up in its place, the user choosing it
if (v.on && v.error && v.serverFile?.replace) {
row(t("Upload this computer's setup"), t("It replaces the file on the server. That file is kept in the sync folder first."),
btn(t("Upload…"), () => askUpload(v.serverFile)));
btn(t("Upload…"), () => syncFile("askUpload", v.serverFile)));
}
// agent fields set back here after a sync changed them (hayden4608)
if (v.on && v.agents !== false && v.own?.length) {
@@ -20298,7 +20283,7 @@ async function renderSync(v) {
renderSync(await api("davsync/auto", { minutes: m || -1 }).catch((x) => ({ ...v, error: x.message })));
}));
row(t("Restore from the server"), t("This computer's setup becomes the one on the server. What is here now is kept first, to undo."),
btn(t("Restore…"), () => askRestore(v, parts)));
btn(t("Restore…"), () => syncFile("askRestore", v, parts)));
}
// export and import
@@ -20311,57 +20296,16 @@ async function renderSync(v) {
if (window.autoBackupFill) autoBackupFill(ab); else import("./autobackup.js").then(() => autoBackupFill(ab), () => {});
}
// syncFile draws the server's, Export's or Import's form, from syncfiles.js once loaded
function syncFile(f, v) {
if (window[f]) return window[f](v);
// syncFile draws the server's, Export's or Import's form, or asks before a
// Restore or Upload, from syncfiles.js once loaded
function syncFile(f, v, ...more) {
if (window[f]) return window[f](v, ...more);
if (f.startsWith("ask")) return import("./syncfiles.js").then(() => window[f](v, ...more), statusErr);
const at = el("div");
import("./syncfiles.js").then(() => at.replaceWith(window[f](v)), () => {});
return at;
}
// askRestore asks before the server's setup replaces this computer's
// (#847); what is here is kept, and the notice it leaves can undo it.
function askRestore(v, parts) {
const ed = el("div", "editor restore-ask");
const head = el("div", "ehead");
head.append(el("b", "", t("Restore from the server?")));
ed.append(head);
const goes = ["providers", "settings", "profiles"];
if (v.agents !== false) goes.push("agents");
if (v.library !== false) goes.push("library");
ed.append(el("p", "lib-confirm", t("This computer's {parts} become the ones on the server, as your other computers last synced them. Whatever was changed here since is replaced.", { parts: parts(goes) })));
ed.append(el("p", "lib-confirm", t("What is here now is sealed into the sync folder first, and Undo puts it back.")));
const err = el("p", "editor-error", "");
ed.append(err);
const bar = el("div", "bar");
const go = el("button", "text primary danger-fill", t("Restore setup"));
go.onclick = async (e) => {
e.stopPropagation();
go.disabled = true;
go.classList.add("busy");
try {
const r = await api("davsync/restore", {});
closeConfirmAsk();
renderSync(r);
if (r.error) return;
if (r.brought?.length) refreshAfterSync();
else status(t("This computer's setup is already the server's: nothing to restore"), "ok");
} catch (x) {
go.disabled = false;
go.classList.remove("busy");
err.textContent = x.message;
}
};
const cancel = el("button", "text", t("Cancel"));
cancel.onclick = cancelAsk;
bar.append(el("span", "grow"), cancel, go);
ed.append(bar);
confirmAsk = ed;
openModal(ed);
$("#modal").classList.add("lib");
cancel.focus(NO_SCROLL);
}
// serverFileSaid: what the server holds where the backup should be, in the
// reader's language, from what davsync told of it (never its contents).
function serverFileSaid(f) {
@@ -20381,44 +20325,6 @@ function serverFileSaid(f) {
return t("the file on the server isn't a magpie backup: it is {type} ({size})", { type: f.type || "?", size });
}
// askUpload asks before this computer's setup replaces a server file that
// isn't a backup; the server's file is kept in the sync folder first.
function askUpload(f) {
const ed = el("div", "editor restore-ask upload-ask");
const head = el("div", "ehead");
head.append(el("b", "", t("Replace the file on the server?")));
ed.append(head);
ed.append(el("p", "lib-confirm", t("This computer's setup goes up in place of the file on the server, and your other computers sync with it from then on.")));
if (f.what === "cut") ed.append(el("p", "lib-confirm", t("What another computer wrote into that file and has nowhere else is lost. If one of them synced it last, Sync now there may rebuild it instead.")));
ed.append(el("p", "lib-confirm", t("The file on the server is kept in the sync folder first.")));
const err = el("p", "editor-error", "");
ed.append(err);
const bar = el("div", "bar");
const go = el("button", "text primary danger-fill", t("Upload this computer's setup"));
go.onclick = async (e) => {
e.stopPropagation();
go.disabled = true;
go.classList.add("busy");
try {
const r = await api("davsync/upload", {});
closeConfirmAsk();
renderSync(r);
} catch (x) {
go.disabled = false;
go.classList.remove("busy");
err.textContent = x.message;
}
};
const cancel = el("button", "text", t("Cancel"));
cancel.onclick = cancelAsk;
bar.append(el("span", "grow"), cancel, go);
ed.append(bar);
confirmAsk = ed;
openModal(ed);
$("#modal").classList.add("lib");
cancel.focus(NO_SCROLL);
}
// refreshAfterSync: what a sync or an import brought in reaches the other
// pages, leaving this one (and what it says was done) as it is.
function refreshAfterSync() {
+19
View File
@@ -0,0 +1,19 @@
// Settings › About's Open-source licenses: THIRD_PARTY_NOTICES, which
// every build carries. app.js imports this when View is pressed
// (showNotices), so it weighs nothing on the core (#5720).
window.noticesSheet = async function () {
let text;
try { text = (await api("notices")).text; } catch (e) { statusErr(e); return; }
const ed = el("div", "editor wide notices");
const head = el("div", "ehead");
head.append(el("b", "", t("Open-source licenses")));
const bar = el("div", "bar");
const ok = el("button", "text primary", t("Done"));
ok.onclick = cancelAsk;
bar.append(el("span", "grow"), ok);
ed.append(head, el("pre", "notices-text", text), bar);
confirmAsk = ed;
openModal(ed);
$("#modal").classList.add("lib");
ok.focus(NO_SCROLL);
}
+85 -3
View File
@@ -1,7 +1,8 @@
// Settings › Sync's forms: the server's (WebDAV, S3 or GitHub), Export and
// Import, and what putting a file's sign-ins in came to (qianxunji,
// curtinp118 on Discord). app.js imports this when one of the forms opens
// (syncFile), so it weighs nothing on the core.
// Import, what putting a file's sign-ins in came to (qianxunji,
// curtinp118 on Discord), and the asks before a Restore or an Upload
// (#847, #5720). app.js imports this when one of them opens (syncFile), so
// it weighs nothing on the core.
// davForm: the kind picked shows one set of fields; drafts survive switching.
// Inactive servers keep their settings for moving sync back.
@@ -214,3 +215,84 @@ window.importForm = function () {
};
return ed;
};
// askRestore asks before the server's setup replaces this computer's
// (#847); what is here is kept, and the notice it leaves can undo it.
window.askRestore = function (v, parts) {
const ed = el("div", "editor restore-ask");
const head = el("div", "ehead");
head.append(el("b", "", t("Restore from the server?")));
ed.append(head);
const goes = ["providers", "settings", "profiles"];
if (v.agents !== false) goes.push("agents");
if (v.library !== false) goes.push("library");
ed.append(el("p", "lib-confirm", t("This computer's {parts} become the ones on the server, as your other computers last synced them. Whatever was changed here since is replaced.", { parts: parts(goes) })));
ed.append(el("p", "lib-confirm", t("What is here now is sealed into the sync folder first, and Undo puts it back.")));
const err = el("p", "editor-error", "");
ed.append(err);
const bar = el("div", "bar");
const go = el("button", "text primary danger-fill", t("Restore setup"));
go.onclick = async (e) => {
e.stopPropagation();
go.disabled = true;
go.classList.add("busy");
try {
const r = await api("davsync/restore", {});
closeConfirmAsk();
renderSync(r);
if (r.error) return;
if (r.brought?.length) refreshAfterSync();
else status(t("This computer's setup is already the server's: nothing to restore"), "ok");
} catch (x) {
go.disabled = false;
go.classList.remove("busy");
err.textContent = x.message;
}
};
const cancel = el("button", "text", t("Cancel"));
cancel.onclick = cancelAsk;
bar.append(el("span", "grow"), cancel, go);
ed.append(bar);
confirmAsk = ed;
openModal(ed);
$("#modal").classList.add("lib");
cancel.focus(NO_SCROLL);
};
// askUpload asks before this computer's setup replaces a server file that
// isn't a backup; the server's file is kept in the sync folder first.
window.askUpload = function (f) {
const ed = el("div", "editor restore-ask upload-ask");
const head = el("div", "ehead");
head.append(el("b", "", t("Replace the file on the server?")));
ed.append(head);
ed.append(el("p", "lib-confirm", t("This computer's setup goes up in place of the file on the server, and your other computers sync with it from then on.")));
if (f.what === "cut") ed.append(el("p", "lib-confirm", t("What another computer wrote into that file and has nowhere else is lost. If one of them synced it last, Sync now there may rebuild it instead.")));
ed.append(el("p", "lib-confirm", t("The file on the server is kept in the sync folder first.")));
const err = el("p", "editor-error", "");
ed.append(err);
const bar = el("div", "bar");
const go = el("button", "text primary danger-fill", t("Upload this computer's setup"));
go.onclick = async (e) => {
e.stopPropagation();
go.disabled = true;
go.classList.add("busy");
try {
const r = await api("davsync/upload", {});
closeConfirmAsk();
renderSync(r);
} catch (x) {
go.disabled = false;
go.classList.remove("busy");
err.textContent = x.message;
}
};
const cancel = el("button", "text", t("Cancel"));
cancel.onclick = cancelAsk;
bar.append(el("span", "grow"), cancel, go);
ed.append(bar);
confirmAsk = ed;
openModal(ed);
$("#modal").classList.add("lib");
cancel.focus(NO_SCROLL);
};
File diff suppressed because one or more lines are too long
+3 -2
View File
@@ -160,9 +160,10 @@ test("compat.js is the first of the page's own scripts", async () => {
// conversations, balfound.js when the editor draws a relay's balance
// with no Balance URL, passerrors.js when it draws a key provider's
// Errors, keybalance.js when it draws a key whose vendor tells no
// balance, modellimits.js when it draws a model's row; the checks above
// balance, modellimits.js when it draws a model's row, notices.js when
// About's Open-source licenses opens; the checks above
// still read them
for (const f of await scripts()) if (!["webfonts.js", "cfgblocked.js", "signsheets.js", "ruleedit.js", "ratewindows.js", "traywindows.js", "autoresetown.js", "registry.js", "navlamp.js", "whatsnew.js", "claudemode.js", "ctxtext.js", "resetask.js", "quotaall.js", "quitask.js", "checkinnow.js", "autobackup.js", "scrollends.js", "profilerename.js", "settingshints.js", "keyspend.js", "syncfiles.js", "agentcompact.js", "balfound.js", "passerrors.js", "keybalance.js", "modellimits.js"].includes(f)) assert(all.includes(f), f + " is not loaded by index.html");
for (const f of await scripts()) if (!["webfonts.js", "cfgblocked.js", "signsheets.js", "ruleedit.js", "ratewindows.js", "traywindows.js", "autoresetown.js", "registry.js", "navlamp.js", "whatsnew.js", "claudemode.js", "ctxtext.js", "resetask.js", "quotaall.js", "quitask.js", "checkinnow.js", "autobackup.js", "scrollends.js", "profilerename.js", "settingshints.js", "keyspend.js", "syncfiles.js", "agentcompact.js", "balfound.js", "passerrors.js", "keybalance.js", "modellimits.js", "notices.js"].includes(f)) assert(all.includes(f), f + " is not loaded by index.html");
});
test("the styles hold up in Safari 15.0", async () => {