From 434afdbd1b0a0c54c6db5f44efd1e942019b8440 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Wed, 10 Jul 2019 14:42:40 -0700 Subject: [PATCH] feat: add notifyUser option to disable the upgrade dialog prompt (#46) --- index.js | 37 ++++++++++++++++++++----------------- readme.md | 16 +++++++++------- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/index.js b/index.js index 9dcd754..2402fd3 100644 --- a/index.js +++ b/index.js @@ -70,21 +70,23 @@ function initUpdater (opts) { log('update-not-available') }) - autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName, releaseDate, updateURL) => { - log('update-downloaded', arguments) - - const dialogOpts = { - type: 'info', - buttons: ['Restart', 'Later'], - title: 'Application Update', - message: process.platform === 'win32' ? releaseNotes : releaseName, - detail: 'A new version has been downloaded. Restart the application to apply the updates.' - } - - dialog.showMessageBox(dialogOpts, (response) => { - if (response === 0) autoUpdater.quitAndInstall() + if (opts.notifyUser) { + autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName, releaseDate, updateURL) => { + log('update-downloaded', arguments) + + const dialogOpts = { + type: 'info', + buttons: ['Restart', 'Later'], + title: 'Application Update', + message: process.platform === 'win32' ? releaseNotes : releaseName, + detail: 'A new version has been downloaded. Restart the application to apply the updates.' + } + + dialog.showMessageBox(dialogOpts, (response) => { + if (response === 0) autoUpdater.quitAndInstall() + }) }) - }) + } // check for updates right away and keep checking later autoUpdater.checkForUpdates() @@ -95,9 +97,10 @@ function validateInput (opts) { const defaults = { host: 'https://update.electronjs.org', updateInterval: '10 minutes', - logger: console + logger: console, + notifyUser: true } - const {host, updateInterval, logger} = Object.assign({}, defaults, opts) + const {host, updateInterval, logger, notifyUser} = Object.assign({}, defaults, opts) // allows electron to be mocked in tests const electron = opts.electron || require('electron') @@ -140,5 +143,5 @@ function validateInput (opts) { 'function' ) - return {host, repo, updateInterval, logger, electron} + return {host, repo, updateInterval, logger, electron, notifyUser} } diff --git a/readme.md b/readme.md index 36309de..e6d5e8b 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -# update-electron-app +# update-electron-app > A drop-in module that adds autoUpdating capabilities to Electron apps @@ -57,20 +57,22 @@ Options: - `host` String (optional) - Defaults to `https://update.electronjs.org` - `updateInterval` String (optional) - How frequently to check for updates. Defaults to `10 minutes`. Minimum allowed interval is `5 minutes`. - `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. +- `notifyUser` Boolean (optional) - Defaults to `true`. When enabled the user will be + prompted to apply the update immediately after download. ## FAQ #### What kinds of assets do I need to build? -For macOS, you'll need to build a `.zip` file and include it in your GitHub Release. +For macOS, you'll need to build a `.zip` file and include it in your GitHub Release. Use [electron-forge] or [electron-installer-zip] to package your app as a zip. -For Windows, you'll need to build a `.exe` file and include it in your GitHub Release. +For Windows, you'll need to build a `.exe` file and include it in your GitHub Release. #### Why is my app launching multiple times? Windows apps have an update process that requires multiple application restarts. -You can use the [electron-squirrel-startup](https://github.com/mongodb-js/electron-squirrel-startup) module to improve this +You can use the [electron-squirrel-startup](https://github.com/mongodb-js/electron-squirrel-startup) module to improve this behavior. #### Can I use this module by uploading my private app's builds to a public GitHub repository? @@ -83,10 +85,10 @@ MIT ## See Also -If your app is packaged with `electron-builder`, you may not need this module. -Builder has its own built-in mechanism for updating apps. Find out more at +If your app is packaged with `electron-builder`, you may not need this module. +Builder has its own built-in mechanism for updating apps. Find out more at [electron.build/auto-update](https://www.electron.build/auto-update). [electron-forge]: https://github.com/electron-userland/electron-forge [electron-installer-zip]: https://github.com/mongodb-js/electron-installer-zip -[code signed]: https://github.com/electron/electron/blob/master/docs/tutorial/code-signing.md \ No newline at end of file +[code signed]: https://github.com/electron/electron/blob/master/docs/tutorial/code-signing.md