fix: check for updates only once at startup (#517)

Currently, the update check runs every single time the main application
controller is instantiated, meaning that the update check would run
again when you visit the settings screen and go back to the main page,
or return to the main page after finishing a flash.

Signed-off-by: Juan Cruz Viotti <jviottidc@gmail.com>
This commit is contained in:
Juan Cruz Viotti 2016-06-23 12:19:32 -04:00 committed by GitHub
parent 321c653d74
commit c845fe10b0

View File

@ -66,8 +66,27 @@ const app = angular.module('Etcher', [
require('./utils/byte-size/byte-size')
]);
app.run(function(AnalyticsService) {
app.run(function(AnalyticsService, UpdateNotifierService, SelectionStateModel) {
AnalyticsService.logEvent('Application start');
if (UpdateNotifierService.shouldCheckForUpdates()) {
AnalyticsService.logEvent('Checking for updates');
UpdateNotifierService.isLatestVersion().then(function(isLatestVersion) {
// In case the internet connection is not good and checking the
// latest published version takes too long, only show notify
// the user about the new version if he didn't start the flash
// process (e.g: selected an image), otherwise such interruption
// might be annoying.
if (!isLatestVersion && !SelectionStateModel.hasImage()) {
AnalyticsService.logEvent('Notifying update');
UpdateNotifierService.notify();
}
});
}
});
app.config(function($stateProvider, $urlRouterProvider) {
@ -116,24 +135,6 @@ app.controller('AppController', function(
throw error;
};
if (UpdateNotifierService.shouldCheckForUpdates()) {
AnalyticsService.logEvent('Checking for updates');
UpdateNotifierService.isLatestVersion().then(function(isLatestVersion) {
// In case the internet connection is not good and checking the
// latest published version takes too long, only show notify
// the user about the new version if he didn't start the flash
// process (e.g: selected an image), otherwise such interruption
// might be annoying.
if (!isLatestVersion && !SelectionStateModel.hasImage()) {
AnalyticsService.logEvent('Notifying update');
UpdateNotifierService.notify();
}
});
}
// This catches the case where the user enters
// the settings screen when a flash finished
// and goes back to the main screen with the back button.