Skip to content

Commit 9f52848

Browse files
committed
feat(nsis): per machine one-click installer #564
1 parent a01f481 commit 9f52848

File tree

6 files changed

+24
-21
lines changed

6 files changed

+24
-21
lines changed

docs/Options.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ See [NSIS target notes](https://github.com/electron-userland/electron-builder/wi
127127

128128
| Name | Description
129129
| --- | ---
130-
| perMachine | <a name="NsisOptions-perMachine"></a>Mark "all users" (per-machine) as default. Not recommended. Defaults to `false`.
131-
| allowElevation | <a name="NsisOptions-allowElevation"></a>Allow requesting for elevation. If false, user will have to restart installer with elevated permissions. Defaults to `true`.
132130
| oneClick | <a name="NsisOptions-oneClick"></a>One-click installation. Defaults to `true`.
131+
| perMachine | <a name="NsisOptions-perMachine"></a>Install per all users (per-machine). Defaults to `false`.
132+
| allowElevation | <a name="NsisOptions-allowElevation"></a>Allow requesting for elevation. If false, user will have to restart installer with elevated permissions. Defaults to `true`.
133133
| installerHeader | <a name="NsisOptions-installerHeader"></a>*boring installer only.* `MUI_HEADERIMAGE`, relative to the project directory. Defaults to `build/installerHeader.bmp`
134134
| installerHeaderIcon | <a name="NsisOptions-installerHeaderIcon"></a>*one-click installer only.* The path to header icon (above the progress bar), relative to the project directory. Defaults to `build/installerHeaderIcon.ico` or application icon.
135135

src/metadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ export interface NsisOptions {
370370
readonly perMachine?: boolean | null
371371

372372
/*
373-
Allow requesting for elevation. If false, user will have to restart installer with elevated permissions. Defaults to `true`.
373+
*boring installer only.* Allow requesting for elevation. If false, user will have to restart installer with elevated permissions. Defaults to `true`.
374374
*/
375375
readonly allowElevation?: boolean | null
376376

src/targets/nsis.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export default class NsisTarget extends Target {
9191
defines.INSTALL_MODE_PER_ALL_USERS = null
9292
}
9393

94-
if (this.options.allowElevation !== false) {
94+
if (!oneClick && this.options.allowElevation !== false) {
9595
defines.MULTIUSER_INSTALLMODE_ALLOW_ELEVATION = null
9696
}
9797

templates/nsis/NsisMultiUser.nsh

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ Var RadioButtonLabel1
5656
!define MULTIUSER_INSTALLMODE_DISPLAYNAME "${PRODUCT_NAME} ${VERSION}"
5757
!endif
5858

59-
RequestExecutionLevel user
60-
6159
; Sets install mode to "per-machine" (all users).
6260
!macro MULTIUSER_INSTALLMODE_ALLUSERS UNINSTALLER_PREFIX UNINSTALLER_FUNCPREFIX
6361
;Install mode initialization - per-machine
@@ -372,8 +370,9 @@ FunctionEnd
372370
SendMessage $MultiUser.InstallModePage.AllUsers ${BM_GETCHECK} 0 0 $MultiUser.InstallModePage.ReturnValue
373371

374372
${if} $MultiUser.InstallModePage.ReturnValue = ${BST_CHECKED}
375-
${if} $IsAdmin == "0"
376-
!ifdef MULTIUSER_INSTALLMODE_ALLOW_ELEVATION ; if it's not Power or Admin, but elevation is allowed, then elevate...
373+
${if} $IsAdmin == "0"
374+
# if it's not Power or Admin, but elevation is allowed, then elevate
375+
!ifdef MULTIUSER_INSTALLMODE_ALLOW_ELEVATION
377376
;MessageBox MB_OK "Will elevate and quit"
378377
ShowWindow $HWNDPARENT ${SW_HIDE} ; HideWindow would work?
379378
!insertmacro UAC_RunElevated
@@ -407,12 +406,12 @@ FunctionEnd
407406

408407
ShowWindow $HWNDPARENT ${SW_SHOW}
409408
BringToFront
410-
Abort ; Stay on page - http://nsis.sourceforge.net/Abort
411-
!else
412-
;se não é Power ou Admin, e não é permitida elevation, então nem deveria ter chegado aqui... o radiobutton deveria estar disabled
409+
# Stay on page
410+
Abort
413411
!endif
414412
${else}
415-
Call ${UNINSTALLER_FUNCPREFIX}MultiUser.InstallMode.AllUsers ; if it's Power or Admin, just go on with installation...
413+
# if it's Power or Admin, just go on with installation
414+
Call ${UNINSTALLER_FUNCPREFIX}MultiUser.InstallMode.AllUsers
416415
${endif}
417416
${else}
418417
Call ${UNINSTALLER_FUNCPREFIX}MultiUser.InstallMode.CurrentUser

templates/nsis/installer.nsi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ FunctionEnd
1616
AutoCloseWindow true
1717
!insertmacro MUI_PAGE_INSTFILES
1818
!insertmacro MUI_UNPAGE_INSTFILES
19+
20+
!ifdef INSTALL_MODE_PER_ALL_USERS
21+
RequestExecutionLevel admin
22+
!else
23+
RequestExecutionLevel user
24+
!endif
1925
!else
26+
RequestExecutionLevel user
2027
!include "boring-installer.nsh"
2128
!endif
2229

test/src/winPackagerTest.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,15 @@ test.ifDevOrLinuxCi("nsis 32 perMachine", () => assertPack("test-app-one", {
4646
}))
4747

4848
test.ifNotCiOsx("nsis boring", () => assertPack("test-app-one", _signed({
49-
targets: Platform.WINDOWS.createTarget(["nsis"]),
50-
devMetadata: {
51-
build: {
52-
nsis: {
53-
oneClick: false,
54-
}
49+
targets: Platform.WINDOWS.createTarget(["nsis"]),
50+
devMetadata: {
51+
build: {
52+
nsis: {
53+
oneClick: false,
5554
}
5655
}
57-
}), {
58-
useTempDir: true,
5956
}
60-
))
57+
})))
6158

6259
test.ifNotCiOsx("nsis, installerHeaderIcon", () => {
6360
let headerIconPath: string | null = null

0 commit comments

Comments
 (0)