diff --git a/src/app/screen-snippet-handler.ts b/src/app/screen-snippet-handler.ts index 0759ec11..b0390a37 100644 --- a/src/app/screen-snippet-handler.ts +++ b/src/app/screen-snippet-handler.ts @@ -187,7 +187,7 @@ class ScreenSnippet { hideOnCapture, ); this.uploadSnippet(webContents, hideOnCapture); - this.closeSnippet(); + this.closeSnippet(webContents); this.copyToClipboard(); this.saveAs(); return; @@ -355,7 +355,6 @@ class ScreenSnippet { ); webContents.send('screen-snippet-data', payload); winStore.restoreWindows(hideOnCapture); - webContents.focus(); await this.verifyAndUpdateAlwaysOnTop(); } catch (error) { await this.verifyAndUpdateAlwaysOnTop(); @@ -363,6 +362,7 @@ class ScreenSnippet { `screen-snippet-handler: upload of screen capture failed with error: ${error}!`, ); } + webContents.focus(); }, ); } @@ -370,7 +370,7 @@ class ScreenSnippet { /** * Close the current snippet */ - private closeSnippet() { + private closeSnippet(webContents: WebContents) { ipcMain.once(ScreenShotAnnotation.CLOSE, async (_event) => { try { windowHandler.closeSnippingToolWindow(); @@ -381,6 +381,8 @@ class ScreenSnippet { `screen-snippet-handler: close window failed with error: ${error}!`, ); } + + webContents?.focus(); }); } diff --git a/src/app/stores/window-store.ts b/src/app/stores/window-store.ts index 228d4b44..8383c8fb 100644 --- a/src/app/stores/window-store.ts +++ b/src/app/stores/window-store.ts @@ -77,15 +77,17 @@ export class WindowStore { if (hideOnCapture) { this.restoreNotificationProperties(); const storedWindows = this.getWindowStore(); - let currentWindow = storedWindows.windows.find( + let _currentWindow = storedWindows.windows.find( (currentWindow) => currentWindow.focused, ); - if (!currentWindow) { + if (!_currentWindow) { // In case there is no window focused, we automatically focus on the main one. - currentWindow = storedWindows.windows.find( + _currentWindow = storedWindows.windows.find( (currentWindow) => currentWindow.id === 'main', ); - currentWindow!.focused = true; + if (_currentWindow) { + _currentWindow!.focused = true; + } } let focusedWindowToRestore: ICustomBrowserWindow | undefined;