Skip to content
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/five-actors-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"electron-updater": minor
---

Enhanced the `checkForUpdatesAndNotify` method to provide more flexible download notification options. The method now accepts custom Electron Notification instances, allows disabling notifications entirely, while maintaining full backward compatibility.
25 changes: 19 additions & 6 deletions packages/electron-updater/src/AppUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { GenericProvider } from "./providers/GenericProvider"
import { createClient, isUrlProbablySupportMultiRangeRequests } from "./providerFactory"
import { Provider, ProviderPlatform } from "./providers/Provider"
import type { TypedEmitter } from "tiny-typed-emitter"
import Session = Electron.Session
import { Session, Notification } from "electron"
import type { AuthInfo } from "electron"
import { gunzipSync, gzipSync } from "zlib"
import { DifferentialDownloaderOptions } from "./differentialDownloader/DifferentialDownloader"
Expand Down Expand Up @@ -365,7 +365,7 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter
}

// noinspection JSUnusedGlobalSymbols
checkForUpdatesAndNotify(downloadNotification?: DownloadNotification): Promise<UpdateCheckResult | null> {
checkForUpdatesAndNotify(downloadNotification?: Notification | DownloadNotification | false): Promise<UpdateCheckResult | null> {
return this.checkForUpdates().then(it => {
if (!it?.downloadPromise) {
if (this._logger.debug != null) {
Expand All @@ -374,10 +374,23 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter
return it
}

void it.downloadPromise.then(() => {
const notificationContent = AppUpdater.formatDownloadNotification(it.updateInfo.version, this.app.name, downloadNotification)
new (require("electron").Notification)(notificationContent).show()
})
if (downloadNotification !== false) {
// Stricly conditional check with false to allow for disabling notifications
void it.downloadPromise.then(() => {
const version = it.updateInfo.version
const appName = this.app.name

if (downloadNotification instanceof Notification) {
// Allow custom electron Notification
downloadNotification.title = downloadNotification.title.replace("{appName}", appName).replace("{version}", version)
downloadNotification.body = downloadNotification.body.replace("{appName}", appName).replace("{version}", version)
downloadNotification.show()
} else {
const notificationContent = AppUpdater.formatDownloadNotification(version, appName, downloadNotification)
new (require("electron").Notification)(notificationContent).show()
}
})
}

return it
})
Expand Down
Loading