mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-27 21:26:38 +00:00
Make setProgress accept an options object
This allows us to pass more things than just the percentage to `setProgress`.
This commit is contained in:
parent
e30de45707
commit
a46a716512
@ -359,16 +359,19 @@ imageWriter.service('ImageWriterService', function($q, $timeout) {
|
|||||||
* @function
|
* @function
|
||||||
* @private
|
* @private
|
||||||
*
|
*
|
||||||
* @param {Number} progress
|
* @param {Object} state - progress state
|
||||||
|
* @param {Number} state.percentage - progress percentage
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ImageWriterService.setProgress(50);
|
* ImageWriterService.setProgress({
|
||||||
|
* percentage: 50
|
||||||
|
* });
|
||||||
*/
|
*/
|
||||||
this.setProgress = function(progress) {
|
this.setProgress = function(state) {
|
||||||
|
|
||||||
// Safely bring the state to the world of Angular
|
// Safely bring the state to the world of Angular
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
self.state.progress = Math.floor(progress);
|
self.state.progress = Math.floor(state.percentage);
|
||||||
console.debug('Progress: ' + self.state.progress);
|
console.debug('Progress: ' + self.state.progress);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -383,7 +386,9 @@ imageWriter.service('ImageWriterService', function($q, $timeout) {
|
|||||||
* ImageWriterService.reset();
|
* ImageWriterService.reset();
|
||||||
*/
|
*/
|
||||||
this.reset = function() {
|
this.reset = function() {
|
||||||
self.setProgress(0);
|
self.setProgress({
|
||||||
|
percentage: 0
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -470,9 +475,7 @@ imageWriter.service('ImageWriterService', function($q, $timeout) {
|
|||||||
|
|
||||||
self.setBurning(true);
|
self.setBurning(true);
|
||||||
|
|
||||||
return self.performWrite(image, drive, function(state) {
|
return self.performWrite(image, drive, self.setProgress).finally(function() {
|
||||||
self.setProgress(state.percentage);
|
|
||||||
}).finally(function() {
|
|
||||||
self.setBurning(false);
|
self.setBurning(false);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -51,16 +51,19 @@ imageWriter.service('ImageWriterService', function($q, $timeout) {
|
|||||||
* @function
|
* @function
|
||||||
* @private
|
* @private
|
||||||
*
|
*
|
||||||
* @param {Number} progress
|
* @param {Object} state - progress state
|
||||||
|
* @param {Number} state.percentage - progress percentage
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ImageWriterService.setProgress(50);
|
* ImageWriterService.setProgress({
|
||||||
|
* percentage: 50
|
||||||
|
* });
|
||||||
*/
|
*/
|
||||||
this.setProgress = function(progress) {
|
this.setProgress = function(state) {
|
||||||
|
|
||||||
// Safely bring the state to the world of Angular
|
// Safely bring the state to the world of Angular
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
self.state.progress = Math.floor(progress);
|
self.state.progress = Math.floor(state.percentage);
|
||||||
console.debug('Progress: ' + self.state.progress);
|
console.debug('Progress: ' + self.state.progress);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -75,7 +78,9 @@ imageWriter.service('ImageWriterService', function($q, $timeout) {
|
|||||||
* ImageWriterService.reset();
|
* ImageWriterService.reset();
|
||||||
*/
|
*/
|
||||||
this.reset = function() {
|
this.reset = function() {
|
||||||
self.setProgress(0);
|
self.setProgress({
|
||||||
|
percentage: 0
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -162,9 +167,7 @@ imageWriter.service('ImageWriterService', function($q, $timeout) {
|
|||||||
|
|
||||||
self.setBurning(true);
|
self.setBurning(true);
|
||||||
|
|
||||||
return self.performWrite(image, drive, function(state) {
|
return self.performWrite(image, drive, self.setProgress).finally(function() {
|
||||||
self.setProgress(state.percentage);
|
|
||||||
}).finally(function() {
|
|
||||||
self.setBurning(false);
|
self.setBurning(false);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -64,13 +64,19 @@ describe('Browser: ImageWriter', function() {
|
|||||||
describe('.setProgress()', function() {
|
describe('.setProgress()', function() {
|
||||||
|
|
||||||
it('should be able to set the progress', function() {
|
it('should be able to set the progress', function() {
|
||||||
ImageWriterService.setProgress(50);
|
ImageWriterService.setProgress({
|
||||||
|
percentage: 50
|
||||||
|
});
|
||||||
|
|
||||||
$timeout.flush();
|
$timeout.flush();
|
||||||
m.chai.expect(ImageWriterService.state.progress).to.equal(50);
|
m.chai.expect(ImageWriterService.state.progress).to.equal(50);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should floor the percentage', function() {
|
it('should floor the percentage', function() {
|
||||||
ImageWriterService.setProgress(49.9999);
|
ImageWriterService.setProgress({
|
||||||
|
percentage: 49.9999
|
||||||
|
});
|
||||||
|
|
||||||
$timeout.flush();
|
$timeout.flush();
|
||||||
m.chai.expect(ImageWriterService.state.progress).to.equal(49);
|
m.chai.expect(ImageWriterService.state.progress).to.equal(49);
|
||||||
});
|
});
|
||||||
@ -80,7 +86,10 @@ describe('Browser: ImageWriter', function() {
|
|||||||
describe('.reset()', function() {
|
describe('.reset()', function() {
|
||||||
|
|
||||||
it('should reset progress percentage to 0', function() {
|
it('should reset progress percentage to 0', function() {
|
||||||
ImageWriterService.setProgress(50);
|
ImageWriterService.setProgress({
|
||||||
|
percentage: 50
|
||||||
|
});
|
||||||
|
|
||||||
$timeout.flush();
|
$timeout.flush();
|
||||||
m.chai.expect(ImageWriterService.state.progress).to.equal(50);
|
m.chai.expect(ImageWriterService.state.progress).to.equal(50);
|
||||||
ImageWriterService.reset();
|
ImageWriterService.reset();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user