From b47ebfb976d8eef64e3a45632bc3f07a56588a09 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: Thu, 1 Oct 2026 13:30:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=8C=85=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E6=97=B6=E6=94=BE=E5=9B=9E=E5=8D=87=E7=BA=A7=E5=89=8D=E7=9A=84?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 升级脚本先挪走旧目录后,解开中途失败会把那一份放回去。补丁没写完不清除升级标记,下次启动再试。 Co-authored-by: Cursor --- lib/core.js | 33 +++++++++++++++++++++++---------- lib/index.js | 2 +- release-notes.md | 4 ++-- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/lib/core.js b/lib/core.js index e29ff42..6ee7dd9 100644 --- a/lib/core.js +++ b/lib/core.js @@ -1635,6 +1635,14 @@ export function sealedAsarHandoff(input = {}) { return { exe, asar, swapAsar: true }; } +/** 当前目录还不能当宿主时,把升级脚本或上一次换目录挪走的那一份放回去。能用的目录不动。 */ +function restoreUnusableExtract(appDir, prev) { + if (aiBaseUnderAppDir(appDir)) return false; + const saved = prev || newestPreservedDir(appDir); + if (!saved) return false; + return restoreExtractedDir(appDir, saved); +} + /** 官方 app.asar 解开到 resources/app。已有解开目录时直接用,不重新解包。 */ export async function openSealedDesktopHost(options = {}) { const handoff = sealedAsarHandoff(); @@ -1644,21 +1652,26 @@ export async function openSealedDesktopHost(options = {}) { let extracted = false; let prev = ""; if (!aiBase) { - const side = extractAsarToSide(handoff.asar, appDir); - overlayAsarUnpacked(handoff.asar, side.next); - if (!aiBaseUnderAppDir(side.next)) { - try { hostFs.rmSync(side.next, { recursive: true, force: true }); } catch { /* 半成品留在旁边,不覆盖正在用的目录 */ } - throw new Error(`已解开 ${handoff.asar},但里面没有 @deepseek-ai`); + try { + const side = extractAsarToSide(handoff.asar, appDir); + overlayAsarUnpacked(handoff.asar, side.next); + if (!aiBaseUnderAppDir(side.next)) { + try { hostFs.rmSync(side.next, { recursive: true, force: true }); } catch { /* 半成品留在旁边,不覆盖正在用的目录 */ } + throw new Error(`已解开 ${handoff.asar},但里面没有 @deepseek-ai`); + } + const committed = commitExtractedDir(appDir, side.next); + prev = committed.prev || ""; + extracted = true; + aiBase = aiBaseUnderAppDir(appDir); + } catch (error) { + try { restoreUnusableExtract(appDir, prev); } catch { /* 放回失败时旧目录仍留在旁边 */ } + throw error; } - const committed = commitExtractedDir(appDir, side.next); - prev = committed.prev || ""; - extracted = true; - aiBase = aiBaseUnderAppDir(appDir); } else { overlayAsarUnpacked(handoff.asar, appDir); } if (!aiBase) { - if (prev) restoreExtractedDir(appDir, prev); + restoreUnusableExtract(appDir, prev); throw new Error(`已解开 ${handoff.asar},但 ${appDir} 下没有 @deepseek-ai`); } resetPathMemo(); diff --git a/lib/index.js b/lib/index.js index f8e4ee0..14f7c9d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -320,11 +320,11 @@ function shimNeedsPatch(state) { async function settleInstalledPatches(config, ctx) { if (officialUpdate.upgradeMarkerExists(process.execPath)) { const upgraded = await reapply.reapplyInstalled({ scheduleSwap: false, forceExtract: true }); - officialUpdate.clearUpgradeMarker(process.execPath); if (!upgraded.ok) { log(config, "official upgrade reapply failed:", upgraded.error || ""); return "reapply-failed"; } + officialUpdate.clearUpgradeMarker(process.execPath); officialUpdate.clearStaleExtractedApps(process.execPath); log(config, "official upgrade reapplied; restarting onto the new build"); try { diff --git a/release-notes.md b/release-notes.md index a264843..52cbfaa 100644 --- a/release-notes.md +++ b/release-notes.md @@ -3,7 +3,7 @@ ## 中文 - 版本升级到 1.1.44。 -- 官方桌面解开 `app.asar` 时先写到旁边的目录,解开完成才换上 `resources/app`。解包卡住或这一轮补丁没写完,原来的目录还在。 +- 官方桌面解开 `app.asar` 时先写到旁边的目录,解开完成才换上 `resources/app`。解包卡住、升级前挪走的目录,或这一轮补丁没写完,原来的目录都会放回去。升级补丁没写完时保留标记,下次启动再试。 - 平常重启不再重新解包。只有官方升级换了新归档时才解一次,然后像 Web 一样把补丁补回去。 - 回退上一轮只撤掉最后一条已经发出的消息和它的回复,更早的轮次留在对话里,也从模型请求里拿掉。 - 可编辑提示词整份放在系统提示最前,同一份正文不再拼第二遍。每一步用当前这一份替换第一条系统提示。 @@ -11,7 +11,7 @@ ## English - Version 1.1.44. -- Unpacking `app.asar` writes beside `resources/app` and swaps in only after the unpack finishes. If unpacking sticks or that round of patches does not finish, the previous directory stays. +- Unpacking `app.asar` writes beside `resources/app` and swaps in only after the unpack finishes. If unpacking sticks, the directory moved aside before an upgrade is put back, and an unfinished patch round is put back too. The upgrade marker stays until that round finishes, so the next start tries again. - A normal restart does not unpack again. A new archive from an official upgrade is unpacked once, then patches are applied the same way as on Web. - Rewinding the previous round removes only that sent message and its reply. Earlier rounds stay on screen and leave the next model request. - The editable prompt is placed once at the front of the system prompt. Each step replaces the first system prompt with that current text.