Skip to content
Open
Show file tree
Hide file tree
Changes from all 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.
19 changes: 14 additions & 5 deletions packages/electron-updater/src/AppUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -365,7 +364,7 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter
}

// noinspection JSUnusedGlobalSymbols
checkForUpdatesAndNotify(downloadNotification?: DownloadNotification): Promise<UpdateCheckResult | null> {
checkForUpdatesAndNotify(downloadNotification?: Electron.Notification | DownloadNotification): Promise<UpdateCheckResult | null> {
return this.checkForUpdates().then(it => {
if (!it?.downloadPromise) {
if (this._logger.debug != null) {
Expand All @@ -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
Expand Down
Loading