From a9fc3718985aa778b30266b8eafc36e885cc506c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AB=E6=88=91=E5=B0=8F=E6=9D=A8=E5=90=8C=E5=AD=A6?= Date: Sun, 20 Sep 2026 17:01:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=87=E6=8D=A2=E7=AB=8B=E5=8D=B3?= =?UTF-8?q?=E6=A0=87=E5=BD=93=E5=89=8D=EF=BC=8C=E8=A6=86=E7=9B=96=E5=90=8E?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E8=AE=BE=E7=BD=AE=E9=A1=B5=E4=B8=8D=E5=86=8D?= =?UTF-8?q?=E5=BC=BA=E5=88=B6=E9=87=8D=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- client.js | 54 ++++++++++++++++++++++++++++++++++++++------------- lib/update.js | 40 ++++++++++++++++++++++---------------- 2 files changed, 64 insertions(+), 30 deletions(-) diff --git a/client.js b/client.js index 06e191f..b173d36 100644 --- a/client.js +++ b/client.js @@ -192,9 +192,10 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => { "update.latest": "已是最新({version})", "update.available": "有新版本 {remote},当前 {local}", "update.pinned": "已固定在 {version},通道最新是 {remote}", - "update.done": "已更新到 {version},请重启", - "update.switched": "已切换到 {version},请重启", - "update.autoDone": "已自动更新到 {version},请重启", + "update.done": "已更新到 {version}", + "update.switched": "已切换到 {version}", + "update.autoDone": "已自动更新到 {version}", + "update.reloading": "正在刷新设置页…", "update.dirty": "有新版本,本地有改动未自动覆盖", "update.fail": "更新失败: {error}", "update.timeout": "检测超时,请再点一次检测更新", @@ -397,9 +398,10 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => { "update.latest": "Up to date ({version})", "update.available": "Update {remote} available (now {local})", "update.pinned": "Pinned at {version}; channel latest is {remote}", - "update.done": "Updated to {version}. Restart to apply.", - "update.switched": "Switched to {version}. Restart to apply.", - "update.autoDone": "Auto-updated to {version}. Restart to apply.", + "update.done": "Updated to {version}.", + "update.switched": "Switched to {version}.", + "update.autoDone": "Auto-updated to {version}.", + "update.reloading": "Refreshing settings…", "update.dirty": "Update available; local edits were not overwritten.", "update.fail": "Update failed: {error}", "update.timeout": "Check timed out. Click Check update again.", @@ -888,8 +890,11 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => { const applyUpdateInfo = useCallback((d, tr, kind) => { if (d.channel) setChannel(d.channel); - setUpdateInfo(d); - syncPicks(d); + setUpdateInfo((prev) => { + const versions = (d.versions && d.versions.length) ? d.versions : ((prev && prev.versions) || []); + return Object.assign({}, prev || {}, d, { versions }); + }); + if (d.versions && d.versions.length) syncPicks(d); if (kind === "check") setCanApplyUpdate(Boolean(d.hasUpdate) && !d.error); else if (kind === "done" || kind === "switched" || kind === "channel") setCanApplyUpdate(false); const version = d.localVersion || d.localSha || "—"; @@ -933,7 +938,14 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => { .then((d) => { if (!d || (d.ok === false && d.error)) throw new Error((d && d.error) || "update failed"); applyUpdateInfo(d, tr, kind); - if (d.applied || d.needRestart) setAskRestart(true); + if (d.applied && d.reloadClient !== false) { + setUpdateNotice({ kind: "ok", text: tr("update.reloading") }); + setTimeout(() => { + try { window.location.reload(); } catch { /* ignore */ } + }, 280); + } else if (d.needRestart) { + setAskRestart(true); + } return d; }) .catch((e) => { @@ -955,8 +967,15 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => { if (!next) return; const tr = tRef.current; if (!window.confirm(tr("update.confirmChannel", { version: tr("channel." + next) }))) return; - postUpdate({ op: "channel", channel: next }, "channel", next).catch(() => {}); - }, [postUpdate]); + const prevChannel = channel; + const prevInfo = updateInfo; + setChannel(next); + setUpdateInfo((cur) => Object.assign({}, cur || {}, { channel: next })); + postUpdate({ op: "channel", channel: next }, "channel", next).catch(() => { + setChannel(prevChannel); + setUpdateInfo(prevInfo); + }); + }, [channel, postUpdate, updateInfo]); const switchSelected = useCallback((id) => { const tr = tRef.current; @@ -966,8 +985,17 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => { const label = (hit && (hit.label || hit.version)) || ref; if (!ref) return; if (!window.confirm(tr("update.confirmSwitch", { version: label }))) return; - postUpdate({ op: "switch", ref }, "switched", id).catch(() => {}); - }, [pick, postUpdate, updateInfo]); + const prevChannel = channel; + const prevInfo = updateInfo; + if (hit && hit.channel) { + setChannel(hit.channel); + setUpdateInfo((cur) => Object.assign({}, cur || {}, { channel: hit.channel })); + } + postUpdate({ op: "switch", ref }, "switched", id).catch(() => { + setChannel(prevChannel); + setUpdateInfo(prevInfo); + }); + }, [channel, pick, postUpdate, updateInfo]); const loadAll = useCallback(() => { const tr = tRef.current; diff --git a/lib/update.js b/lib/update.js index f730289..908800f 100644 --- a/lib/update.js +++ b/lib/update.js @@ -830,7 +830,7 @@ export async function applyUpdate(jobs = planUpdates(), options = {}) { await overlayFromZip(zipDirs, ref); vias.add("zip"); } - const sha = (await remoteHeadSha(ref)) || (gitOk() ? gitHead(PLUGIN_ROOT) : ""); + const sha = (gitOk() ? gitHead(PLUGIN_ROOT) : "") || (await remoteHeadSha(ref).catch(() => "")); if (sha) writeStamp(sha); const via = vias.size > 1 ? "mixed" : [...vias][0] || detectVia(); const pin = options.pin === false ? "" : (options.pin || state.pin || ""); @@ -845,7 +845,13 @@ export async function applyUpdate(jobs = planUpdates(), options = {}) { label: versionLabel(localVer, channel, sha), at: new Date().toISOString(), }); - const listed = await listRemoteVersions().catch(() => ({ versions: [], hasBeta: saved.channel === "beta" })); + const prev = lastUpdateResult() || {}; + const listed = { + versions: Array.isArray(prev.versions) ? prev.versions : [], + hasBeta: prev.hasBeta !== false, + stableSha: prev.stableSha || "", + betaSha: prev.betaSha || "", + }; return rememberUpdate({ ok: true, applied: true, @@ -856,7 +862,8 @@ export async function applyUpdate(jobs = planUpdates(), options = {}) { remoteVersion: localVer, localSha: sha ? String(sha).slice(0, 7) : "", remoteSha: sha ? String(sha).slice(0, 7) : "", - needRestart: true, + needRestart: false, + reloadClient: true, via, versions: listed.versions, lanes: lanesOf(listed, saved, localVer, sha), @@ -868,21 +875,20 @@ export async function switchChannel(channel, { apply = true } = {}) { const next = normalizeChannel(channel); if (next === "beta") { const betaSha = await remoteHeadSha(BETA_REF); - const tags = await listGithubTags(); - const hasBeta = Boolean(betaSha || tags.some((item) => item.channel === "beta")); - if (!hasBeta) { - return rememberUpdate({ - ok: false, - error: "还没有测试版", - hasBeta: false, - ...channelPublic(), - versions: [], - lanes: { stable: { id: "stable", hasRemote: true }, beta: { id: "beta", hasRemote: false } }, - }); - } - if (!betaSha && apply) { + if (!betaSha) { + const tags = await listGithubTags(); const tag = tags.find((item) => item.channel === "beta"); - if (tag) return applyUpdate(planUpdates(), { ref: tag.ref, channel: "beta", pin: false, force: true }); + if (!tag) { + return rememberUpdate({ + ok: false, + error: "还没有测试版", + hasBeta: false, + ...channelPublic(), + versions: [], + lanes: { stable: { id: "stable", hasRemote: true }, beta: { id: "beta", hasRemote: false } }, + }); + } + if (apply) return applyUpdate(planUpdates(), { ref: tag.ref, channel: "beta", pin: false, force: true }); } } if (!apply) {