fix(native-buttons): watching for changes on other platforms than win32

This commit is contained in:
Elian Doran
2024-12-07 00:41:17 +02:00
parent 04cbb7ea07
commit 2d0e88b503

View File

@@ -54,17 +54,25 @@ function initOnElectron() {
} }
function initTitleBarButtons() { function initTitleBarButtons() {
function applyTitleBarOverlaySettings() {
const electronRemote = utils.dynamicRequire("@electron/remote"); const electronRemote = utils.dynamicRequire("@electron/remote");
const currentWindow = electronRemote.getCurrentWindow(); const currentWindow = electronRemote.getCurrentWindow();
const style = window.getComputedStyle(document.body); const style = window.getComputedStyle(document.body);
if (window.glob.platform === "win32") {
const applyWindowsOverlay = () => {
const color = style.getPropertyValue("--native-titlebar-background"); const color = style.getPropertyValue("--native-titlebar-background");
const symbolColor = style.getPropertyValue("--native-titlebar-foreground"); const symbolColor = style.getPropertyValue("--native-titlebar-foreground");
if (color && symbolColor) {
if (window.glob.platform === "win32" && color && symbolColor) {
currentWindow.setTitleBarOverlay({ color, symbolColor }); currentWindow.setTitleBarOverlay({ color, symbolColor });
} }
};
applyWindowsOverlay();
// Register for changes to the native title bar colors.
window.matchMedia("(prefers-color-scheme: dark)")
.addEventListener("change", applyWindowsOverlay);
}
if (window.glob.platform === "darwin") { if (window.glob.platform === "darwin") {
const xOffset = parseInt(style.getPropertyValue("--native-titlebar-darwin-x-offset"), 10); const xOffset = parseInt(style.getPropertyValue("--native-titlebar-darwin-x-offset"), 10);
@@ -72,11 +80,3 @@ function initTitleBarButtons() {
currentWindow.setWindowButtonPosition({ x: xOffset, y: yOffset }); currentWindow.setWindowButtonPosition({ x: xOffset, y: yOffset });
} }
} }
// Update the native title bar buttons.
applyTitleBarOverlaySettings();
// Register for changes to the native title bar colors.
window.matchMedia("(prefers-color-scheme: dark)")
.addEventListener("change", applyTitleBarOverlaySettings);
}