SDA-1661 - Make about app window a modal window and optimize code (#843)

This commit is contained in:
Kiran Niranjan 2020-01-08 17:19:06 +05:30 committed by Vishwas Shashidhar
parent a9fc026df9
commit c63a2682e3
2 changed files with 39 additions and 32 deletions

View File

@ -21,7 +21,8 @@ import { versionHandler } from './version-handler';
import { handlePermissionRequests, monitorWindowActions } from './window-actions'; import { handlePermissionRequests, monitorWindowActions } from './window-actions';
import { import {
createComponentWindow, createComponentWindow,
getBounds, didVerifyAndRestoreWindow,
getBounds, getWindowByName,
handleCertificateProxyVerification, handleCertificateProxyVerification,
handleDownloadManager, handleDownloadManager,
injectStyles, injectStyles,
@ -476,24 +477,16 @@ export class WindowHandler {
// This prevents creating multiple instances of the // This prevents creating multiple instances of the
// about window // about window
if (this.aboutAppWindow && windowExists(this.aboutAppWindow)) { if (didVerifyAndRestoreWindow(this.aboutAppWindow)) {
if (this.aboutAppWindow.isMinimized()) {
this.aboutAppWindow.restore();
}
this.aboutAppWindow.focus();
return; return;
} }
const allWindows = BrowserWindow.getAllWindows(); const selectedParentWindow = getWindowByName(windowName);
const selectedParentWindow = allWindows.find((window) => {
return (window as ICustomBrowserWindow).winName === windowName;
});
const opts: BrowserWindowConstructorOptions = this.getWindowOpts({ const opts: BrowserWindowConstructorOptions = this.getWindowOpts({
width: 550, width: 550,
height: isWindowsOS ? 745 : 705, height: isWindowsOS ? 745 : 705,
modal: false, modal: true,
alwaysOnTop: isMac, alwaysOnTop: isMac,
resizable: false, resizable: false,
}, { }, {
@ -671,17 +664,10 @@ export class WindowHandler {
}); });
// This prevents creating multiple instances of the // This prevents creating multiple instances of the
// notification configuration window // notification configuration window
if (this.notificationSettingsWindow && !this.notificationSettingsWindow.isDestroyed()) { if (didVerifyAndRestoreWindow(this.notificationSettingsWindow)) {
if (this.notificationSettingsWindow.isMinimized()) {
this.notificationSettingsWindow.restore();
}
this.notificationSettingsWindow.focus();
return; return;
} }
const allWindows = BrowserWindow.getAllWindows(); const selectedParentWindow = getWindowByName(windowName);
const selectedParentWindow = allWindows.find((window) => {
return (window as ICustomBrowserWindow).winName === windowName;
});
if (selectedParentWindow) { if (selectedParentWindow) {
opts.parent = selectedParentWindow; opts.parent = selectedParentWindow;
@ -785,7 +771,7 @@ export class WindowHandler {
const winY: string = element.bounds.y.toString(); const winY: string = element.bounds.y.toString();
this.execCmd(this.screenShareIndicatorFrameUtil, [ winX, winY ]); this.execCmd(this.screenShareIndicatorFrameUtil, [ winX, winY ]);
} else { } else {
this.createScrenSharingFrameWindow('screen-sharing-frame', this.createScreenSharingFrameWindow('screen-sharing-frame',
element.workArea.width, element.workArea.width,
element.workArea.height, element.workArea.height,
element.workArea.x, element.workArea.x,
@ -822,22 +808,15 @@ export class WindowHandler {
/** /**
* Creates a screen-sharing frame around the shared area * Creates a screen-sharing frame around the shared area
*/ */
public createScrenSharingFrameWindow(windowName: string, frameWidth: number, frameHeight: number, framePositionX: number, framePositionY: number): void { public createScreenSharingFrameWindow(windowName: string, frameWidth: number, frameHeight: number, framePositionX: number, framePositionY: number): void {
// This prevents creating multiple instances of the // This prevents creating multiple instances of the
// about window // about window
if (this.screenSharingFrameWindow && windowExists(this.screenSharingFrameWindow)) { if (didVerifyAndRestoreWindow(this.screenSharingFrameWindow)) {
if (this.screenSharingFrameWindow.isMinimized()) {
this.screenSharingFrameWindow.restore();
}
this.screenSharingFrameWindow.focus();
return; return;
} }
const allWindows = BrowserWindow.getAllWindows(); const selectedParentWindow = getWindowByName(windowName);
const selectedParentWindow = allWindows.find((window) => {
return (window as ICustomBrowserWindow).winName === windowName;
});
const opts: BrowserWindowConstructorOptions = this.getWindowOpts({ const opts: BrowserWindowConstructorOptions = this.getWindowOpts({
width: frameWidth, width: frameWidth,

View File

@ -513,3 +513,31 @@ export const reloadWindow = (browserWindow: ICustomBrowserWindow) => {
mainWindow.webContents.send('restart-floater', { windowName, bounds }); mainWindow.webContents.send('restart-floater', { windowName, bounds });
} }
}; };
/**
* Verifies if window exists and restores/focuses the window
*
* @param browserWindow {ICustomBrowserWindow}
*/
export const didVerifyAndRestoreWindow = (browserWindow: BrowserWindow | null): boolean => {
if (!browserWindow || !windowExists(browserWindow)) {
return false;
}
if (browserWindow.isMinimized()) {
browserWindow.restore();
}
browserWindow.focus();
return true;
};
/**
* Finds and returns a specific window by name
*
* @param windowName {String}
*/
export const getWindowByName = (windowName: string): BrowserWindow | undefined => {
const allWindows = BrowserWindow.getAllWindows();
return allWindows.find((window) => {
return (window as ICustomBrowserWindow).winName === windowName;
});
};