diff --git a/lib/gui/app.js b/lib/gui/app.js index b7077e2d..59f29afc 100644 --- a/lib/gui/app.js +++ b/lib/gui/app.js @@ -80,7 +80,7 @@ app.run(() => { ].join('\n')); }); -app.run((AnalyticsService, UpdateNotifierService, SelectionStateModel) => { +app.run((AnalyticsService, ErrorService, UpdateNotifierService, SelectionStateModel) => { AnalyticsService.logEvent('Application start'); if (UpdateNotifierService.shouldCheckForUpdates() && !process.env.ETCHER_DISABLE_UPDATES) { @@ -96,9 +96,9 @@ app.run((AnalyticsService, UpdateNotifierService, SelectionStateModel) => { if (!isLatestVersion && !SelectionStateModel.hasImage()) { AnalyticsService.logEvent('Notifying update'); - UpdateNotifierService.notify(); + return UpdateNotifierService.notify(); } - }); + }).catch(ErrorService.reportException); } }); diff --git a/lib/gui/components/update-notifier/controllers/update-notifier.js b/lib/gui/components/update-notifier/controllers/update-notifier.js index a70649cf..3e3894a7 100644 --- a/lib/gui/components/update-notifier/controllers/update-notifier.js +++ b/lib/gui/components/update-notifier/controllers/update-notifier.js @@ -16,7 +16,7 @@ 'use strict'; -module.exports = function($uibModalInstance, SettingsModel) { +module.exports = function($uibModalInstance, SettingsModel, options) { // We update this value in this controller since its the only place // where we can be sure the modal was really presented to the user. @@ -32,6 +32,13 @@ module.exports = function($uibModalInstance, SettingsModel) { */ this.settings = SettingsModel; + /** + * @summary Modal options + * @type Object + * @public + */ + this.options = options; + /** * @summary Close the modal * @function diff --git a/lib/gui/components/update-notifier/services/update-notifier.js b/lib/gui/components/update-notifier/services/update-notifier.js index 9bc4b25b..c0b1f447 100644 --- a/lib/gui/components/update-notifier/services/update-notifier.js +++ b/lib/gui/components/update-notifier/services/update-notifier.js @@ -16,6 +16,7 @@ 'use strict'; +const _ = require('lodash'); const semver = require('semver'); const etcherLatestVersion = require('etcher-latest-version'); @@ -25,6 +26,9 @@ module.exports = function($http, $q, ModalService, UPDATE_NOTIFIER_SLEEP_TIME, M * @summary Get the latest available Etcher version * @function * @private + * @description + * We assume the received latest version number will not increase + * while Etcher is running and memoize it * * @fulfil {String} - latest version * @returns {Promise} @@ -34,7 +38,7 @@ module.exports = function($http, $q, ModalService, UPDATE_NOTIFIER_SLEEP_TIME, M * console.log(`The latest version is: ${latestVersion}`); * }); */ - this.getLatestVersion = () => { + this.getLatestVersion = _.memoize(() => { return $q((resolve, reject) => { return etcherLatestVersion((url, callback) => { return $http.get(url).then((response) => { @@ -50,7 +54,9 @@ module.exports = function($http, $q, ModalService, UPDATE_NOTIFIER_SLEEP_TIME, M return resolve(latestVersion); }); }); - }; + + // Arbitrary identifier for the memoization function + }, _.constant('latest-version')); /** * @summary Check if the current version is the latest version @@ -111,11 +117,18 @@ module.exports = function($http, $q, ModalService, UPDATE_NOTIFIER_SLEEP_TIME, M * UpdateNotifierService.notify(); */ this.notify = () => { - return ModalService.open({ - template: './components/update-notifier/templates/update-notifier-modal.tpl.html', - controller: 'UpdateNotifierController as modal', - size: 'update-notifier' - }).result; + return this.getLatestVersion().then((version) => { + return ModalService.open({ + template: './components/update-notifier/templates/update-notifier-modal.tpl.html', + controller: 'UpdateNotifierController as modal', + size: 'update-notifier', + resolve: { + options: _.constant({ + version: version + }) + } + }).result; + }); }; }; diff --git a/lib/gui/components/update-notifier/templates/update-notifier-modal.tpl.html b/lib/gui/components/update-notifier/templates/update-notifier-modal.tpl.html index f4ba7684..06e932be 100644 --- a/lib/gui/components/update-notifier/templates/update-notifier-modal.tpl.html +++ b/lib/gui/components/update-notifier/templates/update-notifier-modal.tpl.html @@ -5,10 +5,7 @@
A new version of Etcher is available for download
- - See what's new - +Etcher {{ ::modal.options.version }} is available for download