Merge pull request #235 from resin-io/refactor/decouple-drive-scanner-from-dialog

Decouple DriveScannerService from Dialog
This commit is contained in:
Juan Cruz Viotti 2016-04-01 10:51:58 -04:00
commit 5642eb2e0a
2 changed files with 4 additions and 11 deletions

View File

@ -118,7 +118,7 @@ app.controller('AppController', function(
WindowProgressService.set(state.progress); WindowProgressService.set(state.progress);
}); });
this.scanner.start(2000).on('scan', function(drives) { this.scanner.start(2000).on('error', dialog.showError).on('scan', function(drives) {
// Notice we only autoselect the drive if there is an image, // Notice we only autoselect the drive if there is an image,
// which means that the first step was completed successfully, // which means that the first step was completed successfully,

View File

@ -23,17 +23,8 @@
const angular = require('angular'); const angular = require('angular');
const _ = require('lodash'); const _ = require('lodash');
const EventEmitter = require('events').EventEmitter; const EventEmitter = require('events').EventEmitter;
const electron = require('electron');
const drivelist = require('drivelist'); const drivelist = require('drivelist');
if (window.mocha) {
var path = require('path');
var srcPath = path.join(__dirname, '..', '..', 'src');
var dialog = electron.remote.require(path.join(srcPath, 'dialog'));
} else {
var dialog = electron.remote.require('./src/dialog');
}
const driveScanner = angular.module('Etcher.drive-scanner', []); const driveScanner = angular.module('Etcher.drive-scanner', []);
driveScanner.service('DriveScannerService', function($q, $interval, $timeout) { driveScanner.service('DriveScannerService', function($q, $interval, $timeout) {
@ -141,7 +132,9 @@ driveScanner.service('DriveScannerService', function($q, $interval, $timeout) {
return self.scan().then(function(drives) { return self.scan().then(function(drives) {
emitter.emit('scan', drives); emitter.emit('scan', drives);
self.setDrives(drives); self.setDrives(drives);
}).catch(dialog.showError); }).catch(function(error) {
emitter.emit('error', error);
});
}; };
// Make sure any pending interval is cancelled // Make sure any pending interval is cancelled