From a8a75f22b2a0297c468bd4058f31eb663310703e Mon Sep 17 00:00:00 2001 From: Alexis Svinartchouk Date: Fri, 22 Jun 2018 19:56:50 +0100 Subject: [PATCH] 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 --- lib/gui/app/models/store.js | 18 ++---------------- lib/gui/app/modules/progress-status.js | 7 ++++++- lib/gui/app/os/window-progress.js | 4 +++- lib/gui/app/pages/main/templates/main.tpl.html | 4 ++-- lib/gui/modules/child-writer.js | 15 +++++++++++---- lib/shared/units.js | 2 +- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/gui/app/models/store.js b/lib/gui/app/models/store.js index f005f263..341df642 100644 --- a/lib/gui/app/models/store.js +++ b/lib/gui/app/models/store.js @@ -56,8 +56,6 @@ const verifyNoNilFields = (object, fields, name) => { * @private */ const flashStateNoNilFields = [ - 'percentage', - 'eta', 'speed', 'totalSpeed' ] @@ -94,8 +92,8 @@ const DEFAULT_STATE = Immutable.fromJS({ successful: 0, failed: 0, percentage: 0, - speed: 0, - totalSpeed: 0 + speed: null, + 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)) } diff --git a/lib/gui/app/modules/progress-status.js b/lib/gui/app/modules/progress-status.js index 57d60536..6e2dae99 100644 --- a/lib/gui/app/modules/progress-status.js +++ b/lib/gui/app/modules/progress-status.js @@ -18,6 +18,7 @@ const settings = require('../models/settings') const utils = require('../../../shared/utils') +const units = require('../../../shared/units') /** * @summary Make the progress status subtitle string @@ -58,7 +59,11 @@ exports.fromFlashState = (state) => { return 'Finishing...' } else if (isFlashing) { - return `${state.percentage}% Flashing` + if (state.percentage != null) { + return `${state.percentage}% Flashing` + } else { + return `${units.bytesToClosestUnit(state.position)} flashed` + } } else if (isValidating) { return `${state.percentage}% Validating` } else if (!isFlashing && !isValidating) { diff --git a/lib/gui/app/os/window-progress.js b/lib/gui/app/os/window-progress.js index dcc8bccf..0053cc69 100644 --- a/lib/gui/app/os/window-progress.js +++ b/lib/gui/app/os/window-progress.js @@ -90,7 +90,9 @@ exports.currentWindow = electron.remote.getCurrentWindow() * }) */ exports.set = (state) => { - exports.currentWindow.setProgressBar(utils.percentageToFloat(state.percentage)) + if (state.percentage != null) { + exports.currentWindow.setProgressBar(utils.percentageToFloat(state.percentage)) + } exports.currentWindow.setTitle(getWindowTitle(state)) } diff --git a/lib/gui/app/pages/main/templates/main.tpl.html b/lib/gui/app/pages/main/templates/main.tpl.html index 684f8a60..dd181600 100644 --- a/lib/gui/app/pages/main/templates/main.tpl.html +++ b/lib/gui/app/pages/main/templates/main.tpl.html @@ -133,9 +133,9 @@ -
diff --git a/lib/gui/modules/child-writer.js b/lib/gui/modules/child-writer.js index c358d729..a4599cad 100644 --- a/lib/gui/modules/child-writer.js +++ b/lib/gui/modules/child-writer.js @@ -108,15 +108,17 @@ function pipeRegularSourceToDestination(source, destination, verify, onProgress, flashing: destination.destinations.length, verifying: 0, failed: 0, - successful: 0 + successful: 0, + type: step } function updateState() { + state.type = step state.failed = errors.size state.active = destination.destinations.length - state.failed if (step === 'flashing') { state.flashing = state.active state.verifying = 0 - } else if (step === 'verifying') { + } else if (step === 'check') { state.flashing = 0 state.verifying = state.active } else if (step === 'finished') { @@ -128,7 +130,7 @@ function pipeRegularSourceToDestination(source, destination, verify, onProgress, progressEvent.percentage = progressEvent.position / sourceMetadata.size * 100 // NOTE: We need to guard against this becoming Infinity, // 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 Object.assign(progressEvent, state) onProgress(progressEvent) @@ -166,8 +168,13 @@ function pipeRegularSourceToDestination(source, destination, verify, onProgress, }) }) .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) { - step = 'verifying' + step = 'check' updateState() const verifier = destination.createVerifier(checksum, sourceMetadata.size) verifier.on('progress', onProgress2) diff --git a/lib/shared/units.js b/lib/shared/units.js index 16b00293..6e4f5741 100644 --- a/lib/shared/units.js +++ b/lib/shared/units.js @@ -29,7 +29,7 @@ const prettyBytes = require('pretty-bytes') * @description * 1 MB = 1e+6 B */ -const MEGABYTE_TO_BYTE_RATIO = 1e+6 +const MEGABYTE_TO_BYTE_RATIO = 1000000 /** * @summary Milliseconds in a day