diff --git a/lib/gui/app.js b/lib/gui/app.js index 7ebb4ccc..c1415aa1 100644 --- a/lib/gui/app.js +++ b/lib/gui/app.js @@ -26,6 +26,7 @@ var angular = require('angular'); /* eslint-enable no-var */ +const _ = require('lodash'); const Store = require('./models/store'); const app = angular.module('Etcher', [ @@ -36,14 +37,17 @@ const app = angular.module('Etcher', [ // Etcher modules require('./modules/analytics'), require('./modules/error'), + require('./modules/drive-scanner'), // Models require('./models/selection-state'), require('./models/flash-state'), + require('./models/drives'), // Components require('./components/svg-icon/svg-icon'), require('./components/update-notifier/update-notifier'), + require('./components/drive-selector/drive-selector'), // Pages require('./pages/main/main'), @@ -106,6 +110,26 @@ app.run((AnalyticsService, OSWindowProgressService, FlashStateModel) => { }); }); +app.run(($timeout, DriveScannerService, DrivesModel, ErrorService, DriveSelectorService) => { + DriveScannerService.on('drives', (drives) => { + + // Safely trigger a digest cycle. + // In some cases, AngularJS doesn't aknowledge that the + // available drives list has changed, and incorrectly + // keeps asking the user to "Connect a drive". + $timeout(() => { + DrivesModel.setDrives(drives); + }); + + if (_.isEmpty(drives)) { + DriveSelectorService.close(); + } + }); + + DriveScannerService.on('error', ErrorService.reportException); + DriveScannerService.start(); +}); + app.config(($urlRouterProvider) => { $urlRouterProvider.otherwise('/main'); }); diff --git a/lib/gui/pages/main/controllers/main.js b/lib/gui/pages/main/controllers/main.js index 5e983af9..cf7876b8 100644 --- a/lib/gui/pages/main/controllers/main.js +++ b/lib/gui/pages/main/controllers/main.js @@ -20,7 +20,6 @@ const _ = require('lodash'); module.exports = function( $state, - $timeout, DriveScannerService, SelectionStateModel, FlashStateModel, @@ -45,25 +44,6 @@ module.exports = function( this.settings = SettingsModel; this.tooltipModal = TooltipModalService; - DriveScannerService.start(); - - DriveScannerService.on('error', ErrorService.reportException); - - DriveScannerService.on('drives', (drives) => { - - // Safely trigger a digest cycle. - // In some cases, AngularJS doesn't aknowledge that the - // available drives list has changed, and incorrectly - // keeps asking the user to "Connect a drive". - $timeout(() => { - this.drives.setDrives(drives); - }); - - if (_.isEmpty(drives)) { - DriveSelectorService.close(); - } - }); - this.getProgressButtonLabel = () => { const flashState = this.state.getFlashState(); @@ -212,7 +192,10 @@ module.exports = function( ErrorService.reportException(error); }) - .finally(OSWindowProgressService.clear); + .finally(() => { + OSWindowProgressService.clear(); + DriveScannerService.start(); + }); }; };