Skip to content

Commit

Permalink
feat: add option for quitAndInstall for non-silent update without res…
Browse files Browse the repository at this point in the history
…tart (#7136)
  • Loading branch information
shenglianlee committed Oct 1, 2022
1 parent 50d126e commit 4d989a8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .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
7 changes: 5 additions & 2 deletions docs/api/electron-builder.md
@@ -1,5 +1,5 @@
Developer API only. See [Configuration](../configuration/configuration.md) for user documentation.

<!-- do not edit. start of generated block -->
<h1 id="modules">Modules</h1>
<dl>
Expand Down Expand Up @@ -1585,6 +1585,9 @@ return path.join(target.outDir, <code>__${target.name}-${getArtifactArchName(arc
<p><code id="AppUpdater-autoInstallOnAppQuit">autoInstallOnAppQuit</code> = <code>true</code> Boolean - Whether to automatically install a downloaded update on app quit (if <code>quitAndInstall</code> was not called before).</p>
</li>
<li>
<p><code id="AppUpdater-autoRunAppAfterInstall">autoRunAppAfterInstall</code> = <code>true</code> Boolean - <em>windows-only</em> Whether to run the app after finish install when run the installer <em>NOT in silent mode</em>.</p>
</li>
<li>
<p><code id="AppUpdater-allowPrerelease">allowPrerelease</code> = <code>false</code> Boolean - <em>GitHub provider only.</em> Whether to allow update to pre-release versions. Defaults to <code>true</code> if application version contains prerelease components (e.g. <code>0.12.1-alpha.1</code>, here <code>alpha</code> is a prerelease component), otherwise <code>false</code>.</p>
<p>If <code>true</code>, downgrade will be allowed (<code>allowDowngrade</code> will be set to <code>true</code>).</p>
</li>
Expand Down Expand Up @@ -1745,7 +1748,7 @@ This is different from the normal quit event sequence.</p>
<tr>
<td>isForceRunAfter</td>
<td><code>Boolean</code></td>
<td>Run the app after finish even on silent install. Not applicable for macOS. Ignored if <code>isSilent</code> is set to <code>false</code>.</td>
<td>Run the app after finish even on silent install. Not applicable for macOS. Ignored if <code>isSilent</code> is set to <code>false</code>(In this case you can still set <code>autoRunAppAfterInstall</code> to <code>false</code> to prevent run the app)</td>
</tr>
</tbody>
</table>
Expand Down
9 changes: 8 additions & 1 deletion packages/electron-updater/src/AppUpdater.ts
Expand Up @@ -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`.
*
Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion packages/electron-updater/src/BaseUpdater.ts
Expand Up @@ -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
Expand Down

0 comments on commit 4d989a8

Please sign in to comment.