Merge pull request #176 from resin-io/feat/auto-unmount-setting

Add a setting to disable auto-unmount on success
This commit is contained in:
Juan Cruz Viotti 2016-03-02 12:28:12 -04:00
commit dbb4ee6a5a
6 changed files with 28 additions and 7 deletions

View File

@ -207,7 +207,9 @@ app.controller('NavigationController', function($state) {
this.isState = $state.is; this.isState = $state.is;
}); });
app.controller('FinishController', function($state, SelectionStateService) { app.controller('FinishController', function($state, SelectionStateService, SettingsService) {
this.settings = SettingsService.data;
this.restart = function(options) { this.restart = function(options) {
SelectionStateService.clear(options); SelectionStateService.clear(options);
$state.go('main'); $state.go('main');

View File

@ -29,9 +29,12 @@ if (window.mocha) {
var writer = electron.remote.require('./src/writer'); var writer = electron.remote.require('./src/writer');
} }
const imageWriter = angular.module('Etcher.image-writer', []); require('./settings');
const imageWriter = angular.module('Etcher.image-writer', [
'Etcher.settings'
]);
imageWriter.service('ImageWriterService', function($q, $timeout) { imageWriter.service('ImageWriterService', function($q, $timeout, SettingsService) {
let self = this; let self = this;
let burning = false; let burning = false;
@ -90,7 +93,7 @@ imageWriter.service('ImageWriterService', function($q, $timeout) {
* }); * });
*/ */
this.performWrite = function(image, drive, onProgress) { this.performWrite = function(image, drive, onProgress) {
return $q.when(writer.writeImage(image, drive, onProgress)); return $q.when(writer.writeImage(image, drive, SettingsService.data, onProgress));
}; };
/** /**

View File

@ -35,7 +35,8 @@ settings.service('SettingsService', function($localStorage) {
* @public * @public
*/ */
this.data = $localStorage.$default({ this.data = $localStorage.$default({
errorReporting: true errorReporting: true,
unmountOnSuccess: true
}); });
}); });

View File

@ -7,4 +7,11 @@
<span>Enable error reporting</span> <span>Enable error reporting</span>
</label> </label>
</div> </div>
<div class="checkbox">
<label>
<input type="checkbox" ng-model="settings.storage.unmountOnSuccess">
<span>Enable auto-unmounting on success</span>
</label>
</div>
</div> </div>

View File

@ -2,7 +2,7 @@
<div class="col-xs"> <div class="col-xs">
<div class="box text-center"> <div class="box text-center">
<h3><hero-tick type="success" class="space-right-tiny"></hero-tick> Burn Complete!</h3> <h3><hero-tick type="success" class="space-right-tiny"></hero-tick> Burn Complete!</h3>
<p class="soft">Safely ejected and ready for use</p> <p ng-show="finish.settings.unmountOnSuccess" class="soft">Safely ejected and ready for use</p>
<div class="row center-xs space-vertical-large"> <div class="row center-xs space-vertical-large">
<div class="col-xs-4 space-medium"> <div class="col-xs-4 space-medium">

View File

@ -59,6 +59,8 @@ exports.getImageStream = function(image) {
* *
* @param {String} image - path to image * @param {String} image - path to image
* @param {Object} drive - drive * @param {Object} drive - drive
* @param {Object} options - options
* @param {Boolean} [options.unmountOnSuccess=false] - unmount on success
* @param {Function} onProgress - on progress callback (state) * @param {Function} onProgress - on progress callback (state)
* *
* @returns {Promise} * @returns {Promise}
@ -66,13 +68,15 @@ exports.getImageStream = function(image) {
* @example * @example
* writer.writeImage('path/to/image.img', { * writer.writeImage('path/to/image.img', {
* device: '/dev/disk2' * device: '/dev/disk2'
* }, {
* unmountOnSuccess: true
* }, function(state) { * }, function(state) {
* console.log(state.percentage); * console.log(state.percentage);
* }).then(function() { * }).then(function() {
* console.log('Done!'); * console.log('Done!');
* }); * });
*/ */
exports.writeImage = function(image, drive, onProgress) { exports.writeImage = function(image, drive, options, onProgress) {
return umount.umountAsync(drive.device).then(function() { return umount.umountAsync(drive.device).then(function() {
let stream = exports.getImageStream(image); let stream = exports.getImageStream(image);
return imageWrite.write(drive.device, stream); return imageWrite.write(drive.device, stream);
@ -83,6 +87,10 @@ exports.writeImage = function(image, drive, onProgress) {
writer.on('done', resolve); writer.on('done', resolve);
}); });
}).then(function() { }).then(function() {
if (!options.unmountOnSuccess) {
return;
}
if (isWindows && drive.mountpoint) { if (isWindows && drive.mountpoint) {
return removedrive.ejectAsync(drive.mountpoint); return removedrive.ejectAsync(drive.mountpoint);
} }