Skip to content

Commit 86aa262

Browse files
committed
fix(win): zip apply helper plan path + NSIS install log visibility
Pass -PlanPath to the detached PowerShell apply script so the update plan is always available (Windows detached spawn often does not pass custom env vars such as HSP_UPDATE_PLAN). Improve fatal error logging when Write-ApplyLog is not yet available. Emit ShowInstDetails show in customPageAfterChangeDir before MUI_PAGE_INSTFILES. common.nsh sets nevershow and customHeader runs after assistedInstaller, so the InstFiles page was built without a details list; DetailPrint had nowhere to appear. Made-with: Cursor
1 parent 50481a6 commit 86aa262

2 files changed

Lines changed: 24 additions & 14 deletions

File tree

app/windows/build.cjs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,9 +1116,10 @@ function setupAutoUpdater() {
11161116
settleMs = Math.min(5000, Math.max(0, defaultSettle));
11171117
}
11181118
const ps1Body = [
1119+
"param([string]$PlanPath)",
11191120
'$ErrorActionPreference = "Stop"',
1120-
"$PlanPath = $env:HSP_UPDATE_PLAN",
1121-
'if (-not $PlanPath) { throw "HSP_UPDATE_PLAN environment variable is missing" }',
1121+
"if (-not $PlanPath) { $PlanPath = $env:HSP_UPDATE_PLAN }",
1122+
'if (-not $PlanPath) { throw "Plan path missing (pass -PlanPath to this script or set HSP_UPDATE_PLAN)" }',
11221123
"$plan = Get-Content -LiteralPath $PlanPath -Encoding UTF8 -Raw | ConvertFrom-Json",
11231124
"$LogFile = $plan.logPath",
11241125
`$settleMs = ${settleMs}`,
@@ -1183,7 +1184,9 @@ function setupAutoUpdater() {
11831184
" try { Remove-Item -LiteralPath $PlanPath -Force } catch {}",
11841185
' Write-ApplyLog "apply done"',
11851186
"} catch {",
1186-
' Write-ApplyLog ("FATAL: " + $_.Exception.Message)',
1187+
' $err = "FATAL: " + $_.Exception.Message',
1188+
" if ($LogFile) { try { Write-ApplyLog $err } catch {} }",
1189+
" elseif ($plan -and $plan.logPath) { try { Add-Content -LiteralPath $plan.logPath -Value (\"[\" + (Get-Date).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ss.fffZ') + \"] \" + $err) -Encoding UTF8 } catch {} }",
11871190
" try { Remove-Item -LiteralPath $PlanPath -Force } catch {}",
11881191
" exit 1",
11891192
"}",
@@ -1203,15 +1206,19 @@ function setupAutoUpdater() {
12031206
const systemRoot = process.env.SystemRoot || process.env.SYSTEMROOT || "C:\\Windows";
12041207
const psExe = path.join(systemRoot, "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
12051208

1206-
const child = spawn(psExe, ["-NoProfile", "-ExecutionPolicy", "Bypass", "-File", ps1Path], {
1207-
env: { ...process.env, HSP_UPDATE_PLAN: planPath },
1208-
detached: true,
1209-
stdio: "ignore",
1210-
windowsHide: true,
1211-
});
1209+
const child = spawn(
1210+
psExe,
1211+
["-NoProfile", "-ExecutionPolicy", "Bypass", "-File", ps1Path, "-PlanPath", planPath],
1212+
{
1213+
env: { ...process.env, HSP_UPDATE_PLAN: planPath },
1214+
detached: true,
1215+
stdio: "ignore",
1216+
windowsHide: true,
1217+
},
1218+
);
12121219
logUpdater(
12131220
"apply",
1214-
`spawn ${psExe} pid=${child.pid} detached=true env HSP_UPDATE_PLAN (robocopy staging → installDir, then relaunch exe)`,
1221+
`spawn ${psExe} pid=${child.pid} detached=true -PlanPath + HSP_UPDATE_PLAN (robocopy / junction, relaunch)`,
12151222
);
12161223
child.unref();
12171224
if (!child.pid) {

app/windows/installer-hooks.nsi

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,21 @@
1414
; multiple electron-builder users on some Windows machines.
1515
CRCCheck off
1616

17-
; assistedInstaller.nsh runs !ifmacrodef customPageAfterChangeDir immediately before MUI_PAGE_INSTFILES.
18-
; Hook SHOW only (not PRE) so we do not override electron-builder's instFilesPre when
19-
; allowToChangeInstallationDirectory is true. Runtime SetDetailsPrint fixes empty InstFiles log.
17+
; assistedInstaller.nsh runs !ifmacrodef customPageAfterChangeDir immediately *before* MUI_PAGE_INSTFILES.
18+
; common.nsh sets ShowInstDetails nevershow; customHeader runs *after* assistedInstaller, so
19+
; ShowInstDetails show there is too late — the InstFiles page is already generated hidden (only the
20+
; stub line / progress text shows). Emit ShowInstDetails show here so the details list exists.
21+
; Hook SHOW for runtime SetDetailsPrint (belt-and-suspenders).
2022
; Omit when BUILD_UNINSTALLER: the uninstaller pass has no installer InstFiles page; an unreferenced
2123
; Function triggers NSIS warning 6010 and electron-builder fails (warnings as errors).
2224
!ifndef BUILD_UNINSTALLER
2325
!macro customPageAfterChangeDir
26+
ShowInstDetails show
2427
!define MUI_PAGE_CUSTOMFUNCTION_SHOW HspInstFilesShow
2528
!macroend
2629

2730
Function HspInstFilesShow
28-
; Match installSection: do not gate on ${Silent} here. Only ensure details are enabled; steps come from the section.
31+
; Match installSection: do not gate on ${Silent} here.
2932
SetDetailsPrint both
3033
FunctionEnd
3134
!endif

0 commit comments

Comments
 (0)