SDA-3516 (Refocus to main webContents when title bar action buttons are clicked) (#1326)

* SDA-3516 - Refocus to main webContents when title bar action button are clicked

* SDA-3516 - Add getMainWebContents mock function
This commit is contained in:
Kiran Niranjan 2022-01-21 13:36:36 +05:30 committed by GitHub
parent 3d2bdbc23b
commit 5bcf36e7bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 1 deletions

View File

@ -46,6 +46,7 @@ jest.mock('../src/app/window-handler', () => {
isOnline: false,
updateVersionInfo: jest.fn(),
isMana: false,
getMainWebContents: jest.fn(),
appMenu: {
buildMenu: jest.fn(),
},

View File

@ -83,6 +83,7 @@ ipcMain.on(
);
return;
}
const mainWebContents = windowHandler.getMainWebContents();
logApiCallParams(arg);
switch (arg.cmd) {
case apiCmds.isOnline:
@ -178,7 +179,6 @@ ipcMain.on(
showPopupMenu({ window: browserWin });
// Give focus back to main webContents so that
// cut, copy & paste from edit menu works as expected
const mainWebContents = windowHandler.getMainWebContents();
if (mainWebContents && !mainWebContents.isDestroyed()) {
mainWebContents.focus();
}
@ -337,13 +337,25 @@ ipcMain.on(
}
break;
case apiCmds.closeMainWindow:
// Give focus back to main webContents
if (mainWebContents && !mainWebContents.isDestroyed()) {
mainWebContents.focus();
}
windowHandler.getMainWindow()?.close();
break;
case apiCmds.minimizeMainWindow:
// Give focus back to main webContents
if (mainWebContents && !mainWebContents.isDestroyed()) {
mainWebContents.focus();
}
windowHandler.getMainWindow()?.minimize();
break;
case apiCmds.maximizeMainWindow:
windowHandler.getMainWindow()?.maximize();
// Give focus back to main webContents
if (mainWebContents && !mainWebContents.isDestroyed()) {
mainWebContents.focus();
}
break;
case apiCmds.unmaximizeMainWindow:
const mainWindow = windowHandler.getMainWindow();
@ -352,6 +364,10 @@ ipcMain.on(
? mainWindow.setFullScreen(false)
: mainWindow.unmaximize();
}
// Give focus back to main webContents
if (mainWebContents && !mainWebContents.isDestroyed()) {
mainWebContents.focus();
}
break;
case apiCmds.setPodUrl:
await config.updateUserConfig({ url: arg.newPodUrl });

View File

@ -260,6 +260,15 @@ export class WindowHandler {
app.getLocale()) as LocaleType;
i18n.setLocale(locale);
logger.info(`window handler: env details`, {
contextIsolation: this.contextIsolation,
isNodeEnv,
isDevEnv,
isMac,
isWindowsOS,
isLinux,
});
this.listenForLoad();
}