Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add custom download completed notification #4952

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 23 additions & 6 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,9 +677,14 @@ export interface DownloadExecutorTask {
readonly done?: (event: UpdateDownloadedEvent) => Promise<any>
}

export interface DownloadNotification {
body: string
title: string
}

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

isUseDifferentialDownload?: boolean
}
}