Skip to content

Commit

Permalink
feat(updater): allow usage of autoRunAppAfterInstall with mac updat…
Browse files Browse the repository at this point in the history
…er (#8633)
  • Loading branch information
mmaietta authored Oct 26, 2024
1 parent 2a3195d commit 96f5c3e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/new-zoos-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"electron-updater": minor
---

feat(updater): allow usage of `autoRunAppAfterInstall` on mac updater
4 changes: 3 additions & 1 deletion packages/electron-updater/src/AppUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,18 @@ export type AppUpdaterEvents = {
export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter<AppUpdaterEvents>) {
/**
* Whether to automatically download an update when it is found.
* @default true
*/
autoDownload = true

/**
* Whether to automatically install a downloaded update on app quit (if `quitAndInstall` was not called before).
* @default true
*/
autoInstallOnAppQuit = true

/**
* *windows-only* Whether to run the app after finish install when run the installer NOT in silent mode.
* Whether to run the app after finish install when run the installer is NOT in silent mode.
* @default true
*/
autoRunAppAfterInstall = true
Expand Down
17 changes: 11 additions & 6 deletions packages/electron-updater/src/MacUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,17 +253,22 @@ export class MacUpdater extends AppUpdater {
})
}

private handleUpdateDownloaded() {
if (this.autoRunAppAfterInstall) {
this.nativeUpdater.quitAndInstall()
} else {
this.app.quit()
}
this.closeServerIfExists()
}

quitAndInstall(): void {
if (this.squirrelDownloadedUpdate) {
// update already fetched by Squirrel, it's ready to install
this.nativeUpdater.quitAndInstall()
this.closeServerIfExists()
this.handleUpdateDownloaded()
} else {
// Quit and install as soon as Squirrel get the update
this.nativeUpdater.on("update-downloaded", () => {
this.nativeUpdater.quitAndInstall()
this.closeServerIfExists()
})
this.nativeUpdater.on("update-downloaded", () => this.handleUpdateDownloaded())

if (!this.autoInstallOnAppQuit) {
/**
Expand Down

0 comments on commit 96f5c3e

Please sign in to comment.