diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index a54e9933f..f649b2203 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -20088,42 +20088,6 @@ function renderCLI(r) { // Settings' Download source (#893): a GitHub mirror before github.com, as // `magpie update mirror` writes; the feed and SHA-256 stay usemagpie.ai's let mirrorEditing = false, mirrorDraft = "", mirrorErr = ""; -function setUpdateMirror(mirror) { - return writingPrefs(api("settings/update-mirror", { mirror })) - .then((ns) => { prefs = ns; mirrorEditing = false; mirrorDraft = mirrorErr = ""; renderSettings(); status(t("Saved"), "ok", 1500); return ns; }); -} -// Use a mirror… and Change open the field from mirroredit.js -const editMirror = (r, s, v) => import("./mirroredit.js").then(() => { mirrorEditing = true; mirrorDraft = v; renderUpdateMirror(r, s); }, statusErr); -function renderUpdateMirror(r, s) { - r.classList.add("update-mirror-row"); - const who = r.querySelector(".who"), val = r.querySelector(".val"); - who.querySelector(".sub")?.remove(); - val.replaceChildren(); - const sub = el("div", "sub"); - who.append(sub); - const m = s.updateMirror || ""; - sub.textContent = mirrorErr || (m ? t("Updates are downloaded from usemagpie.ai, and through this mirror when that fails, each checked against usemagpie.ai's checksum") - : t("Updates are downloaded from usemagpie.ai, and from GitHub when that fails; a mirror can stand in for GitHub where it is slow")); - // the docs' Mirrors page says which mirror and how (WeltAn_X on X) - const more = el("button", "sub-more", t("How mirrors work")); - more.onclick = () => api("open", { url: "https://usemagpie.ai/docs/" + ({ zh: "zh/", "zh-TW": "zh/", ja: "ja/" }[locale] || "") + "mirrors#settings" }).catch(() => {}); - sub.append(" ", more); - sub.classList.toggle("err", !!mirrorErr); - sub.title = t("The update and its checksum always come from usemagpie.ai; a file from the mirror that doesn't match it is not installed."); - if (mirrorEditing) return mirrorEdit(r, s, sub, val); - if (m) { - const official = el("button", "text", t("Remove mirror")); - official.onclick = () => setUpdateMirror("").catch(statusTErr); - const change = el("button", "text", t("Change")); - change.onclick = () => editMirror(r, s, m); - val.append(el("code", "", m), change, official); - } else { - const add = el("button", "text", t("Use a mirror…")); - add.onclick = () => editMirror(r, s, ""); - val.append(el("code", "", "usemagpie.ai"), add); - } -} - function renderSettings() { const s = prefs; const keep = prefsKeep(s); @@ -20309,13 +20273,13 @@ function renderSettings() { segsOO(!s.noAutoDownload, (v) => savePrefs({ ...keep, noAutoDownload: !v }))).classList.add("update-download-row"); row(t("Restart automatically"), s.noAutoUpdate ? t("While automatic updates are on") : t("Once an update is downloaded, restarts into it without cutting off an agent's request"), "", segsOO(s.autoRestart, (v) => savePrefs({ ...keep, autoRestart: v }))).classList.add("update-restart-row", ...(s.noAutoUpdate ? ["off"] : [])); - renderUpdateMirror(row(t("Download source"), "", ""), s); + const mr = row(t("Download source"), "", ""); // beside Download source, both where an update comes from (WeltAn_X on X) const src = el("button", "sess-pick pref-pick"); Object.assign(src, { type: "button", id: "updateSourcePick" }); menuOpener(src); row(t("Update source"), "", "", src).id = "updateSourceRow"; - import("./updatesource.js").then(() => src.isConnected && updateSourcePick(s, keep), statusErr); + import("./updatesource.js").then(() => src.isConnected && (renderUpdateMirror(mr, s), updateSourcePick(s, keep)), statusErr); const open = el("button", "text", t("Open")); open.onclick = () => api("settings/reveal", {}).catch(statusErr); // portable (a data folder beside magpie, #508): everything is in there diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index 10e4f2a27..eb6166580 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -4292,6 +4292,10 @@ const I18N = { "Updates are downloaded from usemagpie.ai, and through this mirror when that fails, each checked against usemagpie.ai's checksum": "更新从 usemagpie.ai 下载,失败时经此镜像下载,每个文件都按 usemagpie.ai 的校验和核对", "Updates are downloaded from usemagpie.ai, and from GitHub when that fails; a mirror can stand in for GitHub where it is slow": "更新从 usemagpie.ai 下载,失败时改从 GitHub 下载;GitHub 慢时可以给它配镜像", "The update and its checksum always come from usemagpie.ai; a file from the mirror that doesn't match it is not installed.": "更新信息和校验和始终来自 usemagpie.ai;从镜像下载的文件如果与校验和不符,magpie 不会安装它。", + "Update source is usemagpie.ai only: updates never come from GitHub, so no mirror is used": "更新源为仅 usemagpie.ai:更新从不来自 GitHub,所以不使用镜像", + "Update source is GitHub only: updates come through this mirror, each checked against the release's signed checksums": "更新源为仅 GitHub:更新经此镜像下载,每个文件都按版本附带的签名校验和核对", + "Update source is GitHub only: updates come from GitHub; a mirror can stand in for it where it is slow": "更新源为仅 GitHub:更新从 GitHub 下载;GitHub 慢时可以给它配镜像", + "The checksums come signed with the release; a file from the mirror that doesn't match them is not installed.": "校验和随版本一起签名发布;从镜像下载的文件如果与校验和不符,magpie 不会安装它。", "Remove mirror": "不用镜像", "Change": "修改", "Use a mirror…": "使用镜像…", @@ -9724,6 +9728,10 @@ const I18N = { "Updates are downloaded from usemagpie.ai, and through this mirror when that fails, each checked against usemagpie.ai's checksum": "更新從 usemagpie.ai 下載,失敗時經此鏡像下載,每個檔案都按 usemagpie.ai 的檢查碼核對", "Updates are downloaded from usemagpie.ai, and from GitHub when that fails; a mirror can stand in for GitHub where it is slow": "更新從 usemagpie.ai 下載,失敗時改從 GitHub 下載;GitHub 慢時可以給它配鏡像", "The update and its checksum always come from usemagpie.ai; a file from the mirror that doesn't match it is not installed.": "更新資訊和檢查碼始終來自 usemagpie.ai;從鏡像下載的檔案如果與檢查碼不符,magpie 不會安裝它。", + "Update source is usemagpie.ai only: updates never come from GitHub, so no mirror is used": "更新來源為僅 usemagpie.ai:更新從不來自 GitHub,所以不使用鏡像", + "Update source is GitHub only: updates come through this mirror, each checked against the release's signed checksums": "更新來源為僅 GitHub:更新經此鏡像下載,每個檔案都依版本附帶的簽章檢查碼核對", + "Update source is GitHub only: updates come from GitHub; a mirror can stand in for it where it is slow": "更新來源為僅 GitHub:更新從 GitHub 下載;GitHub 慢時可以給它配鏡像", + "The checksums come signed with the release; a file from the mirror that doesn't match them is not installed.": "檢查碼隨版本一起簽章發佈;從鏡像下載的檔案如果與檢查碼不符,magpie 不會安裝它。", "Remove mirror": "不用鏡像", "Change": "修改", "Use a mirror…": "使用鏡像…", @@ -15169,6 +15177,10 @@ const I18N = { "Updates are downloaded from usemagpie.ai, and through this mirror when that fails, each checked against usemagpie.ai's checksum": "更新は usemagpie.ai からダウンロードし、失敗したときはこのミラー経由で取得します。それぞれ usemagpie.ai のチェックサムで照合します", "Updates are downloaded from usemagpie.ai, and from GitHub when that fails; a mirror can stand in for GitHub where it is slow": "更新は usemagpie.ai からダウンロードし、失敗したときは GitHub から取得します。GitHub が遅い場合はミラーを使えます", "The update and its checksum always come from usemagpie.ai; a file from the mirror that doesn't match it is not installed.": "更新情報とチェックサムは常に usemagpie.ai から取得します。ミラーから取得したファイルがチェックサムと一致しない場合、magpie はインストールしません。", + "Update source is usemagpie.ai only: updates never come from GitHub, so no mirror is used": "アップデート元は usemagpie.ai のみ:GitHub からは取得しないため、ミラーは使いません", + "Update source is GitHub only: updates come through this mirror, each checked against the release's signed checksums": "アップデート元は GitHub のみ:このミラー経由で取得し、リリースの署名付きチェックサムで確認します", + "Update source is GitHub only: updates come from GitHub; a mirror can stand in for it where it is slow": "アップデート元は GitHub のみ:GitHub から取得します。遅い場合はミラーを使えます", + "The checksums come signed with the release; a file from the mirror that doesn't match them is not installed.": "チェックサムはリリースと一緒に署名されています。ミラーから取得したファイルが一致しない場合、magpie はインストールしません。", "Remove mirror": "ミラーをやめる", "Change": "変更", "Use a mirror…": "ミラーを使う…", @@ -20627,6 +20639,10 @@ const I18N = { "Updates are downloaded from usemagpie.ai, and through this mirror when that fails, each checked against usemagpie.ai's checksum": "Updates werden von usemagpie.ai geladen, und über diesen Spiegel, wenn das scheitert; jeweils mit der Prüfsumme von usemagpie.ai abgeglichen", "Updates are downloaded from usemagpie.ai, and from GitHub when that fails; a mirror can stand in for GitHub where it is slow": "Updates werden von usemagpie.ai geladen, und von GitHub, wenn das scheitert; wo GitHub langsam ist, hilft ein Spiegel", "The update and its checksum always come from usemagpie.ai; a file from the mirror that doesn't match it is not installed.": "Update und Prüfsumme kommen immer von usemagpie.ai; eine Datei vom Spiegel, die nicht zur Prüfsumme passt, wird nicht installiert.", + "Update source is usemagpie.ai only: updates never come from GitHub, so no mirror is used": "Update-Quelle ist nur usemagpie.ai: Updates kommen nie von GitHub, daher wird kein Spiegel genutzt", + "Update source is GitHub only: updates come through this mirror, each checked against the release's signed checksums": "Update-Quelle ist nur GitHub: Updates kommen über diesen Spiegel, jeweils gegen die signierten Prüfsummen des Releases geprüft", + "Update source is GitHub only: updates come from GitHub; a mirror can stand in for it where it is slow": "Update-Quelle ist nur GitHub: Updates kommen von GitHub; wo es langsam ist, hilft ein Spiegel", + "The checksums come signed with the release; a file from the mirror that doesn't match them is not installed.": "Die Prüfsummen kommen signiert mit dem Release; eine Datei vom Spiegel, die nicht passt, wird nicht installiert.", "Remove mirror": "Spiegel entfernen", "Change": "Ändern", "Use a mirror…": "Spiegel verwenden…", diff --git a/internal/gui/assets/updatesource.js b/internal/gui/assets/updatesource.js index d6fcf0957..bb0629126 100644 --- a/internal/gui/assets/updatesource.js +++ b/internal/gui/assets/updatesource.js @@ -18,3 +18,45 @@ window.updateSourcePick = function updateSourcePick(s, keep) { }, "Update source", "sess-menu", "right"); }; }; + +// Settings' Download source, drawn here with Update source so it weighs +// nothing on the core; it says what the source picked does +window.setUpdateMirror = function (mirror) { + return writingPrefs(api("settings/update-mirror", { mirror })) + .then((ns) => { prefs = ns; mirrorEditing = false; mirrorDraft = mirrorErr = ""; renderSettings(); status(t("Saved"), "ok", 1500); return ns; }); +}; +// Use a mirror… and Change open the field from mirroredit.js +const editMirror = (r, s, v) => import("./mirroredit.js").then(() => { mirrorEditing = true; mirrorDraft = v; renderUpdateMirror(r, s); }, statusErr); +window.renderUpdateMirror = function (r, s) { + r.classList.add("update-mirror-row"); + const who = r.querySelector(".who"), val = r.querySelector(".val"); + who.querySelector(".sub")?.remove(); + val.replaceChildren(); + const sub = el("div", "sub"); + who.append(sub); + const m = s.updateMirror || "", from = s.updateSource; + // as Update source says: site never asks GitHub, so no mirror is used + sub.textContent = mirrorErr || (from === "site" ? t("Update source is usemagpie.ai only: updates never come from GitHub, so no mirror is used") + : from === "github" ? (m ? t("Update source is GitHub only: updates come through this mirror, each checked against the release's signed checksums") : t("Update source is GitHub only: updates come from GitHub; a mirror can stand in for it where it is slow")) + : m ? t("Updates are downloaded from usemagpie.ai, and through this mirror when that fails, each checked against usemagpie.ai's checksum") + : t("Updates are downloaded from usemagpie.ai, and from GitHub when that fails; a mirror can stand in for GitHub where it is slow")); + // the docs' Mirrors page says which mirror and how (WeltAn_X on X) + const more = el("button", "sub-more", t("How mirrors work")); + more.onclick = () => api("open", { url: "https://usemagpie.ai/docs/" + ({ zh: "zh/", "zh-TW": "zh/", ja: "ja/" }[locale] || "") + "mirrors#settings" }).catch(() => {}); + sub.append(" ", more); + sub.classList.toggle("err", !!mirrorErr); + sub.title = from === "github" ? t("The checksums come signed with the release; a file from the mirror that doesn't match them is not installed.") + : t("The update and its checksum always come from usemagpie.ai; a file from the mirror that doesn't match it is not installed."); + if (mirrorEditing) return mirrorEdit(r, s, sub, val); + if (m) { + const official = el("button", "text", t("Remove mirror")); + official.onclick = () => setUpdateMirror("").catch(statusTErr); + const change = el("button", "text", t("Change")); + change.onclick = () => editMirror(r, s, m); + val.append(el("code", "", m), change, official); + } else { + const add = el("button", "text", t("Use a mirror…")); + add.onclick = () => editMirror(r, s, ""); + val.append(el("code", "", from === "github" ? "github.com" : "usemagpie.ai"), add); + } +}; diff --git a/internal/gui/tests/settings-update-source.test.cjs b/internal/gui/tests/settings-update-source.test.cjs index dde4e83a9..7190ec3d0 100644 --- a/internal/gui/tests/settings-update-source.test.cjs +++ b/internal/gui/tests/settings-update-source.test.cjs @@ -111,12 +111,23 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert(m.text <= Math.ceil(m.span) + 1, `${name}: the label is clipped (${m.text}px in ${m.span}px, button ${m.pick}px)`); assert(m.span > 0, `${name}: the label shows`); }; + // Download source above says what the source picked does: site never + // asks GitHub (so no mirror), GitHub only never usemagpie.ai + const says = async (key, host) => { + const got = await page.evaluate(() => ({ sub: document.querySelector(".update-mirror-row .who .sub")?.firstChild?.textContent, code: document.querySelector(".update-mirror-row code")?.textContent })); + assert.equal(got.sub, await page.evaluate((k) => t(k), key)); + assert.equal(got.code, host); + }; + await says("Updates are downloaded from usemagpie.ai, and from GitHub when that fails; a mirror can stand in for GitHub where it is slow", "usemagpie.ai"); await fits(l.auto); await choose(l.github, "github"); await fits(l.github); + await says("Update source is GitHub only: updates come from GitHub; a mirror can stand in for it where it is slow", "github.com"); await choose(l.site, "site"); await fits(l.site); + await says("Update source is usemagpie.ai only: updates never come from GitHub, so no mirror is used", "usemagpie.ai"); await choose(l.auto, ""); + await says("Updates are downloaded from usemagpie.ai, and from GitHub when that fails; a mirror can stand in for GitHub where it is slow", "usemagpie.ai"); // the menu ticks the one chosen await pick.click(); assert.equal(await page.locator(".proto-menu .pm-item.on").textContent(), l.auto);