diff --git a/lib/gui/app.js b/lib/gui/app.js index e8871e6a..3fb65219 100644 --- a/lib/gui/app.js +++ b/lib/gui/app.js @@ -97,7 +97,7 @@ app.run((AnalyticsService, UpdateNotifierService, SelectionStateModel) => { app.run((AnalyticsService, OSWindowProgressService, ImageWriterService) => { Store.subscribe(() => { - const state = Store.getState().toJS(); + const flashState = ImageWriterService.getFlashState(); // There is usually a short time period between the `isFlashing()` // property being set, and the flashing actually starting, which @@ -106,17 +106,17 @@ app.run((AnalyticsService, OSWindowProgressService, ImageWriterService) => { // // We use the presence of `.eta` to determine that the actual // writing started. - if (!ImageWriterService.isFlashing() || !state.flashState.eta) { + if (!ImageWriterService.isFlashing() || !flashState.eta) { return; } AnalyticsService.log([ - `Progress (${state.flashState.type}):`, - `${state.flashState.percentage}% at ${state.flashState.speed} MB/s`, - `(eta ${state.flashState.eta}s)` + `Progress (${flashState.type}):`, + `${flashState.percentage}% at ${flashState.speed} MB/s`, + `(eta ${flashState.eta}s)` ].join(' ')); - OSWindowProgressService.set(state.flashState.percentage); + OSWindowProgressService.set(flashState.percentage); }); }); @@ -133,7 +133,6 @@ app.config(($stateProvider, $urlRouterProvider) => { app.controller('AppController', function( $state, - $scope, DriveScannerService, SelectionStateModel, SettingsModel, diff --git a/lib/gui/modules/image-writer.js b/lib/gui/modules/image-writer.js index c356a492..0f029a44 100644 --- a/lib/gui/modules/image-writer.js +++ b/lib/gui/modules/image-writer.js @@ -30,7 +30,7 @@ const imageWriter = angular.module(MODULE_NAME, [ require('../models/settings') ]); -imageWriter.service('ImageWriterService', function($q, $timeout, SettingsModel) { +imageWriter.service('ImageWriterService', function($q, $rootScope, SettingsModel) { /** * @summary Reset flash state @@ -46,25 +46,6 @@ imageWriter.service('ImageWriterService', function($q, $timeout, SettingsModel) }); }; - /** - * @summary Flash progress state - * @type Object - * @public - */ - this.state = { - percentage: 0, - speed: 0 - }; - - Store.subscribe(() => { - - // Safely bring the state to the world of Angular - $timeout(() => { - this.state = Store.getState().toJS().flashState; - }); - - }); - /** * @summary Check if currently flashing * @function @@ -179,6 +160,20 @@ imageWriter.service('ImageWriterService', function($q, $timeout, SettingsModel) return Store.getState().toJS().flashResults; }; + /** + * @summary Get the current flash state + * @function + * @public + * + * @returns {Object} flash state + * + * @example + * const flashState = ImageWriterService.getFlashState(); + */ + this.getFlashState = () => { + return Store.getState().get('flashState').toJS(); + }; + /** * @summary Perform write operation * @function @@ -239,7 +234,17 @@ imageWriter.service('ImageWriterService', function($q, $timeout, SettingsModel) this.setFlashingFlag(); - return this.performWrite(image, drive, this.setProgressState).then((results) => { + return this.performWrite(image, drive, (state) => { + + // Bring this value to the world of angular. + // If we don't trigger a digest loop, + // `.getFlashState()` will not return + // the latest updated progress state. + $rootScope.$apply(() => { + this.setProgressState(state); + }); + + }).then((results) => { // TODO: Make sure `etcher-image-write` always // sends a `cancelled` and `passedValidation` property. diff --git a/lib/gui/partials/main.html b/lib/gui/partials/main.html index 9165e25a..0e143eb0 100644 --- a/lib/gui/partials/main.html +++ b/lib/gui/partials/main.html @@ -84,19 +84,19 @@