diff --git a/src/electron/electronConstants.ts b/src/electron/electronConstants.ts index 3226486d34..b0086f8029 100644 --- a/src/electron/electronConstants.ts +++ b/src/electron/electronConstants.ts @@ -3,4 +3,5 @@ export class ElectronConstants { static readonly enableCloseToTrayKey: string = 'enableCloseToTray'; static readonly enableTrayKey: string = 'enableTray'; static readonly enableStartToTrayKey: string = 'enableStartToTrayKey'; + static readonly enableAlwaysOnTopKey: string = 'enableAlwaysOnTopKey'; } diff --git a/src/electron/window.main.ts b/src/electron/window.main.ts index 865ea81368..6faed6a00d 100644 --- a/src/electron/window.main.ts +++ b/src/electron/window.main.ts @@ -1,9 +1,10 @@ import { app, BrowserWindow, screen } from 'electron'; +import { ElectronConstants } from './electronConstants'; + import * as path from 'path'; import * as url from 'url'; import { isDev, isMacAppStore, isSnapStore } from './utils'; - import { StorageService } from '../abstractions/storage.service'; const WindowEventHandlingDelay = 100; @@ -14,6 +15,7 @@ const Keys = { export class WindowMain { win: BrowserWindow; isQuitting: boolean = false; + enableAlwaysOnTop: boolean = false; private windowStateChangeTimer: NodeJS.Timer; private windowStates: { [key: string]: any; } = {}; @@ -84,6 +86,7 @@ export class WindowMain { async createWindow(): Promise { this.windowStates[Keys.mainWindowSize] = await this.getWindowState(Keys.mainWindowSize, this.defaultWidth, this.defaultHeight); + this.enableAlwaysOnTop = await this.storageService.get(ElectronConstants.enableAlwaysOnTopKey); // Create the browser window. this.win = new BrowserWindow({ @@ -97,6 +100,7 @@ export class WindowMain { icon: process.platform === 'linux' ? path.join(__dirname, '/images/icon.png') : undefined, titleBarStyle: this.hideTitleBar && process.platform === 'darwin' ? 'hiddenInset' : undefined, show: false, + alwaysOnTop: this.enableAlwaysOnTop, }); if (this.windowStates[Keys.mainWindowSize].isMaximized) { @@ -147,6 +151,13 @@ export class WindowMain { this.win.on('move', () => { this.windowStateChangeHandler(Keys.mainWindowSize, this.win); }); + + } + + async toggleAlwaysOnTop(){ + this.enableAlwaysOnTop = !this.win.isAlwaysOnTop(); + this.win.setAlwaysOnTop(this.enableAlwaysOnTop); + await this.storageService.save(ElectronConstants.enableAlwaysOnTopKey, this.enableAlwaysOnTop); } private windowStateChangeHandler(configKey: string, win: BrowserWindow) {