[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
This commit is contained in:
Devin Binnie 2024-07-23 09:30:20 -04:00 committed by GitHub
parent 1acd26dc08
commit 314f7ab96f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -24,11 +24,12 @@ import {
MAIN_WINDOW_FOCUSED, MAIN_WINDOW_FOCUSED,
VIEW_FINISHED_RESIZING, VIEW_FINISHED_RESIZING,
TOGGLE_SECURE_INPUT, TOGGLE_SECURE_INPUT,
EMIT_CONFIGURATION,
} from 'common/communication'; } from 'common/communication';
import Config from 'common/config'; import Config from 'common/config';
import {Logger} from 'common/log'; import {Logger} from 'common/log';
import ServerManager from 'common/servers/serverManager'; 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 Utils from 'common/utils/util';
import * as Validator from 'common/Validator'; import * as Validator from 'common/Validator';
import {boundsInfoPath} from 'main/constants'; import {boundsInfoPath} from 'main/constants';
@ -61,6 +62,7 @@ export class MainWindow extends EventEmitter {
ipcMain.handle(GET_FULL_SCREEN_STATUS, () => this.win?.isFullScreen()); ipcMain.handle(GET_FULL_SCREEN_STATUS, () => this.win?.isFullScreen());
ipcMain.on(VIEW_FINISHED_RESIZING, this.handleViewFinishedResizing); ipcMain.on(VIEW_FINISHED_RESIZING, this.handleViewFinishedResizing);
ipcMain.on(EMIT_CONFIGURATION, this.handleUpdateTitleBarOverlay);
ServerManager.on(SERVERS_UPDATE, this.handleUpdateConfig); ServerManager.on(SERVERS_UPDATE, this.handleUpdateConfig);
@ -81,6 +83,7 @@ export class MainWindow extends EventEmitter {
frame: !this.isFramelessWindow(), frame: !this.isFramelessWindow(),
fullscreen: this.shouldStartFullScreen(), fullscreen: this.shouldStartFullScreen(),
titleBarStyle: 'hidden' as const, titleBarStyle: 'hidden' as const,
titleBarOverlay: process.platform === 'linux' ? this.getTitleBarOverlay() : false,
trafficLightPosition: {x: 12, y: 12}, 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 backgroundColor: '#fff', // prevents blurry text: https://electronjs.org/docs/faq#the-font-looks-blurry-what-is-this-and-what-can-i-do
webPreferences: { webPreferences: {
@ -246,6 +249,13 @@ export class MainWindow extends EventEmitter {
return os.platform() === 'darwin' || (os.platform() === 'win32' && Utils.isVersionGreaterThanOrEqualTo(os.release(), '6.2')); 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<SavedWindowState> => { private getSavedWindowState = (): Partial<SavedWindowState> => {
try { try {
let savedWindowState: SavedWindowState | null = JSON.parse(fs.readFileSync(boundsInfoPath, 'utf-8')); 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) => { private handleUpdateAppStateForViewId = (viewId: string, isExpired: boolean, newMentions: number, newUnreads: boolean) => {
this.win?.webContents.send(UPDATE_MENTIONS, viewId, newMentions, newUnreads, isExpired); this.win?.webContents.send(UPDATE_MENTIONS, viewId, newMentions, newUnreads, isExpired);
}; };
private handleUpdateTitleBarOverlay = () => {
this.win?.setTitleBarOverlay?.(this.getTitleBarOverlay());
};
} }
const mainWindow = new MainWindow(); const mainWindow = new MainWindow();