Autoselect a single drive by using DriveScanner scan event

- The autoselection only happens once the user has selected an image to
prevent weird behaviour.

- The autoselection happens only if the current selected drive is
different from the new drive in order to avoid selecting the same driver
over and over again if it still is the only one.
This commit is contained in:
Juan Cruz Viotti 2016-01-18 13:39:07 -04:00
parent f218cc1b59
commit 9ffc642784
2 changed files with 38 additions and 8 deletions

View File

@ -20,6 +20,7 @@
*/
var angular = require('angular');
var _ = require('lodash');
var remote = window.require('remote');
var shell = remote.require('shell');
var dialog = remote.require('./src/dialog');
@ -52,12 +53,26 @@ app.controller('AppController', function($q, DriveScannerService, SelectionState
console.debug('Restarting');
this.selection.clear();
this.writer.setProgress(0);
this.scanner.start(2000);
this.scanner.start(2000).on('scan', function(drives) {
this.scanner.scan().then(function (res) {
if(res.length === 1){
self.selectDrive(res[0]);
// Notice we only autoselect the drive if there is an image,
// which means that the first step was completed successfully,
// otherwise the drive is selected while the drive step is disabled
// which looks very weird.
if (drives.length === 1 && self.selection.hasImage()) {
var drive = _.first(drives);
// Do not autoselect the same drive over and over again
// and fill the logs unnecessary.
// `angular.equals` is used instead of `_.isEqual` to
// cope with `$$hashKey`.
if (!angular.equals(self.selection.getDrive(), drive)) {
console.debug('Autoselecting drive: ' + drive.device);
self.selectDrive(drive);
}
}
});
};

View File

@ -19,6 +19,7 @@
*/
var angular = require('angular');
var _ = require('lodash');
var remote = window.require('remote');
var shell = remote.require('shell');
var dialog = remote.require('./src/dialog');
@ -51,12 +52,26 @@ app.controller('AppController', function($q, DriveScannerService, SelectionState
console.debug('Restarting');
this.selection.clear();
this.writer.setProgress(0);
this.scanner.start(2000);
this.scanner.start(2000).on('scan', function(drives) {
this.scanner.scan().then(function (res) {
if(res.length === 1){
self.selectDrive(res[0]);
// Notice we only autoselect the drive if there is an image,
// which means that the first step was completed successfully,
// otherwise the drive is selected while the drive step is disabled
// which looks very weird.
if (drives.length === 1 && self.selection.hasImage()) {
var drive = _.first(drives);
// Do not autoselect the same drive over and over again
// and fill the logs unnecessary.
// `angular.equals` is used instead of `_.isEqual` to
// cope with `$$hashKey`.
if (!angular.equals(self.selection.getDrive(), drive)) {
console.debug('Autoselecting drive: ' + drive.device);
self.selectDrive(drive);
}
}
});
};