diff --git a/src/automations/commander.ts b/src/automations/commander.ts index 709a4ce..4f7ff3a 100644 --- a/src/automations/commander.ts +++ b/src/automations/commander.ts @@ -29,6 +29,7 @@ export default class Commander { // close stuff await window.closeWaitingPanel(); + await window.restoreWindows(); await window.releaseFocus(); // record @@ -154,12 +155,16 @@ export default class Commander { // done await window.closeWaitingPanel(); + await window.restoreWindows(); await window.releaseFocus(); // now paste console.debug(`Processing LLM output: ${result.response.slice(0, 50)}…`); await this.finishCommand(command, result.response, engine, model); + // done + return result; + } } catch (error) { @@ -167,9 +172,9 @@ export default class Commander { } // done waiting - console.log('Destroying waiting panel') await window.closeWaitingPanel(true); - window.releaseFocus(); + await window.restoreWindows(); + await window.releaseFocus(); // done return result; @@ -190,6 +195,9 @@ export default class Commander { private finishCommand = async (command: Command, text: string, engine: string, model: string): Promise => { + // log + console.log('Finishing command', command, text, engine, model); + // we need an automator const automator = new Automator(); diff --git a/src/main.ts b/src/main.ts index acd1b39..fde0700 100644 --- a/src/main.ts +++ b/src/main.ts @@ -297,8 +297,9 @@ ipcMain.on('get-command-prompt', (event, payload) => { }) ipcMain.on('close-command-palette', async () => { - window.closeCommandPalette(); - window.restoreWindows(); + await window.closeCommandPalette(); + await window.restoreWindows(); + await window.releaseFocus(); }); ipcMain.on('run-command', async (event, payload) => { @@ -319,7 +320,6 @@ ipcMain.on('run-command', async (event, payload) => { commander = null; // cancelled - window.restoreWindows(); if (result.cancelled) return; // show chat window @@ -343,10 +343,6 @@ ipcMain.on('stop-command', async () => { commander = null; } - // restore windows - await window.restoreWindows(); - await window.releaseFocus(); - }); ipcMain.on('run-python-code', async (event, payload) => { diff --git a/src/main/window.ts b/src/main/window.ts index 67fa660..0d0b2a7 100644 --- a/src/main/window.ts +++ b/src/main/window.ts @@ -202,28 +202,30 @@ export const hideWindows = async () => { } export const restoreWindows = () => { - if (windowsToRestore.length) { - console.log(`Restoring ${windowsToRestore.length} windows`) - - // restore main window first - windowsToRestore.sort((a, b) => { - if (a === mainWindow) return -1; - if (b === mainWindow) return 1; - return 0; - }) - - // now restore - for (const window of windowsToRestore) { - try { - window.showInactive(); - } catch (error) { - console.error('Error while restoring window', error); - } - } - // done - windowsToRestore = []; + // log + console.log(`Restoring ${windowsToRestore.length} windows`) + + // restore main window first + windowsToRestore.sort((a, b) => { + if (a === mainWindow) return -1; + if (b === mainWindow) return 1; + return 0; + }) + + // now restore + for (const window of windowsToRestore) { + try { + window.restore(); + //window.showInactive(); + } catch (error) { + console.error('Error while restoring window', error); + } } + + // done + windowsToRestore = []; + }; let commandPalette: BrowserWindow = null; @@ -277,6 +279,7 @@ export const closeWaitingPanel = async (destroy?: boolean) => { if (waitingPanel && !waitingPanel.isDestroyed()) { if (destroy) waitingPanel?.destroy() else waitingPanel?.close() + waitingPanel = null; await wait(); } } catch (error) {