Skip to content

Commit

Permalink
feat(nsis): Add flag to force start on silent install
Browse files Browse the repository at this point in the history
If --force-run flag is specified on installer then will start the app on silent install
Exposed forceRun flag on NSIS updater quit and install, default value is false

electron-userland#1545
  • Loading branch information
Szava authored and Szava committed Jun 20, 2017
1 parent 239d16d commit 7dc1935
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
9 changes: 9 additions & 0 deletions packages/electron-builder/templates/nsis/common.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ Name "${PRODUCT_NAME}"
!macroend
!define Updated `"" Updated ""`

!macro _ForceRun _a _b _t _f
ClearErrors
${GetParameters} $R9
${GetOptions} $R9 "--force-run" $R8
IfErrors `${_f}` `${_t}`
!macroend
!define ForceRun `"" ForceRun ""`


!macro extractEmbeddedAppPackage
!ifdef COMPRESS
SetCompress off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ ${endif}
!ifdef ONE_CLICK
!ifdef RUN_AFTER_FINISH
${IfNot} ${Silent}
${OrIf} ${ForceRun}
# otherwise app window will be in backround
HideWindow
!insertmacro StartApp
Expand Down
13 changes: 9 additions & 4 deletions packages/electron-updater/src/NsisUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,17 @@ export class NsisUpdater extends AppUpdater {

this.app.on("quit", () => {
this._logger.info("Auto install update on quit")
this.install(true)
this.install(true, false)
})
}

quitAndInstall(isSilent: boolean = false): void {
if (this.install(isSilent)) {
quitAndInstall(isSilent: boolean = false, forceRunAfter: boolean = false): void {
if (this.install(isSilent, forceRunAfter)) {
this.app.quit()
}
}

private install(isSilent: boolean): boolean {
private install(isSilent: boolean, forceRunAfter: boolean): boolean {
if (this.quitAndInstallCalled) {
return false
}
Expand All @@ -163,6 +163,11 @@ export class NsisUpdater extends AppUpdater {
if (isSilent) {
args.push("/S")
}

if (forceRunAfter) {
args.push("--force-run")
}

const spawnOptions = {
detached: true,
stdio: "ignore",
Expand Down

0 comments on commit 7dc1935

Please sign in to comment.