diff --git a/.changeset/chilly-days-yawn.md b/.changeset/chilly-days-yawn.md new file mode 100644 index 0000000000..7baf836338 --- /dev/null +++ b/.changeset/chilly-days-yawn.md @@ -0,0 +1,5 @@ +--- +"electron-updater": minor +--- + +feat: non-silent mode allow not to run the app when the installation is complete diff --git a/docs/api/electron-builder.md b/docs/api/electron-builder.md index 3f69764cb2..98ba6f80af 100644 --- a/docs/api/electron-builder.md +++ b/docs/api/electron-builder.md @@ -1,5 +1,5 @@ Developer API only. See [Configuration](../configuration/configuration.md) for user documentation. - +

Modules

@@ -1585,6 +1585,9 @@ return path.join(target.outDir, __${target.name}-${getArtifactArchName(arc

autoInstallOnAppQuit = true Boolean - Whether to automatically install a downloaded update on app quit (if quitAndInstall was not called before).

  • +

    autoRunAppAfterInstall = true Boolean - windows-only Whether to run the app after finish install when run the installer NOT in silent mode.

    +
  • +
  • allowPrerelease = false Boolean - GitHub provider only. Whether to allow update to pre-release versions. Defaults to true if application version contains prerelease components (e.g. 0.12.1-alpha.1, here alpha is a prerelease component), otherwise false.

    If true, downgrade will be allowed (allowDowngrade will be set to true).

  • @@ -1745,7 +1748,7 @@ This is different from the normal quit event sequence.

    isForceRunAfter Boolean -Run the app after finish even on silent install. Not applicable for macOS. Ignored if isSilent is set to false. +Run the app after finish even on silent install. Not applicable for macOS. Ignored if isSilent is set to false(In this case you can still set autoRunAppAfterInstall to false to prevent run the app) diff --git a/packages/electron-updater/src/AppUpdater.ts b/packages/electron-updater/src/AppUpdater.ts index a3afa1299a..92e4c98768 100644 --- a/packages/electron-updater/src/AppUpdater.ts +++ b/packages/electron-updater/src/AppUpdater.ts @@ -53,6 +53,12 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter */ autoInstallOnAppQuit = true + /** + * *windows-only* Whether to run the app after finish install when run the installer NOT in silent mode. + * @default true + */ + autoRunAppAfterInstall = true + /** * *GitHub provider only.* Whether to allow update to pre-release versions. Defaults to `true` if application version contains prerelease components (e.g. `0.12.1-alpha.1`, here `alpha` is a prerelease component), otherwise `false`. * @@ -513,7 +519,8 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter * This is different from the normal quit event sequence. * * @param isSilent *windows-only* Runs the installer in silent mode. Defaults to `false`. - * @param isForceRunAfter Run the app after finish even on silent install. Not applicable for macOS. Ignored if `isSilent` is set to `false`. + * @param isForceRunAfter Run the app after finish even on silent install. Not applicable for macOS. + * Ignored if `isSilent` is set to `false`(In this case you can still set `autoRunAppAfterInstall` to `false` to prevent run the app after finish). */ abstract quitAndInstall(isSilent?: boolean, isForceRunAfter?: boolean): void diff --git a/packages/electron-updater/src/BaseUpdater.ts b/packages/electron-updater/src/BaseUpdater.ts index 3290c3fb42..c4170b599c 100644 --- a/packages/electron-updater/src/BaseUpdater.ts +++ b/packages/electron-updater/src/BaseUpdater.ts @@ -12,7 +12,8 @@ export abstract class BaseUpdater extends AppUpdater { quitAndInstall(isSilent = false, isForceRunAfter = false): void { this._logger.info(`Install on explicit quitAndInstall`) - const isInstalled = this.install(isSilent, isSilent ? isForceRunAfter : true) + // If NOT in silent mode use `autoRunAppAfterInstall` to determine whether to force run the app + const isInstalled = this.install(isSilent, isSilent ? isForceRunAfter : this.autoRunAppAfterInstall) if (isInstalled) { setImmediate(() => { // this event is normally emitted when calling quitAndInstall, this emulates that