feat(gui): show available version in update notifier modal (#928)

We show the Etcher version string in the update notifier modal, by giving
the version string to the template through options similar to the warning
modal.

- We memoize the version Promise and assume the update version won't change
  during runtime.

Changelog-Entry: Show available Etcher version in the update notifier.
Signed-off-by: Juan Cruz Viotti <jviotti@openmailbox.org>
This commit is contained in:
Benedict Aas 2016-12-06 15:33:52 +00:00 committed by Juan Cruz Viotti
parent b63f967d44
commit cce9ce25d7
4 changed files with 32 additions and 15 deletions

View File

@ -80,7 +80,7 @@ app.run(() => {
].join('\n')); ].join('\n'));
}); });
app.run((AnalyticsService, UpdateNotifierService, SelectionStateModel) => { app.run((AnalyticsService, ErrorService, UpdateNotifierService, SelectionStateModel) => {
AnalyticsService.logEvent('Application start'); AnalyticsService.logEvent('Application start');
if (UpdateNotifierService.shouldCheckForUpdates() && !process.env.ETCHER_DISABLE_UPDATES) { if (UpdateNotifierService.shouldCheckForUpdates() && !process.env.ETCHER_DISABLE_UPDATES) {
@ -96,9 +96,9 @@ app.run((AnalyticsService, UpdateNotifierService, SelectionStateModel) => {
if (!isLatestVersion && !SelectionStateModel.hasImage()) { if (!isLatestVersion && !SelectionStateModel.hasImage()) {
AnalyticsService.logEvent('Notifying update'); AnalyticsService.logEvent('Notifying update');
UpdateNotifierService.notify(); return UpdateNotifierService.notify();
} }
}); }).catch(ErrorService.reportException);
} }
}); });

View File

@ -16,7 +16,7 @@
'use strict'; '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 // 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. // 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; this.settings = SettingsModel;
/**
* @summary Modal options
* @type Object
* @public
*/
this.options = options;
/** /**
* @summary Close the modal * @summary Close the modal
* @function * @function

View File

@ -16,6 +16,7 @@
'use strict'; 'use strict';
const _ = require('lodash');
const semver = require('semver'); const semver = require('semver');
const etcherLatestVersion = require('etcher-latest-version'); 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 * @summary Get the latest available Etcher version
* @function * @function
* @private * @private
* @description
* We assume the received latest version number will not increase
* while Etcher is running and memoize it
* *
* @fulfil {String} - latest version * @fulfil {String} - latest version
* @returns {Promise} * @returns {Promise}
@ -34,7 +38,7 @@ module.exports = function($http, $q, ModalService, UPDATE_NOTIFIER_SLEEP_TIME, M
* console.log(`The latest version is: ${latestVersion}`); * console.log(`The latest version is: ${latestVersion}`);
* }); * });
*/ */
this.getLatestVersion = () => { this.getLatestVersion = _.memoize(() => {
return $q((resolve, reject) => { return $q((resolve, reject) => {
return etcherLatestVersion((url, callback) => { return etcherLatestVersion((url, callback) => {
return $http.get(url).then((response) => { return $http.get(url).then((response) => {
@ -50,7 +54,9 @@ module.exports = function($http, $q, ModalService, UPDATE_NOTIFIER_SLEEP_TIME, M
return resolve(latestVersion); return resolve(latestVersion);
}); });
}); });
};
// Arbitrary identifier for the memoization function
}, _.constant('latest-version'));
/** /**
* @summary Check if the current version is the 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(); * UpdateNotifierService.notify();
*/ */
this.notify = () => { this.notify = () => {
return this.getLatestVersion().then((version) => {
return ModalService.open({ return ModalService.open({
template: './components/update-notifier/templates/update-notifier-modal.tpl.html', template: './components/update-notifier/templates/update-notifier-modal.tpl.html',
controller: 'UpdateNotifierController as modal', controller: 'UpdateNotifierController as modal',
size: 'update-notifier' size: 'update-notifier',
resolve: {
options: _.constant({
version: version
})
}
}).result; }).result;
});
}; };
}; };

View File

@ -5,10 +5,7 @@
<div class="modal-body"> <div class="modal-body">
<div class="modal-text"> <div class="modal-text">
<p>A new version of Etcher is available for download</p> <p>Etcher {{ ::modal.options.version }} is available for download</p>
<a os-open-external="https://github.com/resin-io/etcher/blob/master/CHANGELOG.md#readme">
See what's new
</a>
</div> </div>
</div> </div>