Skip to content

Commit

Permalink
feat(nsis): per machine one-click installer #564
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jul 9, 2016
1 parent a01f481 commit 9f52848
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 21 deletions.
4 changes: 2 additions & 2 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ See [NSIS target notes](https://github.com/electron-userland/electron-builder/wi

| Name | Description
| --- | ---
| perMachine | <a name="NsisOptions-perMachine"></a>Mark "all users" (per-machine) as default. Not recommended. Defaults to `false`.
| allowElevation | <a name="NsisOptions-allowElevation"></a>Allow requesting for elevation. If false, user will have to restart installer with elevated permissions. Defaults to `true`.
| oneClick | <a name="NsisOptions-oneClick"></a>One-click installation. Defaults to `true`.
| perMachine | <a name="NsisOptions-perMachine"></a>Install per all users (per-machine). Defaults to `false`.
| allowElevation | <a name="NsisOptions-allowElevation"></a>Allow requesting for elevation. If false, user will have to restart installer with elevated permissions. Defaults to `true`.
| installerHeader | <a name="NsisOptions-installerHeader"></a>*boring installer only.* `MUI_HEADERIMAGE`, relative to the project directory. Defaults to `build/installerHeader.bmp`
| 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.

Expand Down
2 changes: 1 addition & 1 deletion src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ export interface NsisOptions {
readonly perMachine?: boolean | null

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

Expand Down
2 changes: 1 addition & 1 deletion src/targets/nsis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default class NsisTarget extends Target {
defines.INSTALL_MODE_PER_ALL_USERS = null
}

if (this.options.allowElevation !== false) {
if (!oneClick && this.options.allowElevation !== false) {
defines.MULTIUSER_INSTALLMODE_ALLOW_ELEVATION = null
}

Expand Down
15 changes: 7 additions & 8 deletions templates/nsis/NsisMultiUser.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ Var RadioButtonLabel1
!define MULTIUSER_INSTALLMODE_DISPLAYNAME "${PRODUCT_NAME} ${VERSION}"
!endif

RequestExecutionLevel user

; Sets install mode to "per-machine" (all users).
!macro MULTIUSER_INSTALLMODE_ALLUSERS UNINSTALLER_PREFIX UNINSTALLER_FUNCPREFIX
;Install mode initialization - per-machine
Expand Down Expand Up @@ -372,8 +370,9 @@ FunctionEnd
SendMessage $MultiUser.InstallModePage.AllUsers ${BM_GETCHECK} 0 0 $MultiUser.InstallModePage.ReturnValue

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

ShowWindow $HWNDPARENT ${SW_SHOW}
BringToFront
Abort ; Stay on page - http://nsis.sourceforge.net/Abort
!else
;se não é Power ou Admin, e não é permitida elevation, então nem deveria ter chegado aqui... o radiobutton deveria estar disabled
# Stay on page
Abort
!endif
${else}
Call ${UNINSTALLER_FUNCPREFIX}MultiUser.InstallMode.AllUsers ; if it's Power or Admin, just go on with installation...
# if it's Power or Admin, just go on with installation
Call ${UNINSTALLER_FUNCPREFIX}MultiUser.InstallMode.AllUsers
${endif}
${else}
Call ${UNINSTALLER_FUNCPREFIX}MultiUser.InstallMode.CurrentUser
Expand Down
7 changes: 7 additions & 0 deletions templates/nsis/installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ FunctionEnd
AutoCloseWindow true
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_INSTFILES

!ifdef INSTALL_MODE_PER_ALL_USERS
RequestExecutionLevel admin
!else
RequestExecutionLevel user
!endif
!else
RequestExecutionLevel user
!include "boring-installer.nsh"
!endif

Expand Down
15 changes: 6 additions & 9 deletions test/src/winPackagerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,15 @@ test.ifDevOrLinuxCi("nsis 32 perMachine", () => assertPack("test-app-one", {
}))

test.ifNotCiOsx("nsis boring", () => assertPack("test-app-one", _signed({
targets: Platform.WINDOWS.createTarget(["nsis"]),
devMetadata: {
build: {
nsis: {
oneClick: false,
}
targets: Platform.WINDOWS.createTarget(["nsis"]),
devMetadata: {
build: {
nsis: {
oneClick: false,
}
}
}), {
useTempDir: true,
}
))
})))

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

0 comments on commit 9f52848

Please sign in to comment.