Skip to content
Closed
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.
20 changes: 15 additions & 5 deletions packages/electron-updater/src/AppUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
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 @@
}

// noinspection JSUnusedGlobalSymbols
checkForUpdatesAndNotify(downloadNotification?: DownloadNotification): Promise<UpdateCheckResult | null> {
checkForUpdatesAndNotify(downloadNotification: Notification | DownloadNotification): Promise<UpdateCheckResult | null> {
return this.checkForUpdates().then(it => {
if (!it?.downloadPromise) {
if (this._logger.debug != null) {
Expand All @@ -375,9 +375,19 @@
}

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

Check warning on line 378 in packages/electron-updater/src/AppUpdater.ts

View workflow job for this annotation

GitHub Actions / test-mac-old (differentialUpdateTest,blackboxUpdateTest,dmgTest)

Delete `··`
const appName = this.app.name

Check warning on line 379 in packages/electron-updater/src/AppUpdater.ts

View workflow job for this annotation

GitHub Actions / test-mac-old (differentialUpdateTest,blackboxUpdateTest,dmgTest)

Delete `··`

if (downloadNotification instanceof Notification) {

Check warning on line 381 in packages/electron-updater/src/AppUpdater.ts

View workflow job for this annotation

GitHub Actions / test-mac-old (differentialUpdateTest,blackboxUpdateTest,dmgTest)

Delete `··`
// Allow custom electron Notification

Check warning on line 382 in packages/electron-updater/src/AppUpdater.ts

View workflow job for this annotation

GitHub Actions / test-mac-old (differentialUpdateTest,blackboxUpdateTest,dmgTest)

Replace `············` with `··········`
downloadNotification.title = downloadNotification.title.replace("{appName}", appName).replace("{version}", version)

Check warning on line 383 in packages/electron-updater/src/AppUpdater.ts

View workflow job for this annotation

GitHub Actions / test-mac-old (differentialUpdateTest,blackboxUpdateTest,dmgTest)

Delete `··`
downloadNotification.body = downloadNotification.body.replace("{appName}", appName).replace("{version}", version)

Check warning on line 384 in packages/electron-updater/src/AppUpdater.ts

View workflow job for this annotation

GitHub Actions / test-mac-old (differentialUpdateTest,blackboxUpdateTest,dmgTest)

Delete `··`
downloadNotification.show()

Check warning on line 385 in packages/electron-updater/src/AppUpdater.ts

View workflow job for this annotation

GitHub Actions / test-mac-old (differentialUpdateTest,blackboxUpdateTest,dmgTest)

Replace `············` with `··········`
} else {

Check warning on line 386 in packages/electron-updater/src/AppUpdater.ts

View workflow job for this annotation

GitHub Actions / test-mac-old (differentialUpdateTest,blackboxUpdateTest,dmgTest)

Delete `··`
const notificationContent = AppUpdater.formatDownloadNotification(version, appName, downloadNotification)

Check warning on line 387 in packages/electron-updater/src/AppUpdater.ts

View workflow job for this annotation

GitHub Actions / test-mac-old (differentialUpdateTest,blackboxUpdateTest,dmgTest)

Delete `··`
new (require("electron").Notification)(notificationContent).show()

Check warning on line 388 in packages/electron-updater/src/AppUpdater.ts

View workflow job for this annotation

GitHub Actions / test-mac-old (differentialUpdateTest,blackboxUpdateTest,dmgTest)

Replace `············` with `··········`
}
});

return it
})
Expand Down
Loading