mirror of
https://github.com/balena-io/etcher.git
synced 2025-04-24 07:17:18 +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 settings = require('../../../models/settings');
|
||||
const flashState = require('../../../models/flash-state');
|
||||
const utils = require('../../../../shared/utils');
|
||||
|
||||
module.exports = function(
|
||||
$state,
|
||||
@ -102,14 +103,12 @@ module.exports = function(
|
||||
this.getProgressButtonLabel = () => {
|
||||
const currentFlashState = flashState.getFlashState();
|
||||
const isChecking = currentFlashState.type === 'check';
|
||||
const PERCENTAGE_MINIMUM = 0;
|
||||
const PERCENTAGE_MAXIMUM = 100;
|
||||
|
||||
if (!flashState.isFlashing()) {
|
||||
return 'Flash!';
|
||||
} else if (currentFlashState.percentage === PERCENTAGE_MINIMUM && !currentFlashState.speed) {
|
||||
} else if (currentFlashState.percentage === utils.PERCENTAGE_MINIMUM && !currentFlashState.speed) {
|
||||
return 'Starting...';
|
||||
} else if (currentFlashState.percentage === PERCENTAGE_MAXIMUM) {
|
||||
} else if (currentFlashState.percentage === utils.PERCENTAGE_MAXIMUM) {
|
||||
if (isChecking && settings.get('unmountOnSuccess')) {
|
||||
return 'Unmounting...';
|
||||
}
|
||||
|
@ -22,18 +22,18 @@ const errors = require('./errors');
|
||||
/**
|
||||
* @summary Minimum percentage value
|
||||
* @constant
|
||||
* @private
|
||||
* @public
|
||||
* @type {Number}
|
||||
*/
|
||||
const PERCENTAGE_MINIMUM = 0;
|
||||
exports.PERCENTAGE_MINIMUM = 0;
|
||||
|
||||
/**
|
||||
* @summary Maximum percentage value
|
||||
* @constant
|
||||
* @private
|
||||
* @public
|
||||
* @type {Number}
|
||||
*/
|
||||
const PERCENTAGE_MAXIMUM = 100;
|
||||
exports.PERCENTAGE_MAXIMUM = 100;
|
||||
|
||||
/**
|
||||
* @summary Check if a percentage is valid
|
||||
@ -51,8 +51,8 @@ const PERCENTAGE_MAXIMUM = 100;
|
||||
exports.isValidPercentage = (percentage) => {
|
||||
return _.every([
|
||||
_.isNumber(percentage),
|
||||
percentage >= PERCENTAGE_MINIMUM,
|
||||
percentage <= PERCENTAGE_MAXIMUM
|
||||
percentage >= exports.PERCENTAGE_MINIMUM,
|
||||
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