fix(desktop): 换包先杀 Electron main,挪不动时把原版拉起来 (#197)

- ASAR_SWAP_PS1 先按安装根路径 + 非 --type= 识别并 kill Electron main,再扫安装目录其余进程:main 是唯一会弹「host stopped」的对话框来源,先杀它就不会出现 host 死了 main 还活着的半死状态
- 挪包失败的分支补上 Start-Process:用户至少拿到原版应用,不再面对空桌面;失败原因写入 %TEMP%\\dsh-purge-desktop.log
- 导出 ASAR_SWAP_PS1 并新增 test/desktop-asar-swap.test.js(3 例,守住顺序与两条重启分支)
- 全量 node --test 94/94 通过
This commit is contained in:
iigzx committed 2026-10-31 21:51:32 +08:00
1 parent 7b3f8ede49
commit c236e689f3
2 files changed
+45 -1

No files matched your search

+20 -1
View File
@@ -1010,7 +1010,7 @@ function desktopRuntimeOf(ctx) {
return runtime && typeof runtime.requestRestart === "function" ? runtime : null;
}
const ASAR_SWAP_PS1 = [
export const ASAR_SWAP_PS1 = [
"param(",
" [Parameter(Mandatory = $true)][int]$WaitPid,",
" [Parameter(Mandatory = $true)][string]$AsarPath,",
@@ -1037,6 +1037,16 @@ const ASAR_SWAP_PS1 = [
"# 来得及处理 host 退出事件就被 kill,UI 根本不存在,无法弹 crash dialog。",
"# PowerShell 本身是 detached 独立进程(spawn 时 detached:true, stdio:ignore),",
"# 杀 Electron 不会连带杀 PowerShell。",
"# #197b: 先杀 Electron main。main 是唯一会弹「host stopped」对话框的进程:",
"# 若先杀 host,main 还活着就会弹框,然后脚本若在挪 asar 前失败,用户就卡在",
"# 「host 死了、main 半死、asar 没动」的状态(2026-10-31 实测)。先杀 main 就没框。",
"$mains = @(Get-CimInstance Win32_Process -ErrorAction SilentlyContinue | Where-Object {",
" $ep = $_.ExecutablePath",
" if (-not $ep) { return $false }",
" ($ep.ToLower() -eq $exeNorm) -and ($_.CommandLine -notmatch '--type=')",
"})",
"foreach ($p in $mains) { Stop-Process -Id $p.ProcessId -Force -ErrorAction SilentlyContinue }",
"Start-Sleep -Milliseconds 400",
"Stop-HarnessInstall",
"Start-Sleep -Milliseconds 500",
"Stop-HarnessInstall",
@@ -1080,7 +1090,15 @@ const ASAR_SWAP_PS1 = [
" Remove-Item Env:ELECTRON_RUN_AS_NODE -ErrorAction SilentlyContinue",
" Start-Process -FilePath $ExePath",
"} else {",
" # #197b: 挪不动(asar 仍被占用)时不要把用户扔在空桌面上——把原版拉起来,",
" # 留下 rename-pending 让下一次空闲重试;失败原因写进 dsh-purge 日志。",
" Set-Content -LiteralPath $lock -Value ((Get-Date).ToString('o')) -Encoding ascii",
" try {",
" $log = Join-Path $env:TEMP 'dsh-purge-desktop.log'",
" Add-Content -LiteralPath $log -Value ((Get-Date).ToUniversalTime().ToString('o') + ' [asar-swap] move failed; relaunching original app (asar still sealed)')",
" } catch {}",
" Remove-Item Env:ELECTRON_RUN_AS_NODE -ErrorAction SilentlyContinue",
" Start-Process -FilePath $ExePath",
"}",
"",
].join("\r\n");
@@ -1940,3 +1958,4 @@ export function repairOfficialCliAfterUnpack(exe = findDesktopAppExecutable()) {
}
return report;
}