From 314f7ab96f877f66b5b44c51d4afbf63c20b9cbb Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Tue, 23 Jul 2024 09:30:20 -0400 Subject: [PATCH] [MM-59840] Add Linux title bar buttons using `titleBarOverlay` field of `BrowserWindow` (#3104) * Add Linux title bar buttons using `titleBarOverlay` field of `BrowserWindow` * Lint fix, fix potential null on macOS --- src/main/windows/mainWindow.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/windows/mainWindow.ts b/src/main/windows/mainWindow.ts index b4dc0c50..18d55d2e 100644 --- a/src/main/windows/mainWindow.ts +++ b/src/main/windows/mainWindow.ts @@ -24,11 +24,12 @@ import { MAIN_WINDOW_FOCUSED, VIEW_FINISHED_RESIZING, TOGGLE_SECURE_INPUT, + EMIT_CONFIGURATION, } from 'common/communication'; import Config from 'common/config'; import {Logger} from 'common/log'; import ServerManager from 'common/servers/serverManager'; -import {DEFAULT_WINDOW_HEIGHT, DEFAULT_WINDOW_WIDTH, MINIMUM_WINDOW_HEIGHT, MINIMUM_WINDOW_WIDTH, SECOND} from 'common/utils/constants'; +import {DEFAULT_WINDOW_HEIGHT, DEFAULT_WINDOW_WIDTH, MINIMUM_WINDOW_HEIGHT, MINIMUM_WINDOW_WIDTH, SECOND, TAB_BAR_HEIGHT} from 'common/utils/constants'; import Utils from 'common/utils/util'; import * as Validator from 'common/Validator'; import {boundsInfoPath} from 'main/constants'; @@ -61,6 +62,7 @@ export class MainWindow extends EventEmitter { ipcMain.handle(GET_FULL_SCREEN_STATUS, () => this.win?.isFullScreen()); ipcMain.on(VIEW_FINISHED_RESIZING, this.handleViewFinishedResizing); + ipcMain.on(EMIT_CONFIGURATION, this.handleUpdateTitleBarOverlay); ServerManager.on(SERVERS_UPDATE, this.handleUpdateConfig); @@ -81,6 +83,7 @@ export class MainWindow extends EventEmitter { frame: !this.isFramelessWindow(), fullscreen: this.shouldStartFullScreen(), titleBarStyle: 'hidden' as const, + titleBarOverlay: process.platform === 'linux' ? this.getTitleBarOverlay() : false, trafficLightPosition: {x: 12, y: 12}, backgroundColor: '#fff', // prevents blurry text: https://electronjs.org/docs/faq#the-font-looks-blurry-what-is-this-and-what-can-i-do webPreferences: { @@ -246,6 +249,13 @@ export class MainWindow extends EventEmitter { return os.platform() === 'darwin' || (os.platform() === 'win32' && Utils.isVersionGreaterThanOrEqualTo(os.release(), '6.2')); }; + private getTitleBarOverlay = () => { + return { + color: Config.darkMode ? '#2e2e2e' : '#efefef', + height: TAB_BAR_HEIGHT, + }; + }; + private getSavedWindowState = (): Partial => { try { let savedWindowState: SavedWindowState | null = JSON.parse(fs.readFileSync(boundsInfoPath, 'utf-8')); @@ -548,6 +558,10 @@ export class MainWindow extends EventEmitter { private handleUpdateAppStateForViewId = (viewId: string, isExpired: boolean, newMentions: number, newUnreads: boolean) => { this.win?.webContents.send(UPDATE_MENTIONS, viewId, newMentions, newUnreads, isExpired); }; + + private handleUpdateTitleBarOverlay = () => { + this.win?.setTitleBarOverlay?.(this.getTitleBarOverlay()); + }; } const mainWindow = new MainWindow();