mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 05:10:22 +08:00
fix: 切换立即标当前,覆盖后刷新设置页不再强制重启
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
42ea49fa84
commit
a9fc371898
2 files changed
+64
-30
No files matched your search
@@ -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;
|
||||
|
||||
+23
-17
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user