mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-19 17:26:34 +00:00
feat: expose all flash state fields to the store (#2153)
We expose all the flash state fields to the store, and mirror `speed`'s format with `totalSpeed` with MB as the size unit. We also format the progress state messages to use information available with multiwrites. Change-Type: patch Changelog-Entry: Expose all flash state fields to the store.
This commit is contained in:
parent
b1dfbcbceb
commit
65a4a959bb
@ -182,15 +182,20 @@ app.run(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const currentFlashState = flashState.getFlashState()
|
const currentFlashState = flashState.getFlashState()
|
||||||
|
const stateType = !currentFlashState.flashing && currentFlashState.verifying
|
||||||
|
? `Verifying ${currentFlashState.verifying}`
|
||||||
|
: `Flashing ${currentFlashState.flashing}`
|
||||||
|
|
||||||
// NOTE: There is usually a short time period between the `isFlashing()`
|
// NOTE: There is usually a short time period between the `isFlashing()`
|
||||||
// property being set, and the flashing actually starting, which
|
// property being set, and the flashing actually starting, which
|
||||||
// might cause some non-sense flashing state logs including
|
// might cause some non-sense flashing state logs including
|
||||||
// `undefined` values.
|
// `undefined` values.
|
||||||
analytics.logDebug(
|
analytics.logDebug(
|
||||||
`Progress (${currentFlashState.type}): ` +
|
`${stateType} devices, ` +
|
||||||
`${currentFlashState.percentage}% at ${currentFlashState.speed} MB/s ` +
|
`${currentFlashState.percentage}% at ${currentFlashState.speed} MB/s ` +
|
||||||
`(eta ${currentFlashState.eta}s)`
|
`(total ${currentFlashState.totalSpeed} MB/s) ` +
|
||||||
|
`eta in ${currentFlashState.eta}s ` +
|
||||||
|
`with ${currentFlashState.failed} failed devices`
|
||||||
)
|
)
|
||||||
|
|
||||||
windowProgress.set(currentFlashState)
|
windowProgress.set(currentFlashState)
|
||||||
|
@ -114,36 +114,29 @@ exports.unsetFlashingFlag = (results) => {
|
|||||||
* });
|
* });
|
||||||
*/
|
*/
|
||||||
exports.setProgressState = (state) => {
|
exports.setProgressState = (state) => {
|
||||||
const {
|
// Preserve only one decimal place
|
||||||
flashing,
|
const PRECISION = 1
|
||||||
verifying,
|
const data = _.assign({}, state, {
|
||||||
succeeded,
|
percentage: _.isFinite(state.percentage)
|
||||||
failed,
|
? Math.floor(state.percentage)
|
||||||
percentage,
|
: state.percentage,
|
||||||
eta,
|
|
||||||
speed
|
|
||||||
} = state
|
|
||||||
const data = {
|
|
||||||
flashing,
|
|
||||||
verifying,
|
|
||||||
succeeded,
|
|
||||||
failed,
|
|
||||||
|
|
||||||
percentage: _.isNumber(percentage) && !_.isNaN(percentage)
|
|
||||||
? Math.floor(percentage)
|
|
||||||
: percentage,
|
|
||||||
eta,
|
|
||||||
|
|
||||||
speed: _.attempt(() => {
|
speed: _.attempt(() => {
|
||||||
if (_.isNumber(speed) && !_.isNaN(speed)) {
|
if (_.isFinite(state.speed)) {
|
||||||
// Preserve only two decimal places
|
return _.round(units.bytesToMegabytes(state.speed), PRECISION)
|
||||||
const PRECISION = 2
|
}
|
||||||
return _.round(units.bytesToMegabytes(speed), PRECISION)
|
|
||||||
|
return null
|
||||||
|
}),
|
||||||
|
|
||||||
|
totalSpeed: _.attempt(() => {
|
||||||
|
if (_.isFinite(state.totalSpeed)) {
|
||||||
|
return _.round(units.bytesToMegabytes(state.totalSpeed), PRECISION)
|
||||||
}
|
}
|
||||||
|
|
||||||
return null
|
return null
|
||||||
})
|
})
|
||||||
}
|
})
|
||||||
|
|
||||||
store.dispatch({
|
store.dispatch({
|
||||||
type: store.Actions.SET_FLASH_STATE,
|
type: store.Actions.SET_FLASH_STATE,
|
||||||
|
@ -59,7 +59,8 @@ const verifyNoNilFields = (object, fields, name) => {
|
|||||||
const flashStateNoNilFields = [
|
const flashStateNoNilFields = [
|
||||||
'percentage',
|
'percentage',
|
||||||
'eta',
|
'eta',
|
||||||
'speed'
|
'speed',
|
||||||
|
'totalSpeed'
|
||||||
]
|
]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -92,7 +93,8 @@ const DEFAULT_STATE = Immutable.fromJS({
|
|||||||
succeeded: 0,
|
succeeded: 0,
|
||||||
failed: 0,
|
failed: 0,
|
||||||
percentage: 0,
|
percentage: 0,
|
||||||
speed: 0
|
speed: 0,
|
||||||
|
totalSpeed: 0
|
||||||
},
|
},
|
||||||
settings: {
|
settings: {
|
||||||
unsafeMode: false,
|
unsafeMode: false,
|
||||||
|
@ -247,7 +247,8 @@ describe('Browser: MainPage', function () {
|
|||||||
failed: 0,
|
failed: 0,
|
||||||
percentage: 85,
|
percentage: 85,
|
||||||
eta: 15,
|
eta: 15,
|
||||||
speed: 1000
|
speed: 1000,
|
||||||
|
totalSpeed: 2000
|
||||||
})
|
})
|
||||||
m.chai.expect(controller.getProgressButtonLabel()).to.equal('85% Flashing')
|
m.chai.expect(controller.getProgressButtonLabel()).to.equal('85% Flashing')
|
||||||
})
|
})
|
||||||
|
@ -29,10 +29,15 @@ describe('Model: flashState', function () {
|
|||||||
it('should be able to reset the progress state', function () {
|
it('should be able to reset the progress state', function () {
|
||||||
flashState.setFlashingFlag()
|
flashState.setFlashingFlag()
|
||||||
flashState.setProgressState({
|
flashState.setProgressState({
|
||||||
|
flashing: 0,
|
||||||
|
verifying: 0,
|
||||||
|
succeeded: 0,
|
||||||
|
failed: 0,
|
||||||
type: 'write',
|
type: 'write',
|
||||||
percentage: 50,
|
percentage: 50,
|
||||||
eta: 15,
|
eta: 15,
|
||||||
speed: 100000000000
|
speed: 100000000000,
|
||||||
|
totalSpeed: 200000000000
|
||||||
})
|
})
|
||||||
|
|
||||||
flashState.resetState()
|
flashState.resetState()
|
||||||
@ -43,7 +48,8 @@ describe('Model: flashState', function () {
|
|||||||
succeeded: 0,
|
succeeded: 0,
|
||||||
failed: 0,
|
failed: 0,
|
||||||
percentage: 0,
|
percentage: 0,
|
||||||
speed: 0
|
speed: 0,
|
||||||
|
totalSpeed: 0
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -90,10 +96,15 @@ describe('Model: flashState', function () {
|
|||||||
|
|
||||||
m.chai.expect(function () {
|
m.chai.expect(function () {
|
||||||
flashState.setProgressState({
|
flashState.setProgressState({
|
||||||
|
flashing: 2,
|
||||||
|
verifying: 0,
|
||||||
|
succeeded: 0,
|
||||||
|
failed: 0,
|
||||||
type: 'write',
|
type: 'write',
|
||||||
percentage: 50,
|
percentage: 50,
|
||||||
eta: 15,
|
eta: 15,
|
||||||
speed: 100000000000
|
speed: 100000000000,
|
||||||
|
totalSpeed: 200000000000
|
||||||
})
|
})
|
||||||
}).to.throw('Can\'t set the flashing state when not flashing')
|
}).to.throw('Can\'t set the flashing state when not flashing')
|
||||||
})
|
})
|
||||||
@ -102,10 +113,15 @@ describe('Model: flashState', function () {
|
|||||||
flashState.setFlashingFlag()
|
flashState.setFlashingFlag()
|
||||||
m.chai.expect(function () {
|
m.chai.expect(function () {
|
||||||
flashState.setProgressState({
|
flashState.setProgressState({
|
||||||
|
flashing: 2,
|
||||||
|
verifying: 0,
|
||||||
|
succeeded: 0,
|
||||||
|
failed: 0,
|
||||||
type: 'write',
|
type: 'write',
|
||||||
percentage: 0,
|
percentage: 0,
|
||||||
eta: 15,
|
eta: 15,
|
||||||
speed: 100000000000
|
speed: 100000000000,
|
||||||
|
totalSpeed: 200000000000
|
||||||
})
|
})
|
||||||
}).to.not.throw('Missing flash fields: percentage')
|
}).to.not.throw('Missing flash fields: percentage')
|
||||||
})
|
})
|
||||||
@ -114,9 +130,14 @@ describe('Model: flashState', function () {
|
|||||||
flashState.setFlashingFlag()
|
flashState.setFlashingFlag()
|
||||||
m.chai.expect(function () {
|
m.chai.expect(function () {
|
||||||
flashState.setProgressState({
|
flashState.setProgressState({
|
||||||
|
flashing: 2,
|
||||||
|
verifying: 0,
|
||||||
|
succeeded: 0,
|
||||||
|
failed: 0,
|
||||||
type: 'write',
|
type: 'write',
|
||||||
eta: 15,
|
eta: 15,
|
||||||
speed: 100000000000
|
speed: 100000000000,
|
||||||
|
totalSpeed: 200000000000
|
||||||
})
|
})
|
||||||
}).to.throw('Missing flash fields: percentage')
|
}).to.throw('Missing flash fields: percentage')
|
||||||
})
|
})
|
||||||
@ -125,10 +146,15 @@ describe('Model: flashState', function () {
|
|||||||
flashState.setFlashingFlag()
|
flashState.setFlashingFlag()
|
||||||
m.chai.expect(function () {
|
m.chai.expect(function () {
|
||||||
flashState.setProgressState({
|
flashState.setProgressState({
|
||||||
|
flashing: 2,
|
||||||
|
verifying: 0,
|
||||||
|
succeeded: 0,
|
||||||
|
failed: 0,
|
||||||
type: 'write',
|
type: 'write',
|
||||||
percentage: '50',
|
percentage: '50',
|
||||||
eta: 15,
|
eta: 15,
|
||||||
speed: 100000000000
|
speed: 100000000000,
|
||||||
|
totalSpeed: 200000000000
|
||||||
})
|
})
|
||||||
}).to.throw('Invalid state percentage: 50')
|
}).to.throw('Invalid state percentage: 50')
|
||||||
})
|
})
|
||||||
@ -137,10 +163,15 @@ describe('Model: flashState', function () {
|
|||||||
flashState.setFlashingFlag()
|
flashState.setFlashingFlag()
|
||||||
m.chai.expect(function () {
|
m.chai.expect(function () {
|
||||||
flashState.setProgressState({
|
flashState.setProgressState({
|
||||||
|
flashing: 2,
|
||||||
|
verifying: 0,
|
||||||
|
succeeded: 0,
|
||||||
|
failed: 0,
|
||||||
type: 'write',
|
type: 'write',
|
||||||
percentage: 101,
|
percentage: 101,
|
||||||
eta: 15,
|
eta: 15,
|
||||||
speed: 0
|
speed: 0,
|
||||||
|
totalSpeed: 1
|
||||||
})
|
})
|
||||||
}).to.throw('Invalid state percentage: 101')
|
}).to.throw('Invalid state percentage: 101')
|
||||||
})
|
})
|
||||||
@ -149,10 +180,15 @@ describe('Model: flashState', function () {
|
|||||||
flashState.setFlashingFlag()
|
flashState.setFlashingFlag()
|
||||||
m.chai.expect(function () {
|
m.chai.expect(function () {
|
||||||
flashState.setProgressState({
|
flashState.setProgressState({
|
||||||
|
flashing: 2,
|
||||||
|
verifying: 0,
|
||||||
|
succeeded: 0,
|
||||||
|
failed: 0,
|
||||||
type: 'write',
|
type: 'write',
|
||||||
percentage: -1,
|
percentage: -1,
|
||||||
eta: 15,
|
eta: 15,
|
||||||
speed: 0
|
speed: 0,
|
||||||
|
totalSpeed: 1
|
||||||
})
|
})
|
||||||
}).to.throw('Invalid state percentage: -1')
|
}).to.throw('Invalid state percentage: -1')
|
||||||
})
|
})
|
||||||
@ -161,9 +197,14 @@ describe('Model: flashState', function () {
|
|||||||
flashState.setFlashingFlag()
|
flashState.setFlashingFlag()
|
||||||
m.chai.expect(function () {
|
m.chai.expect(function () {
|
||||||
flashState.setProgressState({
|
flashState.setProgressState({
|
||||||
|
flashing: 2,
|
||||||
|
verifying: 0,
|
||||||
|
succeeded: 0,
|
||||||
|
failed: 0,
|
||||||
type: 'write',
|
type: 'write',
|
||||||
percentage: 50,
|
percentage: 50,
|
||||||
speed: 100000000000
|
speed: 100000000000,
|
||||||
|
totalSpeed: 200000000000
|
||||||
})
|
})
|
||||||
}).to.throw('Missing flash fields: eta')
|
}).to.throw('Missing flash fields: eta')
|
||||||
})
|
})
|
||||||
@ -172,10 +213,15 @@ describe('Model: flashState', function () {
|
|||||||
flashState.setFlashingFlag()
|
flashState.setFlashingFlag()
|
||||||
m.chai.expect(function () {
|
m.chai.expect(function () {
|
||||||
flashState.setProgressState({
|
flashState.setProgressState({
|
||||||
|
flashing: 2,
|
||||||
|
verifying: 0,
|
||||||
|
succeeded: 0,
|
||||||
|
failed: 0,
|
||||||
type: 'write',
|
type: 'write',
|
||||||
percentage: 50,
|
percentage: 50,
|
||||||
eta: 0,
|
eta: 0,
|
||||||
speed: 100000000000
|
speed: 100000000000,
|
||||||
|
totalSpeed: 200000000000
|
||||||
})
|
})
|
||||||
}).to.not.throw('Missing flash field eta')
|
}).to.not.throw('Missing flash field eta')
|
||||||
})
|
})
|
||||||
@ -184,10 +230,15 @@ describe('Model: flashState', function () {
|
|||||||
flashState.setFlashingFlag()
|
flashState.setFlashingFlag()
|
||||||
m.chai.expect(function () {
|
m.chai.expect(function () {
|
||||||
flashState.setProgressState({
|
flashState.setProgressState({
|
||||||
|
flashing: 2,
|
||||||
|
verifying: 0,
|
||||||
|
succeeded: 0,
|
||||||
|
failed: 0,
|
||||||
type: 'write',
|
type: 'write',
|
||||||
percentage: 50,
|
percentage: 50,
|
||||||
eta: '15',
|
eta: '15',
|
||||||
speed: 100000000000
|
speed: 100000000000,
|
||||||
|
totalSpeed: 200000000000
|
||||||
})
|
})
|
||||||
}).to.throw('Invalid state eta: 15')
|
}).to.throw('Invalid state eta: 15')
|
||||||
})
|
})
|
||||||
@ -196,9 +247,14 @@ describe('Model: flashState', function () {
|
|||||||
flashState.setFlashingFlag()
|
flashState.setFlashingFlag()
|
||||||
m.chai.expect(function () {
|
m.chai.expect(function () {
|
||||||
flashState.setProgressState({
|
flashState.setProgressState({
|
||||||
|
flashing: 2,
|
||||||
|
verifying: 0,
|
||||||
|
succeeded: 0,
|
||||||
|
failed: 0,
|
||||||
type: 'write',
|
type: 'write',
|
||||||
percentage: 50,
|
percentage: 50,
|
||||||
eta: 15
|
eta: 15,
|
||||||
|
totalSpeed: 1
|
||||||
})
|
})
|
||||||
}).to.throw('Missing flash fields: speed')
|
}).to.throw('Missing flash fields: speed')
|
||||||
})
|
})
|
||||||
@ -207,21 +263,64 @@ describe('Model: flashState', function () {
|
|||||||
flashState.setFlashingFlag()
|
flashState.setFlashingFlag()
|
||||||
m.chai.expect(function () {
|
m.chai.expect(function () {
|
||||||
flashState.setProgressState({
|
flashState.setProgressState({
|
||||||
|
flashing: 2,
|
||||||
|
verifying: 0,
|
||||||
|
succeeded: 0,
|
||||||
|
failed: 0,
|
||||||
type: 'write',
|
type: 'write',
|
||||||
percentage: 50,
|
percentage: 50,
|
||||||
eta: 15,
|
eta: 15,
|
||||||
speed: 0
|
speed: 0,
|
||||||
|
totalSpeed: 1
|
||||||
})
|
})
|
||||||
}).to.not.throw('Missing flash fields: speed')
|
}).to.not.throw('Missing flash fields: speed')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should throw if totalSpeed is missing', function () {
|
||||||
|
flashState.setFlashingFlag()
|
||||||
|
m.chai.expect(function () {
|
||||||
|
flashState.setProgressState({
|
||||||
|
flashing: 2,
|
||||||
|
verifying: 0,
|
||||||
|
succeeded: 0,
|
||||||
|
failed: 0,
|
||||||
|
type: 'write',
|
||||||
|
percentage: 50,
|
||||||
|
eta: 15,
|
||||||
|
speed: 1
|
||||||
|
})
|
||||||
|
}).to.throw('Missing flash fields: totalSpeed')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should not throw if totalSpeed is 0', function () {
|
||||||
|
flashState.setFlashingFlag()
|
||||||
|
m.chai.expect(function () {
|
||||||
|
flashState.setProgressState({
|
||||||
|
flashing: 2,
|
||||||
|
verifying: 0,
|
||||||
|
succeeded: 0,
|
||||||
|
failed: 0,
|
||||||
|
type: 'write',
|
||||||
|
percentage: 50,
|
||||||
|
eta: 15,
|
||||||
|
speed: 0,
|
||||||
|
totalSpeed: 0
|
||||||
|
})
|
||||||
|
}).to.not.throw('Missing flash fields: totalSpeed')
|
||||||
|
})
|
||||||
|
|
||||||
it('should floor the percentage number', function () {
|
it('should floor the percentage number', function () {
|
||||||
flashState.setFlashingFlag()
|
flashState.setFlashingFlag()
|
||||||
flashState.setProgressState({
|
flashState.setProgressState({
|
||||||
|
flashing: 2,
|
||||||
|
verifying: 0,
|
||||||
|
succeeded: 0,
|
||||||
|
failed: 0,
|
||||||
type: 'write',
|
type: 'write',
|
||||||
percentage: 50.253559459485,
|
percentage: 50.253559459485,
|
||||||
eta: 15,
|
eta: 15,
|
||||||
speed: 0
|
speed: 0,
|
||||||
|
totalSpeed: 1
|
||||||
})
|
})
|
||||||
|
|
||||||
m.chai.expect(flashState.getFlashState().percentage).to.equal(50)
|
m.chai.expect(flashState.getFlashState().percentage).to.equal(50)
|
||||||
@ -253,7 +352,8 @@ describe('Model: flashState', function () {
|
|||||||
succeeded: 0,
|
succeeded: 0,
|
||||||
failed: 0,
|
failed: 0,
|
||||||
percentage: 0,
|
percentage: 0,
|
||||||
speed: 0
|
speed: 0,
|
||||||
|
totalSpeed: 0
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -265,7 +365,8 @@ describe('Model: flashState', function () {
|
|||||||
failed: 0,
|
failed: 0,
|
||||||
percentage: 50,
|
percentage: 50,
|
||||||
eta: 15,
|
eta: 15,
|
||||||
speed: 0
|
speed: 0,
|
||||||
|
totalSpeed: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
flashState.setFlashingFlag()
|
flashState.setFlashingFlag()
|
||||||
@ -278,7 +379,8 @@ describe('Model: flashState', function () {
|
|||||||
failed: 0,
|
failed: 0,
|
||||||
percentage: 50,
|
percentage: 50,
|
||||||
eta: 15,
|
eta: 15,
|
||||||
speed: 0
|
speed: 0,
|
||||||
|
totalSpeed: 0
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -366,19 +468,25 @@ describe('Model: flashState', function () {
|
|||||||
flashState.setFlashingFlag()
|
flashState.setFlashingFlag()
|
||||||
|
|
||||||
flashState.setProgressState({
|
flashState.setProgressState({
|
||||||
|
flashing: 2,
|
||||||
|
verifying: 0,
|
||||||
|
succeeded: 0,
|
||||||
|
failed: 0,
|
||||||
type: 'write',
|
type: 'write',
|
||||||
percentage: 50,
|
percentage: 50,
|
||||||
eta: 15,
|
eta: 15,
|
||||||
speed: 100000000000
|
speed: 100000000000,
|
||||||
|
totalSpeed: 200000000000
|
||||||
})
|
})
|
||||||
|
|
||||||
m.chai.expect(flashState.getFlashState()).to.not.deep.equal({
|
m.chai.expect(flashState.getFlashState()).to.not.deep.equal({
|
||||||
flashing: 0,
|
flashing: 2,
|
||||||
verifying: 0,
|
verifying: 0,
|
||||||
succeeded: 0,
|
succeeded: 0,
|
||||||
failed: 0,
|
failed: 0,
|
||||||
percentage: 0,
|
percentage: 0,
|
||||||
speed: 0
|
speed: 0,
|
||||||
|
totalSpeed: 0
|
||||||
})
|
})
|
||||||
|
|
||||||
flashState.unsetFlashingFlag({
|
flashState.unsetFlashingFlag({
|
||||||
@ -392,7 +500,8 @@ describe('Model: flashState', function () {
|
|||||||
succeeded: 0,
|
succeeded: 0,
|
||||||
failed: 0,
|
failed: 0,
|
||||||
percentage: 0,
|
percentage: 0,
|
||||||
speed: 0
|
speed: 0,
|
||||||
|
totalSpeed: 0
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user