From be2fe97741952cb786fcb693a1f4b600c690e32e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=94=9F=E7=82=BC?= Date: Wed, 14 Sep 2022 17:57:16 +0800 Subject: [PATCH 1/3] feat: add new method quitAppAndInstall --- docs/api/electron-builder.md | 31 +++++++++++++++++++- packages/electron-updater/src/AppUpdater.ts | 11 +++++++ packages/electron-updater/src/BaseUpdater.ts | 12 ++++++++ packages/electron-updater/src/MacUpdater.ts | 4 +++ 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/docs/api/electron-builder.md b/docs/api/electron-builder.md index 3f69764cb2..36b9e1ae94 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

@@ -1428,11 +1428,13 @@ return path.join(target.outDir, __${target.name}-${getArtifactArchName(arc
  • .setFeedURL(options)
  • .isUpdaterActive()Boolean
  • .quitAndInstall(isSilent, isForceRunAfter)
  • +
  • .quitAppAndInstall(isForceRunAfter)
  • .MacUpdaterAppUpdater
  • @@ -1749,6 +1752,28 @@ This is different from the normal quit event sequence.

    +

    +

    appUpdater.quitAppAndInstall(isForceRunAfter)

    +

    Quit the app and explicit installs the update after it has been downloaded. +It should only be called after update-downloaded has been emitted.

    +

    Note: autoUpdater.quitAppAndInstall() will close all application windows first and only emit before-quit event on app after that. +This is different from the normal quit event sequence.

    + + + + + + + + + + + + + + + +
    ParamTypeDescription
    isForceRunAfterBooleanRun the app after finish even on silent install. Not applicable for macOS.

    MacUpdater ⇐ AppUpdater

    Kind: class of electron-updater
    @@ -1757,6 +1782,7 @@ This is different from the normal quit event sequence.

  • .MacUpdaterAppUpdater
    • .quitAndInstall()
    • +
    • .quitAppAndInstall()
    • .addAuthHeader(token)
    • .checkForUpdates()Promise< | UpdateCheckResult>
    • .checkForUpdatesAndNotify(downloadNotification)Promise< | UpdateCheckResult>
    • @@ -1770,6 +1796,9 @@ This is different from the normal quit event sequence.

      macUpdater.quitAndInstall()

      Overrides: quitAndInstall
      +

      +

      macUpdater.quitAppAndInstall()

      +

      Overrides: quitAppAndInstall

      macUpdater.addAuthHeader(token)

      Shortcut for explicitly adding auth tokens to request headers

      diff --git a/packages/electron-updater/src/AppUpdater.ts b/packages/electron-updater/src/AppUpdater.ts index a3afa1299a..d07de9aeea 100644 --- a/packages/electron-updater/src/AppUpdater.ts +++ b/packages/electron-updater/src/AppUpdater.ts @@ -517,6 +517,17 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter */ abstract quitAndInstall(isSilent?: boolean, isForceRunAfter?: boolean): void + /** + * Quit the app and explicit installs the update after it has been downloaded. + * It should only be called after `update-downloaded` has been emitted. + * + * **Note:** `autoUpdater.quitAppAndInstall()` will close all application windows first and only emit `before-quit` event on `app` after that. + * This is different from the normal quit event sequence. + * + * @param isForceRunAfter Run the app after finish. Defaults to `false`. Not applicable for macOS. + */ + abstract quitAppAndInstall(isForceRunAfter?: boolean): void + private async loadUpdateConfig(): Promise { if (this._appUpdateConfigPath == null) { this._appUpdateConfigPath = this.app.appUpdateConfigPath diff --git a/packages/electron-updater/src/BaseUpdater.ts b/packages/electron-updater/src/BaseUpdater.ts index 3290c3fb42..d291e80e29 100644 --- a/packages/electron-updater/src/BaseUpdater.ts +++ b/packages/electron-updater/src/BaseUpdater.ts @@ -24,6 +24,18 @@ export abstract class BaseUpdater extends AppUpdater { } } + quitAppAndInstall(isForceRunAfter = false): void { + const isInstalled = this.install(false, isForceRunAfter); + if (isInstalled) { + setImmediate(() => { + require("electron").autoUpdater.emit("before-quit-for-update") + this.app.quit() + }) + } else { + this.quitAndInstallCalled = false + } + } + protected executeDownload(taskOptions: DownloadExecutorTask): Promise> { return super.executeDownload({ ...taskOptions, diff --git a/packages/electron-updater/src/MacUpdater.ts b/packages/electron-updater/src/MacUpdater.ts index f2dd2162aa..639786a579 100644 --- a/packages/electron-updater/src/MacUpdater.ts +++ b/packages/electron-updater/src/MacUpdater.ts @@ -233,4 +233,8 @@ export class MacUpdater extends AppUpdater { } } } + + quitAppAndInstall(): void { + this.quitAndInstall(); + } } From b7beedd70fbcd36d00ad9f4768d183e53e13bd8a Mon Sep 17 00:00:00 2001 From: lishenglian Date: Mon, 26 Sep 2022 16:37:05 +0800 Subject: [PATCH 2/3] feat: refine code to better achieve the purpose --- docs/api/electron-builder.md | 34 +++----------------- packages/electron-updater/src/AppUpdater.ts | 20 +++++------- packages/electron-updater/src/BaseUpdater.ts | 15 ++------- packages/electron-updater/src/MacUpdater.ts | 4 --- 4 files changed, 14 insertions(+), 59 deletions(-) diff --git a/docs/api/electron-builder.md b/docs/api/electron-builder.md index 36b9e1ae94..98ba6f80af 100644 --- a/docs/api/electron-builder.md +++ b/docs/api/electron-builder.md @@ -1428,13 +1428,11 @@ return path.join(target.outDir, __${target.name}-${getArtifactArchName(arc
    • .setFeedURL(options)
    • .isUpdaterActive()Boolean
    • .quitAndInstall(isSilent, isForceRunAfter)
    • -
    • .quitAppAndInstall(isForceRunAfter)
  • .MacUpdaterAppUpdater
  • @@ -1748,29 +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. - - - -

    -

    appUpdater.quitAppAndInstall(isForceRunAfter)

    -

    Quit the app and explicit installs the update after it has been downloaded. -It should only be called after update-downloaded has been emitted.

    -

    Note: autoUpdater.quitAppAndInstall() will close all application windows first and only emit before-quit event on app after that. -This is different from the normal quit event sequence.

    - - - - - - - - - - - - - +
    ParamTypeDescription
    isForceRunAfterBooleanRun the app after finish even on silent install. Not applicable for macOS.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)
    @@ -1782,7 +1760,6 @@ This is different from the normal quit event sequence.

  • .MacUpdaterAppUpdater
    • .quitAndInstall()
    • -
    • .quitAppAndInstall()
    • .addAuthHeader(token)
    • .checkForUpdates()Promise< | UpdateCheckResult>
    • .checkForUpdatesAndNotify(downloadNotification)Promise< | UpdateCheckResult>
    • @@ -1796,9 +1773,6 @@ This is different from the normal quit event sequence.

      macUpdater.quitAndInstall()

      Overrides: quitAndInstall
      -

      -

      macUpdater.quitAppAndInstall()

      -

      Overrides: quitAppAndInstall

      macUpdater.addAuthHeader(token)

      Shortcut for explicitly adding auth tokens to request headers

      diff --git a/packages/electron-updater/src/AppUpdater.ts b/packages/electron-updater/src/AppUpdater.ts index d07de9aeea..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,21 +519,11 @@ 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 - /** - * Quit the app and explicit installs the update after it has been downloaded. - * It should only be called after `update-downloaded` has been emitted. - * - * **Note:** `autoUpdater.quitAppAndInstall()` will close all application windows first and only emit `before-quit` event on `app` after that. - * This is different from the normal quit event sequence. - * - * @param isForceRunAfter Run the app after finish. Defaults to `false`. Not applicable for macOS. - */ - abstract quitAppAndInstall(isForceRunAfter?: boolean): void - private async loadUpdateConfig(): Promise { if (this._appUpdateConfigPath == null) { this._appUpdateConfigPath = this.app.appUpdateConfigPath diff --git a/packages/electron-updater/src/BaseUpdater.ts b/packages/electron-updater/src/BaseUpdater.ts index d291e80e29..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 @@ -24,18 +25,6 @@ export abstract class BaseUpdater extends AppUpdater { } } - quitAppAndInstall(isForceRunAfter = false): void { - const isInstalled = this.install(false, isForceRunAfter); - if (isInstalled) { - setImmediate(() => { - require("electron").autoUpdater.emit("before-quit-for-update") - this.app.quit() - }) - } else { - this.quitAndInstallCalled = false - } - } - protected executeDownload(taskOptions: DownloadExecutorTask): Promise> { return super.executeDownload({ ...taskOptions, diff --git a/packages/electron-updater/src/MacUpdater.ts b/packages/electron-updater/src/MacUpdater.ts index 639786a579..f2dd2162aa 100644 --- a/packages/electron-updater/src/MacUpdater.ts +++ b/packages/electron-updater/src/MacUpdater.ts @@ -233,8 +233,4 @@ export class MacUpdater extends AppUpdater { } } } - - quitAppAndInstall(): void { - this.quitAndInstall(); - } } From 5fd2b5aea06cd5792f6f36c261509bf593960de2 Mon Sep 17 00:00:00 2001 From: Mike Maietta Date: Fri, 30 Sep 2022 08:22:51 -0700 Subject: [PATCH 3/3] Create chilly-days-yawn.md --- .changeset/chilly-days-yawn.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/chilly-days-yawn.md 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