diff --git a/.changeset/five-actors-boil.md b/.changeset/five-actors-boil.md new file mode 100644 index 00000000000..d5740d38c8e --- /dev/null +++ b/.changeset/five-actors-boil.md @@ -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. diff --git a/packages/electron-updater/src/AppUpdater.ts b/packages/electron-updater/src/AppUpdater.ts index e69afe62d35..bf0d794a4b9 100644 --- a/packages/electron-updater/src/AppUpdater.ts +++ b/packages/electron-updater/src/AppUpdater.ts @@ -29,7 +29,6 @@ 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 type { AuthInfo } from "electron" import { gunzipSync, gzipSync } from "zlib" import { DifferentialDownloaderOptions } from "./differentialDownloader/DifferentialDownloader" @@ -180,7 +179,7 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter protected _logger: Logger = console // noinspection JSMethodCanBeStatic,JSUnusedGlobalSymbols - get netSession(): Session { + get netSession(): Electron.Session { return getNetSession() } @@ -365,7 +364,7 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter } // noinspection JSUnusedGlobalSymbols - checkForUpdatesAndNotify(downloadNotification?: DownloadNotification): Promise { + checkForUpdatesAndNotify(downloadNotification?: Electron.Notification | DownloadNotification): Promise { return this.checkForUpdates().then(it => { if (!it?.downloadPromise) { if (this._logger.debug != null) { @@ -375,8 +374,18 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter } void it.downloadPromise.then(() => { - const notificationContent = AppUpdater.formatDownloadNotification(it.updateInfo.version, this.app.name, downloadNotification) - new (require("electron").Notification)(notificationContent).show() + const version = it.updateInfo.version + const appName = this.app.name + + if (downloadNotification instanceof Electron.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 Electron.Notification(notificationContent).show() + } }) return it