mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-22 18:56:31 +00:00
refactor(utils): make PERCENTAGE_ constants public, and re-use them in flash.js (#1353)
This commit is contained in:
parent
bc01e151c4
commit
30c531417a
@ -19,6 +19,7 @@
|
|||||||
const messages = require('../../../../shared/messages');
|
const messages = require('../../../../shared/messages');
|
||||||
const settings = require('../../../models/settings');
|
const settings = require('../../../models/settings');
|
||||||
const flashState = require('../../../models/flash-state');
|
const flashState = require('../../../models/flash-state');
|
||||||
|
const utils = require('../../../../shared/utils');
|
||||||
|
|
||||||
module.exports = function(
|
module.exports = function(
|
||||||
$state,
|
$state,
|
||||||
@ -102,14 +103,12 @@ module.exports = function(
|
|||||||
this.getProgressButtonLabel = () => {
|
this.getProgressButtonLabel = () => {
|
||||||
const currentFlashState = flashState.getFlashState();
|
const currentFlashState = flashState.getFlashState();
|
||||||
const isChecking = currentFlashState.type === 'check';
|
const isChecking = currentFlashState.type === 'check';
|
||||||
const PERCENTAGE_MINIMUM = 0;
|
|
||||||
const PERCENTAGE_MAXIMUM = 100;
|
|
||||||
|
|
||||||
if (!flashState.isFlashing()) {
|
if (!flashState.isFlashing()) {
|
||||||
return 'Flash!';
|
return 'Flash!';
|
||||||
} else if (currentFlashState.percentage === PERCENTAGE_MINIMUM && !currentFlashState.speed) {
|
} else if (currentFlashState.percentage === utils.PERCENTAGE_MINIMUM && !currentFlashState.speed) {
|
||||||
return 'Starting...';
|
return 'Starting...';
|
||||||
} else if (currentFlashState.percentage === PERCENTAGE_MAXIMUM) {
|
} else if (currentFlashState.percentage === utils.PERCENTAGE_MAXIMUM) {
|
||||||
if (isChecking && settings.get('unmountOnSuccess')) {
|
if (isChecking && settings.get('unmountOnSuccess')) {
|
||||||
return 'Unmounting...';
|
return 'Unmounting...';
|
||||||
}
|
}
|
||||||
|
@ -22,18 +22,18 @@ const errors = require('./errors');
|
|||||||
/**
|
/**
|
||||||
* @summary Minimum percentage value
|
* @summary Minimum percentage value
|
||||||
* @constant
|
* @constant
|
||||||
* @private
|
* @public
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
const PERCENTAGE_MINIMUM = 0;
|
exports.PERCENTAGE_MINIMUM = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @summary Maximum percentage value
|
* @summary Maximum percentage value
|
||||||
* @constant
|
* @constant
|
||||||
* @private
|
* @public
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
const PERCENTAGE_MAXIMUM = 100;
|
exports.PERCENTAGE_MAXIMUM = 100;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @summary Check if a percentage is valid
|
* @summary Check if a percentage is valid
|
||||||
@ -51,8 +51,8 @@ const PERCENTAGE_MAXIMUM = 100;
|
|||||||
exports.isValidPercentage = (percentage) => {
|
exports.isValidPercentage = (percentage) => {
|
||||||
return _.every([
|
return _.every([
|
||||||
_.isNumber(percentage),
|
_.isNumber(percentage),
|
||||||
percentage >= PERCENTAGE_MINIMUM,
|
percentage >= exports.PERCENTAGE_MINIMUM,
|
||||||
percentage <= PERCENTAGE_MAXIMUM
|
percentage <= exports.PERCENTAGE_MAXIMUM
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -76,5 +76,5 @@ exports.percentageToFloat = (percentage) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return percentage / PERCENTAGE_MAXIMUM;
|
return percentage / exports.PERCENTAGE_MAXIMUM;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user