Skip to content

Commit

Permalink
feat: add custom download completed notification (#4952)
Browse files Browse the repository at this point in the history
* feat: add custom download completed notification

Added optional parameter for download notification in checkForUpdatesAndNotify
- if the parameter not given, uses default notification message.
- if {appName} occurs in notification body or title, formatNotification changes it to application name.
- if {version} occurs in notification body or title, formatNotification changes it to application version.

* fix typing in DownloadNotification interface.
  • Loading branch information
onurpolattimur committed May 26, 2020
1 parent 7f8d59c commit 3ffea83
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions packages/electron-updater/src/AppUpdater.ts
Expand Up @@ -244,7 +244,7 @@ export abstract class AppUpdater extends EventEmitter {
}

// noinspection JSUnusedGlobalSymbols
checkForUpdatesAndNotify(): Promise<UpdateCheckResult | null> {
checkForUpdatesAndNotify(downloadNotification?: DownloadNotification): Promise<UpdateCheckResult | null> {
if (!this.isUpdaterActive()) {
return Promise.resolve(null)
}
Expand All @@ -262,16 +262,28 @@ export abstract class AppUpdater extends EventEmitter {

downloadPromise
.then(() => {
new Notification({
title: "A new update is ready to install",
body: `${this.app.name} version ${it.updateInfo.version} has been downloaded and will be automatically installed on exit`
}).show()
const notificationContent = this.formatDownloadNotification(it.updateInfo.version, this.app.name, downloadNotification);
new Notification(notificationContent).show()
})

return it
})
}

private formatDownloadNotification(version: string, appName: string, downloadNotification?: DownloadNotification): DownloadNotification {
if (downloadNotification == null) {
downloadNotification = {
title: "A new update is ready to install",
body: `{appName} version {version} has been downloaded and will be automatically installed on exit`
}
}
downloadNotification = {
title: downloadNotification.title.replace("{appName}", appName).replace("{version}", version),
body: downloadNotification.body.replace("{appName}", appName).replace("{version}", version)
}
return downloadNotification;
}

private async isStagingMatch(updateInfo: UpdateInfo): Promise<boolean> {
const rawStagingPercentage = updateInfo.stagingPercentage
let stagingPercentage = rawStagingPercentage
Expand Down Expand Up @@ -665,6 +677,11 @@ export interface DownloadExecutorTask {
readonly done?: (event: UpdateDownloadedEvent) => Promise<any>
}

export interface DownloadNotification {
body: string
title: string
}

/** @private */
export interface TestOnlyUpdaterOptions {
platform: ProviderPlatform
Expand Down

0 comments on commit 3ffea83

Please sign in to comment.