项目文件夹

文件
caorushizi dfcdf6a6a5 fix(installer): show version in title bar, set installer FileDescription (#637)
- `installer/installer.nsh`: customHeader macro sets Caption to
  "Setup - ${PRODUCT_NAME} ${VERSION}" so users can see which release
  they're installing from the window title (the default $(^SetupCaption)
  omits the version, and re-setting Name trips NSIS warning 6029 which
  electron-builder's -WX flag treats as a hard error).
- `scripts/build.ts`: afterAllArtifactBuild hook runs the app-builder
  rcedit helper on the generated NSIS installer to rewrite its
  FileDescription to "${APP_NAME} installer". electron-builder's
  NsisTarget.computeVersionKey() hardcodes VIAddVersionKey /LANG=1033
  "FileDescription" "${appInfo.description}", binding the installer's
  FileDescription to the app binary's (both drawn from package.json
  description); any in-NSIS override collides on the same LANG+key
  with a hard "already defined!" error that -WX does not gate.
  Post-processing with rcedit sidesteps this and lets installer and
  app binary carry distinct descriptions — same approach VS Code's
  Inno Setup pipeline uses (where "{AppName} Setup" is the default).

Closes #637

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-22 23:23:51 +08:00

57 行
3.1 KiB
NSIS

; ============================================================================
; Custom NSIS overrides injected by electron-builder.
;
; electron-builder splices `!insertmacro customHeader` into the top of its
; generated installer script (see
; node_modules/app-builder-lib/templates/nsis/installer.nsi around line 45),
; which is AFTER `common.nsh` is included. That makes this macro the right
; place to override directives like `Name`, `Caption`, `BrandingText`.
;
; Note on FileDescription: we intentionally do NOT override it here.
; electron-builder's `NsisTarget.computeVersionKey()` (app-builder-lib ->
; out/targets/nsis/NsisTarget.js) unconditionally emits
; VIAddVersionKey /LANG=1033 "FileDescription" "${appInfo.description}"
; from `apps/electron/app/package.json`'s `description`. Any customHeader
; VIAddVersionKey targeting the same LANG+key triggers a hard NSIS error
; ("already defined!") that `-WX` does not gate. Different LANG (e.g. 0)
; produces a `warning 9100: without standard key FileVersion` which IS
; gated by -WX and still fails the build.
;
; The installer's FileDescription is rewritten post-build via `app-builder
; rcedit` in `afterAllArtifactBuild` (see apps/electron/scripts/build.ts).
; That sidesteps the NSIS constraint and lets the installer and app
; binary carry distinct descriptions (like VS Code / Chrome's Inno Setup
; default of "{AppName} Setup").
;
; Wired up through `nsis.include` in apps/electron/scripts/build.ts.
; ============================================================================
!macro customHeader
; ---------------------------------------------------------------------
; Surface the version in the installer's title bar.
;
; electron-builder's common.nsh sets `Name "${PRODUCT_NAME}"`, from
; which NSIS derives the default `$(^SetupCaption)` (e.g. "Setup -
; mediago-community"). That caption omits the version — users had to
; look at the gray BrandingText at the bottom-left to see which
; release they were installing.
;
; Why `Caption` and not `Name`: re-setting `Name` emits
; `warning 6029: Name: specified multiple times`, and electron-builder
; compiles NSIS with `-WX` (warnings-as-errors), so the build fails.
;
; Why a plain literal and not `$(^SetupCaption)`: the localized lang
; string is evaluated at runtime via the MUI plugin. electron-builder
; compiles an intermediate installer with `-DBUILD_UNINSTALLER` and
; executes it silently (NsisTarget.js line ~370, `execWine(installerPath,
; ..., __COMPAT_LAYER=RunAsInvoker)`) just to extract the uninstaller.
; Evaluating a language string in the `Caption` directive during that
; silent pass crashes with STATUS_STACK_BUFFER_OVERRUN (exit 3221225725)
; and aborts the whole packaging. A plain literal sidesteps the MUI
; runtime call entirely, so the intermediate pass finishes cleanly.
; Trade-off: title bar reads "Setup - mediago-community 3.5.0" in every
; locale instead of the translated "Installazione di ..." — acceptable.
; ---------------------------------------------------------------------
Caption "Setup - ${PRODUCT_NAME} ${VERSION}"
!macroend