Switch to hidden titleBar on macOS to integrate the app better (#1101)

This commit is contained in:
Michael Telatynski 2023-07-28 12:51:33 +01:00 committed by GitHub
parent 58bf462c47
commit 1234db90aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 123 additions and 0 deletions

View file

@ -40,6 +40,7 @@ import * as updater from "./updater";
import { getProfileFromDeeplink, protocolInit } from "./protocol";
import { _t, AppLocalization } from "./language-helper";
import { setDisplayMediaCallback } from "./displayMediaCallback";
import { setupMacosTitleBar } from "./macos-titlebar";
const argv = minimist(process.argv, {
alias: { help: "h" },
@ -454,6 +455,9 @@ app.on("ready", async () => {
// https://www.electronjs.org/docs/faq#the-font-looks-blurry-what-is-this-and-what-can-i-do
backgroundColor: "#fff",
titleBarStyle: process.platform === "darwin" ? "hidden" : "default",
trafficLightPosition: { x: 9, y: 8 },
icon: global.trayConfig.icon_path,
show: false,
autoHideMenuBar: global.store.get("autoHideMenuBar", true),
@ -472,6 +476,10 @@ app.on("ready", async () => {
});
global.mainWindow.loadURL("vector://vector/webapp/");
if (process.platform === "darwin") {
setupMacosTitleBar(global.mainWindow);
}
// Handle spellchecker
// For some reason spellCheckerEnabled isn't persisted, so we have to use the store here
global.mainWindow.webContents.session.setSpellCheckerEnabled(global.store.get("spellCheckerEnabled", true));

115
src/macos-titlebar.ts Normal file
View file

@ -0,0 +1,115 @@
/*
Copyright 2023 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { BrowserWindow } from "electron";
export function setupMacosTitleBar(window: BrowserWindow): void {
if (process.platform !== "darwin") return;
let userMenuCssKey: string | undefined;
async function makeSpaceForTrafficLight(): Promise<void> {
userMenuCssKey = await window.webContents.insertCSS(`
/* Create margin of space for the traffic light buttons */
.mx_UserMenu {
margin-top: 32px !important;
}
/* Maintain alignment of the toggle space panel button */
.mx_SpacePanel_toggleCollapse {
/* 19px original top value, 32px margin-top above, 12px original margin-top value */
top: calc(19px + 32px - 12px) !important;
}
`);
}
window.on("enter-full-screen", () => {
if (userMenuCssKey !== undefined) {
window.webContents.removeInsertedCSS(userMenuCssKey);
}
});
window.on("leave-full-screen", () => {
makeSpaceForTrafficLight();
});
window.webContents.on("did-finish-load", () => {
if (!window.isFullScreen()) {
makeSpaceForTrafficLight();
}
window.webContents.insertCSS(`
/* Mark the splash screen as a drag handle */
.mx_MatrixChat_splash {
-webkit-app-region: drag;
}
/* Exclude the splash buttons from being drag handles */
.mx_MatrixChat_splashButtons {
-webkit-app-region: no-drag;
}
/* Mark the background as a drag handle */
.mx_AuthPage {
-webkit-app-region: drag;
}
/* Exclude the main content elements from being drag handles */
.mx_AuthPage .mx_AuthPage_modalBlur,
.mx_AuthPage .mx_AuthFooter > * {
-webkit-app-region: no-drag;
}
/* Mark the header as a drag handle */
.mx_LeftPanel .mx_LeftPanel_filterContainer {
-webkit-app-region: drag;
}
/* Exclude header interactive elements from being drag handles */
.mx_LeftPanel .mx_LeftPanel_filterContainer .mx_AccessibleButton {
-webkit-app-region: no-drag;
}
/* Mark the home page background as a drag handle */
.mx_HomePage {
-webkit-app-region: drag;
}
/* Exclude interactive elements from being drag handles */
.mx_HomePage .mx_HomePage_body,
.mx_HomePage .mx_HomePage_default_wrapper > * {
-webkit-app-region: no-drag;
}
/* Mark the header as a drag handle */
.mx_RoomHeader {
-webkit-app-region: drag;
-webkit-user-select: none;
}
/* Exclude header interactive elements from being drag handles */
.mx_RoomHeader .mx_RoomHeader_avatar,
.mx_RoomHeader .mx_E2EIcon,
.mx_RoomHeader .mx_AccessibleButton {
-webkit-app-region: no-drag;
}
/* Mark the background as a drag handle */
.mx_RoomView_wrapper {
-webkit-app-region: drag;
}
/* Exclude content elements from being drag handles */
.mx_SpaceRoomView_landing > *,
.mx_RoomPreviewBar,
.mx_RoomView_body,
.mx_RoomPreviewCard {
-webkit-app-region: no-drag;
}
`);
});
}