Skip to content

Commit

Permalink
SDA-4207 Snipping tool being closed in case it was existing before pe…
Browse files Browse the repository at this point in the history
…rsisting existing windows and capturing the screen
  • Loading branch information
sbenmoussati committed Jun 27, 2023
1 parent b63b44b commit b719002
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 51 deletions.
89 changes: 44 additions & 45 deletions src/app/screen-snippet-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
});
};

/**
Expand Down
4 changes: 0 additions & 4 deletions src/app/stores/window-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export interface IWindowState {
focused?: boolean;
isFullScreen?: boolean;
isVisible?: boolean;
isAlwaysOnTop?: boolean;
}

export class WindowStore {
Expand Down Expand Up @@ -104,9 +103,6 @@ export class WindowStore {
focusedWindowToRestore = window;
}
}
if (currentWindow && currentWindow.isAlwaysOnTop) {
window.setAlwaysOnTop(true);
}
}
});

Expand Down
1 change: 1 addition & 0 deletions src/app/window-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
8 changes: 6 additions & 2 deletions src/app/window-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions src/app/window-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,9 @@ export const didVerifyAndRestoreWindow = (
if (browserWindow.isMinimized()) {
browserWindow.restore();
}
if (!browserWindow.isVisible()) {
browserWindow.show();
}
browserWindow.focus();
return true;
};
Expand Down
1 change: 1 addition & 0 deletions src/common/api-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit b719002

Please sign in to comment.