Allow flashing from sources for which we don't know the compressed size

* don't show any percentage or eta, show the bytes written instead
This commit is contained in:
Alexis Svinartchouk 2018-06-22 19:56:50 +01:00
parent 6143023502
commit a8a75f22b2
6 changed files with 25 additions and 25 deletions

View File

@ -56,8 +56,6 @@ const verifyNoNilFields = (object, fields, name) => {
* @private * @private
*/ */
const flashStateNoNilFields = [ const flashStateNoNilFields = [
'percentage',
'eta',
'speed', 'speed',
'totalSpeed' 'totalSpeed'
] ]
@ -94,8 +92,8 @@ const DEFAULT_STATE = Immutable.fromJS({
successful: 0, successful: 0,
failed: 0, failed: 0,
percentage: 0, percentage: 0,
speed: 0, speed: null,
totalSpeed: 0 totalSpeed: null
} }
}) })
@ -255,18 +253,6 @@ const storeReducer = (state = DEFAULT_STATE, action) => {
}) })
} }
if (!utils.isValidPercentage(action.data.percentage)) {
throw errors.createError({
title: `Invalid state percentage: ${action.data.percentage}`
})
}
if (!_.isNumber(action.data.eta)) {
throw errors.createError({
title: `Invalid state eta: ${action.data.eta}`
})
}
return state.set('flashState', Immutable.fromJS(action.data)) return state.set('flashState', Immutable.fromJS(action.data))
} }

View File

@ -18,6 +18,7 @@
const settings = require('../models/settings') const settings = require('../models/settings')
const utils = require('../../../shared/utils') const utils = require('../../../shared/utils')
const units = require('../../../shared/units')
/** /**
* @summary Make the progress status subtitle string * @summary Make the progress status subtitle string
@ -58,7 +59,11 @@ exports.fromFlashState = (state) => {
return 'Finishing...' return 'Finishing...'
} else if (isFlashing) { } else if (isFlashing) {
if (state.percentage != null) {
return `${state.percentage}% Flashing` return `${state.percentage}% Flashing`
} else {
return `${units.bytesToClosestUnit(state.position)} flashed`
}
} else if (isValidating) { } else if (isValidating) {
return `${state.percentage}% Validating` return `${state.percentage}% Validating`
} else if (!isFlashing && !isValidating) { } else if (!isFlashing && !isValidating) {

View File

@ -90,7 +90,9 @@ exports.currentWindow = electron.remote.getCurrentWindow()
* }) * })
*/ */
exports.set = (state) => { exports.set = (state) => {
if (state.percentage != null) {
exports.currentWindow.setProgressBar(utils.percentageToFloat(state.percentage)) exports.currentWindow.setProgressBar(utils.percentageToFloat(state.percentage))
}
exports.currentWindow.setTitle(getWindowTitle(state)) exports.currentWindow.setTitle(getWindowTitle(state))
} }

View File

@ -133,9 +133,9 @@
<span class="glyphicon glyphicon-remove-sign"></span> <span class="glyphicon glyphicon-remove-sign"></span>
</button> </button>
<p class="step-footer step-footer-split" ng-if="main.state.getFlashState().speed && main.state.getFlashState().percentage != 100"> <p class="step-footer step-footer-split" ng-if="main.state.getFlashState().speed != null && main.state.getFlashState().percentage != 100">
<span ng-bind="main.state.getFlashState().speed.toFixed(2) + ' MB/s'"></span> <span ng-bind="main.state.getFlashState().speed.toFixed(2) + ' MB/s'"></span>
<span>ETA: {{ main.state.getFlashState().eta | secondsToDate | amDateFormat:'m[m]ss[s]' }}</span> <span ng-if="main.state.getFlashState().eta != null">ETA: {{ main.state.getFlashState().eta | secondsToDate | amDateFormat:'m[m]ss[s]' }}</span>
</p> </p>
<div class="target-status-wrap" ng-if="main.state.getFlashState().failed"> <div class="target-status-wrap" ng-if="main.state.getFlashState().failed">

View File

@ -108,15 +108,17 @@ function pipeRegularSourceToDestination(source, destination, verify, onProgress,
flashing: destination.destinations.length, flashing: destination.destinations.length,
verifying: 0, verifying: 0,
failed: 0, failed: 0,
successful: 0 successful: 0,
type: step
} }
function updateState() { function updateState() {
state.type = step
state.failed = errors.size state.failed = errors.size
state.active = destination.destinations.length - state.failed state.active = destination.destinations.length - state.failed
if (step === 'flashing') { if (step === 'flashing') {
state.flashing = state.active state.flashing = state.active
state.verifying = 0 state.verifying = 0
} else if (step === 'verifying') { } else if (step === 'check') {
state.flashing = 0 state.flashing = 0
state.verifying = state.active state.verifying = state.active
} else if (step === 'finished') { } else if (step === 'finished') {
@ -128,7 +130,7 @@ function pipeRegularSourceToDestination(source, destination, verify, onProgress,
progressEvent.percentage = progressEvent.position / sourceMetadata.size * 100 progressEvent.percentage = progressEvent.position / sourceMetadata.size * 100
// NOTE: We need to guard against this becoming Infinity, // NOTE: We need to guard against this becoming Infinity,
// because that value isn't transmitted properly over IPC and becomes `null` // because that value isn't transmitted properly over IPC and becomes `null`
progressEvent.eta = progressEvent.speed ? (sourceMetadata.size - progressEvent.position) / progressEvent.speed : 0 progressEvent.eta = progressEvent.speed ? (sourceMetadata.size - progressEvent.position) / progressEvent.speed : null
progressEvent.totalSpeed = progressEvent.speed * state.active progressEvent.totalSpeed = progressEvent.speed * state.active
Object.assign(progressEvent, state) Object.assign(progressEvent, state)
onProgress(progressEvent) onProgress(progressEvent)
@ -166,8 +168,13 @@ function pipeRegularSourceToDestination(source, destination, verify, onProgress,
}) })
}) })
.then(() => { .then(() => {
if (sourceMetadata.size == null) {
// This is needed for compressed sources for which we don't know the uncompressed size:
// After writing the image, we know the size.
sourceMetadata.size = lastPosition
}
if (verify) { if (verify) {
step = 'verifying' step = 'check'
updateState() updateState()
const verifier = destination.createVerifier(checksum, sourceMetadata.size) const verifier = destination.createVerifier(checksum, sourceMetadata.size)
verifier.on('progress', onProgress2) verifier.on('progress', onProgress2)

View File

@ -29,7 +29,7 @@ const prettyBytes = require('pretty-bytes')
* @description * @description
* 1 MB = 1e+6 B * 1 MB = 1e+6 B
*/ */
const MEGABYTE_TO_BYTE_RATIO = 1e+6 const MEGABYTE_TO_BYTE_RATIO = 1000000
/** /**
* @summary Milliseconds in a day * @summary Milliseconds in a day