Skip to content

Commit 434afdb

Browse files
mvinesmalept
authored andcommitted
feat: add notifyUser option to disable the upgrade dialog prompt (#46)
1 parent 32ecb3a commit 434afdb

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

index.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,23 @@ function initUpdater (opts) {
7070
log('update-not-available')
7171
})
7272

73-
autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName, releaseDate, updateURL) => {
74-
log('update-downloaded', arguments)
75-
76-
const dialogOpts = {
77-
type: 'info',
78-
buttons: ['Restart', 'Later'],
79-
title: 'Application Update',
80-
message: process.platform === 'win32' ? releaseNotes : releaseName,
81-
detail: 'A new version has been downloaded. Restart the application to apply the updates.'
82-
}
83-
84-
dialog.showMessageBox(dialogOpts, (response) => {
85-
if (response === 0) autoUpdater.quitAndInstall()
73+
if (opts.notifyUser) {
74+
autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName, releaseDate, updateURL) => {
75+
log('update-downloaded', arguments)
76+
77+
const dialogOpts = {
78+
type: 'info',
79+
buttons: ['Restart', 'Later'],
80+
title: 'Application Update',
81+
message: process.platform === 'win32' ? releaseNotes : releaseName,
82+
detail: 'A new version has been downloaded. Restart the application to apply the updates.'
83+
}
84+
85+
dialog.showMessageBox(dialogOpts, (response) => {
86+
if (response === 0) autoUpdater.quitAndInstall()
87+
})
8688
})
87-
})
89+
}
8890

8991
// check for updates right away and keep checking later
9092
autoUpdater.checkForUpdates()
@@ -95,9 +97,10 @@ function validateInput (opts) {
9597
const defaults = {
9698
host: 'https://update.electronjs.org',
9799
updateInterval: '10 minutes',
98-
logger: console
100+
logger: console,
101+
notifyUser: true
99102
}
100-
const {host, updateInterval, logger} = Object.assign({}, defaults, opts)
103+
const {host, updateInterval, logger, notifyUser} = Object.assign({}, defaults, opts)
101104

102105
// allows electron to be mocked in tests
103106
const electron = opts.electron || require('electron')
@@ -140,5 +143,5 @@ function validateInput (opts) {
140143
'function'
141144
)
142145

143-
return {host, repo, updateInterval, logger, electron}
146+
return {host, repo, updateInterval, logger, electron, notifyUser}
144147
}

readme.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# update-electron-app
1+
# update-electron-app
22

33
> A drop-in module that adds autoUpdating capabilities to Electron apps
44
@@ -57,20 +57,22 @@ Options:
5757
- `host` String (optional) - Defaults to `https://update.electronjs.org`
5858
- `updateInterval` String (optional) - How frequently to check for updates. Defaults to `10 minutes`. Minimum allowed interval is `5 minutes`.
5959
- `logger` Object (optional) - A custom logger object that defines a `log` function. Defaults to `console`. See [electron-log](https://github.com/megahertz/electron-log), a module that aggregates logs from main and renderer processes into a single file.
60+
- `notifyUser` Boolean (optional) - Defaults to `true`. When enabled the user will be
61+
prompted to apply the update immediately after download.
6062

6163
## FAQ
6264

6365
#### What kinds of assets do I need to build?
6466

65-
For macOS, you'll need to build a `.zip` file and include it in your GitHub Release.
67+
For macOS, you'll need to build a `.zip` file and include it in your GitHub Release.
6668
Use [electron-forge] or [electron-installer-zip] to package your app as a zip.
6769

68-
For Windows, you'll need to build a `.exe` file and include it in your GitHub Release.
70+
For Windows, you'll need to build a `.exe` file and include it in your GitHub Release.
6971

7072
#### Why is my app launching multiple times?
7173

7274
Windows apps have an update process that requires multiple application restarts.
73-
You can use the [electron-squirrel-startup](https://github.com/mongodb-js/electron-squirrel-startup) module to improve this
75+
You can use the [electron-squirrel-startup](https://github.com/mongodb-js/electron-squirrel-startup) module to improve this
7476
behavior.
7577

7678
#### Can I use this module by uploading my private app's builds to a public GitHub repository?
@@ -83,10 +85,10 @@ MIT
8385

8486
## See Also
8587

86-
If your app is packaged with `electron-builder`, you may not need this module.
87-
Builder has its own built-in mechanism for updating apps. Find out more at
88+
If your app is packaged with `electron-builder`, you may not need this module.
89+
Builder has its own built-in mechanism for updating apps. Find out more at
8890
[electron.build/auto-update](https://www.electron.build/auto-update).
8991

9092
[electron-forge]: https://github.com/electron-userland/electron-forge
9193
[electron-installer-zip]: https://github.com/mongodb-js/electron-installer-zip
92-
[code signed]: https://github.com/electron/electron/blob/master/docs/tutorial/code-signing.md
94+
[code signed]: https://github.com/electron/electron/blob/master/docs/tutorial/code-signing.md

0 commit comments

Comments
 (0)