Disable screensaver while flashing (on balena-electron-env)

Change-type: patch
This commit is contained in:
Alexis Svinartchouk 2020-12-21 18:32:42 +01:00
parent 1dc56aed14
commit 93db90c725
2 changed files with 11 additions and 3 deletions

View File

@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
import * as electron from 'electron';
import * as sdk from 'etcher-sdk'; import * as sdk from 'etcher-sdk';
import * as _ from 'lodash'; import * as _ from 'lodash';
@ -45,6 +46,8 @@ export function isFlashing(): boolean {
* start a flash process. * start a flash process.
*/ */
export function setFlashingFlag() { export function setFlashingFlag() {
// see https://github.com/balenablocks/balena-electron-env/blob/4fce9c461f294d4a768db8f247eea6f75d7b08b0/README.md#remote-methods
electron.ipcRenderer.send('disable-screensaver');
store.dispatch({ store.dispatch({
type: Actions.SET_FLASHING_FLAG, type: Actions.SET_FLASHING_FLAG,
data: {}, data: {},
@ -66,6 +69,8 @@ export function unsetFlashingFlag(results: {
type: Actions.UNSET_FLASHING_FLAG, type: Actions.UNSET_FLASHING_FLAG,
data: results, data: results,
}); });
// see https://github.com/balenablocks/balena-electron-env/blob/4fce9c461f294d4a768db8f247eea6f75d7b08b0/README.md#remote-methods
electron.ipcRenderer.send('enable-screensaver');
} }
export function setDevicePaths(devicePaths: string[]) { export function setDevicePaths(devicePaths: string[]) {

View File

@ -272,7 +272,7 @@ export async function flash(
throw new Error('There is already a flash in progress'); throw new Error('There is already a flash in progress');
} }
flashState.setFlashingFlag(); await flashState.setFlashingFlag();
flashState.setDevicePaths( flashState.setDevicePaths(
drives.map((d) => d.devicePath).filter((p) => p != null) as string[], drives.map((d) => d.devicePath).filter((p) => p != null) as string[],
); );
@ -290,9 +290,12 @@ export async function flash(
try { try {
const result = await write(image, drives, flashState.setProgressState); const result = await write(image, drives, flashState.setProgressState);
flashState.unsetFlashingFlag(result); await flashState.unsetFlashingFlag(result);
} catch (error) { } catch (error) {
flashState.unsetFlashingFlag({ cancelled: false, errorCode: error.code }); await flashState.unsetFlashingFlag({
cancelled: false,
errorCode: error.code,
});
windowProgress.clear(); windowProgress.clear();
const { results = {} } = flashState.getFlashResults(); const { results = {} } = flashState.getFlashResults();
const eventData = { const eventData = {