From 05a838f1ed21ae25e3b999935280309fcda2080c Mon Sep 17 00:00:00 2001 From: JOASSART Edwin Date: Wed, 8 May 2024 09:32:27 +0200 Subject: [PATCH] patch: maintain target list between flashes --- lib/gui/app/app.ts | 24 ++++++++++++++++++++---- lib/gui/app/pages/main/Flash.tsx | 2 -- lib/util/api.ts | 7 ++++++- lib/util/scanner.ts | 7 +++++-- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/lib/gui/app/app.ts b/lib/gui/app/app.ts index 5457909c..59a9ce0f 100644 --- a/lib/gui/app/app.ts +++ b/lib/gui/app/app.ts @@ -130,14 +130,18 @@ observe(() => { function setDrives(drives: Dictionary) { // prevent setting drives while flashing otherwise we might lose some while we unmount them - if (!flashState.isFlashing()) { - availableDrives.setDrives(values(drives)); - } + availableDrives.setDrives(values(drives)); } // Spawning the child process without privileges to get the drives list // TODO: clean up this mess of exports -export let requestMetadata: any; +export let requestMetadata: (params: any) => Promise; +export let startScanner: () => void = () => { + console.log('stopScanner is not yet set'); +}; +export let stopScanner: () => void = () => { + console.log('stopScanner is not yet set'); +}; // start the api and spawn the child process spawnChildAndConnect({ @@ -147,6 +151,18 @@ spawnChildAndConnect({ // start scanning emit('scan', {}); + // make startScanner available for the end of flash + startScanner = () => { + console.log('startScanner'); + emit('scan', {}); + }; + + // make stopScanner available for the start of flash + stopScanner = () => { + console.log('stopScanner'); + emit('scan', {}); + }; + // make the sourceMetada awaitable to be used on source selection requestMetadata = async (params: any): Promise => { emit('sourceMetadata', JSON.stringify(params)); diff --git a/lib/gui/app/pages/main/Flash.tsx b/lib/gui/app/pages/main/Flash.tsx index 25aa4260..0e873594 100644 --- a/lib/gui/app/pages/main/Flash.tsx +++ b/lib/gui/app/pages/main/Flash.tsx @@ -122,8 +122,6 @@ async function flashImageToDrive( errorMessage = messages.error.genericFlashError(error); } return errorMessage; - } finally { - availableDrives.setDrives([]); } return ''; diff --git a/lib/util/api.ts b/lib/util/api.ts index 0fe1e402..f2ce0b88 100644 --- a/lib/util/api.ts +++ b/lib/util/api.ts @@ -24,7 +24,7 @@ import { toJSON } from '../shared/errors'; import { GENERAL_ERROR, SUCCESS } from '../shared/exit-codes'; import type { WriteOptions } from './types/types'; import { write, cleanup } from './child-writer'; -import { startScanning } from './scanner'; +import { startScanning, stopScanning } from './scanner'; import { getSourceMetadata } from './source-metadata'; import type { DrivelistDrive } from '../shared/drive-constraints'; import type { SourceMetadata } from '../shared/typings/source-selector'; @@ -222,6 +222,11 @@ function setup(): Promise { startScanning(); }, + stopScan: () => { + log('Stop scan requested'); + stopScanning(); + }, + // route `cancel` from client cancel: () => onAbort(GENERAL_ERROR), diff --git a/lib/util/scanner.ts b/lib/util/scanner.ts index 323d1ea9..5f3a57a2 100644 --- a/lib/util/scanner.ts +++ b/lib/util/scanner.ts @@ -172,12 +172,15 @@ const COMPUTE_MODULE_DESCRIPTIONS: Dictionary = { }; const startScanning = () => { - driveScanner.on('attach', (drive) => addDrive(drive)); - driveScanner.on('detach', (drive) => removeDrive(drive)); + driveScanner.on('attach', addDrive); + driveScanner.on('detach', removeDrive); driveScanner.start(); }; const stopScanning = () => { + driveScanner.removeListener('attach', addDrive); + driveScanner.removeListener('detach', removeDrive); + availableDrives = []; driveScanner.stop(); };