fix: ELECTRON-1382 (Fix notification z-index when alwaysOnTop is enabled) (#727)

* ELECTRON-1382 - Fix notification z-index when alwaysOnTop is enabled
This commit is contained in:
Kiran Niranjan 2019-07-12 21:25:48 +05:30 committed by GitHub
parent 36a68ec01b
commit 486d345dc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 2 deletions

View File

@ -10,6 +10,12 @@ jest.mock('../src/app/window-handler', () => {
};
});
jest.mock('../src/renderer/notification', () => {
return {
setupNotificationPosition: jest.fn(),
};
});
jest.mock('electron-log');
describe('dialog handler', () => {

View File

@ -5,6 +5,7 @@ import { isMac, isWindowsOS } from '../common/env';
import { i18n } from '../common/i18n';
import { logger } from '../common/logger';
import { throttle } from '../common/utils';
import { notification } from '../renderer/notification';
import { config } from './config-handler';
import { ICustomBrowserWindow, windowHandler } from './window-handler';
import { showPopupMenu, windowExists } from './window-utils';
@ -56,6 +57,11 @@ const windowMaximized = async (): Promise<void> => {
const throttledWindowChanges = throttle(async () => {
await saveWindowSettings();
await windowMaximized();
notification.moveNotificationToTop();
}, 1000);
const throttledWindowRestore = throttle(async () => {
notification.moveNotificationToTop();
}, 1000);
/**
@ -109,7 +115,7 @@ export const updateAlwaysOnTop = (shouldSetAlwaysOnTop: boolean, shouldActivateM
const browserWins: ICustomBrowserWindow[] = BrowserWindow.getAllWindows() as ICustomBrowserWindow[];
if (browserWins.length > 0) {
browserWins
.filter((browser) => typeof browser.notificationObj !== 'object')
.filter((browser) => typeof browser.notificationData !== 'object')
.forEach((browser) => browser.setAlwaysOnTop(shouldSetAlwaysOnTop));
// An issue where changing the alwaysOnTop property
@ -175,6 +181,10 @@ export const monitorWindowActions = (window: BrowserWindow): void => {
window.on('leave-full-screen', throttledWindowChanges);
window.on('unmaximize', throttledWindowChanges);
if ((window as ICustomBrowserWindow).winName === apiName.mainWindowName) {
window.on('restore', throttledWindowRestore);
}
};
/**

View File

@ -35,7 +35,7 @@ interface ICustomBrowserWindowConstructorOpts extends Electron.BrowserWindowCons
export interface ICustomBrowserWindow extends Electron.BrowserWindow {
winName: string;
notificationObj?: object;
notificationData?: object;
origin?: string;
}

View File

@ -300,6 +300,21 @@ class Notification extends NotificationHandler {
this.inactiveWindows = [];
}
/**
* Brings all the notification to the top
* issue: ELECTRON-1382
*/
public moveNotificationToTop(): void {
const notificationWindows = this.activeNotifications as ICustomBrowserWindow[];
notificationWindows
.filter((browserWindow) => typeof browserWindow.notificationData === 'object' && browserWindow.isVisible())
.forEach((browserWindow) => {
if (browserWindow && windowExists(browserWindow) && browserWindow.isVisible()) {
browserWindow.moveTop();
}
});
}
/**
* Waits for window to load and resolves
*
@ -368,6 +383,11 @@ class Notification extends NotificationHandler {
if (!notificationWindow || !windowExists(notificationWindow)) {
return;
}
if (notificationWindow.notificationData && notificationWindow.notificationData.sticky) {
return;
}
const displayTime = (notificationWindow.notificationData && notificationWindow.notificationData.displayTime)
? notificationWindow.notificationData.displayTime
: notificationSettings.displayTime;