patch: maintain target list between flashes

This commit is contained in:
JOASSART Edwin 2024-05-08 09:32:27 +02:00 committed by Edwin Joassart
parent 73b19401c0
commit d5b186c0a5
4 changed files with 31 additions and 9 deletions

View File

@ -130,14 +130,18 @@ observe(() => {
function setDrives(drives: Dictionary<DrivelistDrive>) {
// 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<SourceMetadata>;
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<SourceMetadata> => {
emit('sourceMetadata', JSON.stringify(params));

View File

@ -122,8 +122,6 @@ async function flashImageToDrive(
errorMessage = messages.error.genericFlashError(error);
}
return errorMessage;
} finally {
availableDrives.setDrives([]);
}
return '';

View File

@ -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<EmitLog> {
startScanning();
},
stopScan: () => {
log('Stop scan requested');
stopScanning();
},
// route `cancel` from client
cancel: () => onAbort(GENERAL_ERROR),

View File

@ -172,12 +172,15 @@ const COMPUTE_MODULE_DESCRIPTIONS: Dictionary<string> = {
};
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();
};