Skip to content

Commit

Permalink
fix: ELECTRON-1382 (Fix notification z-index when alwaysOnTop is enab…
Browse files Browse the repository at this point in the history
…led) (#727)

* ELECTRON-1382 - Fix notification z-index when alwaysOnTop is enabled
  • Loading branch information
KiranNiranjan authored Jul 12, 2019
1 parent 36a68ec commit 486d345
Showing 4 changed files with 38 additions and 2 deletions.
6 changes: 6 additions & 0 deletions spec/dialogHandler.spec.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
12 changes: 11 additions & 1 deletion src/app/window-actions.ts
Original file line number Diff line number Diff line change
@@ -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);
}
};

/**
2 changes: 1 addition & 1 deletion src/app/window-handler.ts
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ interface ICustomBrowserWindowConstructorOpts extends Electron.BrowserWindowCons

export interface ICustomBrowserWindow extends Electron.BrowserWindow {
winName: string;
notificationObj?: object;
notificationData?: object;
origin?: string;
}

20 changes: 20 additions & 0 deletions src/renderer/notification.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 486d345

Please sign in to comment.