From bb2aef5242cf14f23b4ba8485eae38cf4c1d2b36 Mon Sep 17 00:00:00 2001 From: Taehyun Hwang Date: Tue, 12 Apr 2022 14:49:29 +0900 Subject: [PATCH] fix(nsis): Decide to use elevate.exe for installer when update using nsis packElevateHelper option in electron-builder config If window service needs to run installer for update, the installer must have admin previlege. Electron-updater detects whether elevating or not using isAdminRightsRequired in update-info.json. And this isAdminRightsRequired true option should be added to latest.yml using nsis's packElevateHelper option --- .changeset/poor-windows-heal.md | 5 ++++ .../src/targets/nsis/NsisTarget.ts | 3 ++- .../windows/assistedInstallerTest.js.snap | 26 +++++++++++++++++++ test/src/windows/assistedInstallerTest.ts | 14 ++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 .changeset/poor-windows-heal.md diff --git a/.changeset/poor-windows-heal.md b/.changeset/poor-windows-heal.md new file mode 100644 index 00000000000..eb35f179280 --- /dev/null +++ b/.changeset/poor-windows-heal.md @@ -0,0 +1,5 @@ +--- +"app-builder-lib": patch +--- + +If window service needs to run installer for update, the installer must have admin previlege. Electron-updater detects whether elevating or not using isAdminRightsRequired in update-info.json. And this isAdminRightsRequired true option should be added to latest.yml using nsis's packElevateHelper option diff --git a/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts b/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts index 50a9c90e847..c6a59ed9d4a 100644 --- a/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts +++ b/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts @@ -159,6 +159,7 @@ export class NsisTarget extends Target { .join(", "), } const isPerMachine = options.perMachine === true + if (!this.isPortable) { logFields.oneClick = oneClick logFields.perMachine = isPerMachine @@ -319,7 +320,7 @@ export class NsisTarget extends Target { updateInfo = await createBlockmap(installerPath, this, packager, safeArtifactName) } - if (updateInfo != null && isPerMachine && oneClick) { + if (updateInfo != null && isPerMachine && (oneClick || options.packElevateHelper)) { updateInfo.isAdminRightsRequired = true } diff --git a/test/snapshots/windows/assistedInstallerTest.js.snap b/test/snapshots/windows/assistedInstallerTest.js.snap index 7fbe86534f6..ff45645ef4f 100644 --- a/test/snapshots/windows/assistedInstallerTest.js.snap +++ b/test/snapshots/windows/assistedInstallerTest.js.snap @@ -128,3 +128,29 @@ Object { ], } `; + +exports[`assisted, only perMachine and elevated 1`] = ` +Object { + "win": Array [ + Object { + "arch": "x64", + "file": "Test App ßW Setup 1.1.0.exe", + "safeArtifactName": "TestApp-Setup-1.1.0.exe", + "updateInfo": Object { + "isAdminRightsRequired": true, + "sha512": "@sha512", + "size": "@size", + }, + }, + Object { + "file": "Test App ßW Setup 1.1.0.exe.blockmap", + "safeArtifactName": "TestApp-Setup-1.1.0.exe.blockmap", + "updateInfo": Object { + "isAdminRightsRequired": true, + "sha512": "@sha512", + "size": "@size", + }, + }, + ], +} +`; diff --git a/test/src/windows/assistedInstallerTest.ts b/test/src/windows/assistedInstallerTest.ts index 58f2826b16f..17ddfa8f008 100644 --- a/test/src/windows/assistedInstallerTest.ts +++ b/test/src/windows/assistedInstallerTest.ts @@ -147,6 +147,20 @@ test.ifNotCiMac( }) ) +test.ifNotCiMac( + "assisted, only perMachine and elevated", + app({ + targets: nsisTarget, + config: { + nsis: { + oneClick: false, + perMachine: true, + packElevateHelper: true + }, + }, + }) +) + // test release notes also test.ifAll.ifNotCiMac( "allowToChangeInstallationDirectory",