From b7190024e0df4af2d07e7f2ae2160b620238605b Mon Sep 17 00:00:00 2001 From: sbenmoussati <51402489+sbenmoussati@users.noreply.github.com> Date: Fri, 9 Jun 2023 11:30:39 +0200 Subject: [PATCH] SDA-4207 Snipping tool being closed in case it was existing before persisting existing windows and capturing the screen --- src/app/screen-snippet-handler.ts | 89 +++++++++++++++---------------- src/app/stores/window-store.ts | 4 -- src/app/window-actions.ts | 1 + src/app/window-handler.ts | 8 ++- src/app/window-utils.ts | 3 ++ src/common/api-interface.ts | 1 + 6 files changed, 55 insertions(+), 51 deletions(-) diff --git a/src/app/screen-snippet-handler.ts b/src/app/screen-snippet-handler.ts index 0fbc17d46..0af21ddc2 100644 --- a/src/app/screen-snippet-handler.ts +++ b/src/app/screen-snippet-handler.ts @@ -95,7 +95,7 @@ class ScreenSnippet { const currentWindowName = (currentWindowObj as ICustomBrowserWindow) ?.winName; const mainWindow = windowHandler.getMainWindow(); - + windowHandler.closeSnippingToolWindow(); if (hideOnCapture) { this.storeWindowsState(mainWindow, currentWindowObj); winStore.hideWindowsOnCapturing(hideOnCapture); @@ -465,55 +465,54 @@ class ScreenSnippet { const windowObj = winStore.getWindowStore(); const currentWindowName = (currentWindowObj as ICustomBrowserWindow) ?.winName; - if (windowObj.windows.length < 1) { - const allWindows = BrowserWindow.getAllWindows(); - let windowsArr: IWindowState[] = []; - const mainArr: IWindowState[] = [ - { - id: 'main', - focused: mainWindow?.isFocused(), - minimized: mainWindow?.isMinimized(), - isFullScreen: mainWindow?.isFullScreen(), - isVisible: mainWindow?.isVisible(), - isAlwaysOnTop: mainWindow?.isAlwaysOnTop(), - }, - ]; - - allWindows.forEach((window) => { - if ( - (window as ICustomBrowserWindow).winName !== currentWindowName && - (window as ICustomBrowserWindow).winName !== 'main' && - (window as ICustomBrowserWindow).winName !== - apiName.notificationWindowName - ) { - windowsArr.push({ - id: (window as ICustomBrowserWindow).winName, - focused: window.isFocused(), - minimized: window?.isMinimized(), - isFullScreen: window?.isFullScreen(), - isVisible: window?.isVisible(), - isAlwaysOnTop: window?.isAlwaysOnTop(), - }); - } - }); - - if (currentWindowName !== 'main') { + if (windowObj.windows.length > 0) { + winStore.destroyWindowStore(); + } + const allWindows = BrowserWindow.getAllWindows(); + let windowsArr: IWindowState[] = []; + const mainArr: IWindowState[] = [ + { + id: 'main', + focused: mainWindow?.isFocused(), + minimized: mainWindow?.isMinimized(), + isFullScreen: mainWindow?.isFullScreen(), + isVisible: mainWindow?.isVisible(), + }, + ]; + + allWindows.forEach((window) => { + if ( + (window as ICustomBrowserWindow).winName && + (window as ICustomBrowserWindow).winName !== currentWindowName && + (window as ICustomBrowserWindow).winName !== 'main' && + (window as ICustomBrowserWindow).winName !== + apiName.notificationWindowName + ) { windowsArr.push({ - id: currentWindowName, - focused: currentWindowObj?.isFocused(), - minimized: currentWindowObj?.isMinimized(), - isFullScreen: currentWindowObj?.isFullScreen(), - isVisible: currentWindowObj?.isVisible(), - isAlwaysOnTop: currentWindowObj?.isAlwaysOnTop(), + id: (window as ICustomBrowserWindow).winName, + focused: window.isFocused(), + minimized: window?.isMinimized(), + isFullScreen: window?.isFullScreen(), + isVisible: window?.isVisible(), }); - windowsArr = mainArr.concat(windowsArr); - } else { - windowsArr = windowsArr.concat(mainArr); } - winStore.setWindowStore({ - windows: windowsArr, + }); + + if (currentWindowName !== 'main') { + windowsArr.push({ + id: currentWindowName, + focused: currentWindowObj?.isFocused(), + minimized: currentWindowObj?.isMinimized(), + isFullScreen: currentWindowObj?.isFullScreen(), + isVisible: currentWindowObj?.isVisible(), }); + windowsArr = mainArr.concat(windowsArr); + } else { + windowsArr = windowsArr.concat(mainArr); } + winStore.setWindowStore({ + windows: windowsArr, + }); }; /** diff --git a/src/app/stores/window-store.ts b/src/app/stores/window-store.ts index 87ac13fbf..5a90451ad 100644 --- a/src/app/stores/window-store.ts +++ b/src/app/stores/window-store.ts @@ -17,7 +17,6 @@ export interface IWindowState { focused?: boolean; isFullScreen?: boolean; isVisible?: boolean; - isAlwaysOnTop?: boolean; } export class WindowStore { @@ -104,9 +103,6 @@ export class WindowStore { focusedWindowToRestore = window; } } - if (currentWindow && currentWindow.isAlwaysOnTop) { - window.setAlwaysOnTop(true); - } } }); diff --git a/src/app/window-actions.ts b/src/app/window-actions.ts index 9104241ce..2949f6d16 100644 --- a/src/app/window-actions.ts +++ b/src/app/window-actions.ts @@ -229,6 +229,7 @@ export const updateAlwaysOnTop = async ( } if (browserWins.length > 0) { browserWins + .filter((browser) => browser && windowExists(browser)) .filter((browser) => typeof browser.notificationData !== 'object') .forEach((browser) => browser.setAlwaysOnTop(shouldSetAlwaysOnTop)); diff --git a/src/app/window-handler.ts b/src/app/window-handler.ts index b50379ab8..502401594 100644 --- a/src/app/window-handler.ts +++ b/src/app/window-handler.ts @@ -170,7 +170,7 @@ export class WindowHandler { private screenSharingFrameWindow: Electron.BrowserWindow | null = null; private basicAuthWindow: Electron.BrowserWindow | null = null; private notificationSettingsWindow: Electron.BrowserWindow | null = null; - private snippingToolWindow: Electron.BrowserWindow | null = null; + private snippingToolWindow: ICustomBrowserWindow | null = null; private finishedLoading: boolean = false; private readonly opts: Electron.BrowserViewConstructorOptions | undefined; private hideOnCapture: boolean = false; @@ -1364,7 +1364,11 @@ export class WindowHandler { opts.modal = true; } - this.snippingToolWindow = createComponentWindow('snipping-tool', opts); + this.snippingToolWindow = createComponentWindow( + 'snipping-tool', + opts, + ) as ICustomBrowserWindow; + this.snippingToolWindow.winName = apiName.snippingToolWindowName; this.moveWindow(this.snippingToolWindow, undefined, parentWindow); this.snippingToolWindow.setVisibleOnAllWorkspaces(true); diff --git a/src/app/window-utils.ts b/src/app/window-utils.ts index e2c5f460a..69902c437 100644 --- a/src/app/window-utils.ts +++ b/src/app/window-utils.ts @@ -1007,6 +1007,9 @@ export const didVerifyAndRestoreWindow = ( if (browserWindow.isMinimized()) { browserWindow.restore(); } + if (!browserWindow.isVisible()) { + browserWindow.show(); + } browserWindow.focus(); return true; }; diff --git a/src/common/api-interface.ts b/src/common/api-interface.ts index bb7cf9b96..09571f04d 100644 --- a/src/common/api-interface.ts +++ b/src/common/api-interface.ts @@ -83,6 +83,7 @@ export enum apiName { mainWindowName = 'main', notificationWindowName = 'notification-window', welcomeScreenName = 'welcome-screen', + snippingToolWindowName = 'snipping-tool-window', } export const NOTIFICATION_WINDOW_TITLE = 'Notification - Symphony';