diff --git a/lib/gui/app/app.ts b/lib/gui/app/app.ts index b6ce9f01221..5457909c984 100644 --- a/lib/gui/app/app.ts +++ b/lib/gui/app/app.ts @@ -142,25 +142,29 @@ export let requestMetadata: any; // start the api and spawn the child process spawnChildAndConnect({ withPrivileges: false, -}).then(({ emit, registerHandler }) => { - // start scanning - emit('scan', {}); - - // make the sourceMetada awaitable to be used on source selection - requestMetadata = async (params: any): Promise => { - emit('sourceMetadata', JSON.stringify(params)); - - return new Promise((resolve) => - registerHandler('sourceMetadata', (data: any) => { - resolve(JSON.parse(data)); - }), - ); - }; - - registerHandler('drives', (data: any) => { - setDrives(JSON.parse(data)); +}) + .then(({ emit, registerHandler }) => { + // start scanning + emit('scan', {}); + + // make the sourceMetada awaitable to be used on source selection + requestMetadata = async (params: any): Promise => { + emit('sourceMetadata', JSON.stringify(params)); + + return new Promise((resolve) => + registerHandler('sourceMetadata', (data: any) => { + resolve(JSON.parse(data)); + }), + ); + }; + + registerHandler('drives', (data: any) => { + setDrives(JSON.parse(data)); + }); + }) + .catch((error: any) => { + throw new Error(`Failed to start the flasher process. error: ${error}`); }); -}); let popupExists = false; diff --git a/lib/gui/app/components/source-selector/source-selector.tsx b/lib/gui/app/components/source-selector/source-selector.tsx index a32b970a595..200c7c8b674 100644 --- a/lib/gui/app/components/source-selector/source-selector.tsx +++ b/lib/gui/app/components/source-selector/source-selector.tsx @@ -423,6 +423,14 @@ export class SourceSelector extends React.Component< // this will send an event down the ipcMain asking for metadata // we'll get the response through an event + // FIXME: This is a poor man wait while loading to prevent a potential race condition without completely blocking the interface + // This should be addressed when refactoring the GUI + let retryRequestMetada = 10; + while (requestMetadata === undefined && retryRequestMetada > 0) { + await new Promise((resolve) => setTimeout(resolve, 1050)); // api is trying to connect every 1000, this is offset to make sure we fall between retries + retryRequestMetada--; + } + metadata = await requestMetadata({ selected, SourceType, auth }); if (!metadata?.hasMBR && this.state.warning === null) {