mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-22 02:36:32 +00:00
refactor(GUI): move drive scanner logic to application entry point (#621)
Currently, the logic the controls the drive scanner and populates the drive model lives in the main application controller. This is not optimal because: - The drive scanner stops populating the drives model when the application is not on the main screen. - An event handler subscribes to the drive scanner every time the user navigates back to the main screen. This PR moves the drive scanner logic to a run block in the entry point of the application. Signed-off-by: Juan Cruz Viotti <jviottidc@gmail.com>
This commit is contained in:
parent
1a46ac0301
commit
c31b45200d
@ -26,6 +26,7 @@ var angular = require('angular');
|
|||||||
|
|
||||||
/* eslint-enable no-var */
|
/* eslint-enable no-var */
|
||||||
|
|
||||||
|
const _ = require('lodash');
|
||||||
const Store = require('./models/store');
|
const Store = require('./models/store');
|
||||||
|
|
||||||
const app = angular.module('Etcher', [
|
const app = angular.module('Etcher', [
|
||||||
@ -36,14 +37,17 @@ const app = angular.module('Etcher', [
|
|||||||
// Etcher modules
|
// Etcher modules
|
||||||
require('./modules/analytics'),
|
require('./modules/analytics'),
|
||||||
require('./modules/error'),
|
require('./modules/error'),
|
||||||
|
require('./modules/drive-scanner'),
|
||||||
|
|
||||||
// Models
|
// Models
|
||||||
require('./models/selection-state'),
|
require('./models/selection-state'),
|
||||||
require('./models/flash-state'),
|
require('./models/flash-state'),
|
||||||
|
require('./models/drives'),
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
require('./components/svg-icon/svg-icon'),
|
require('./components/svg-icon/svg-icon'),
|
||||||
require('./components/update-notifier/update-notifier'),
|
require('./components/update-notifier/update-notifier'),
|
||||||
|
require('./components/drive-selector/drive-selector'),
|
||||||
|
|
||||||
// Pages
|
// Pages
|
||||||
require('./pages/main/main'),
|
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) => {
|
app.config(($urlRouterProvider) => {
|
||||||
$urlRouterProvider.otherwise('/main');
|
$urlRouterProvider.otherwise('/main');
|
||||||
});
|
});
|
||||||
|
@ -20,7 +20,6 @@ const _ = require('lodash');
|
|||||||
|
|
||||||
module.exports = function(
|
module.exports = function(
|
||||||
$state,
|
$state,
|
||||||
$timeout,
|
|
||||||
DriveScannerService,
|
DriveScannerService,
|
||||||
SelectionStateModel,
|
SelectionStateModel,
|
||||||
FlashStateModel,
|
FlashStateModel,
|
||||||
@ -45,25 +44,6 @@ module.exports = function(
|
|||||||
this.settings = SettingsModel;
|
this.settings = SettingsModel;
|
||||||
this.tooltipModal = TooltipModalService;
|
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 = () => {
|
this.getProgressButtonLabel = () => {
|
||||||
const flashState = this.state.getFlashState();
|
const flashState = this.state.getFlashState();
|
||||||
|
|
||||||
@ -212,7 +192,10 @@ module.exports = function(
|
|||||||
|
|
||||||
ErrorService.reportException(error);
|
ErrorService.reportException(error);
|
||||||
})
|
})
|
||||||
.finally(OSWindowProgressService.clear);
|
.finally(() => {
|
||||||
|
OSWindowProgressService.clear();
|
||||||
|
DriveScannerService.start();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user