From 2d0e88b50399fa51df3d15129cb6ea83b649cc97 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 7 Dec 2024 00:41:17 +0200 Subject: [PATCH] fix(native-buttons): watching for changes on other platforms than win32 --- src/public/app/desktop.js | 44 +++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/public/app/desktop.js b/src/public/app/desktop.js index a848366cc..bad74c698 100644 --- a/src/public/app/desktop.js +++ b/src/public/app/desktop.js @@ -54,29 +54,29 @@ function initOnElectron() { } function initTitleBarButtons() { - function applyTitleBarOverlaySettings() { - const electronRemote = utils.dynamicRequire("@electron/remote"); - const currentWindow = electronRemote.getCurrentWindow(); + const electronRemote = utils.dynamicRequire("@electron/remote"); + const currentWindow = electronRemote.getCurrentWindow(); + const style = window.getComputedStyle(document.body); + + if (window.glob.platform === "win32") { + const applyWindowsOverlay = () => { + const color = style.getPropertyValue("--native-titlebar-background"); + const symbolColor = style.getPropertyValue("--native-titlebar-foreground"); + if (color && symbolColor) { + currentWindow.setTitleBarOverlay({ color, symbolColor }); + } + }; - const style = window.getComputedStyle(document.body); - const color = style.getPropertyValue("--native-titlebar-background"); - const symbolColor = style.getPropertyValue("--native-titlebar-foreground"); + applyWindowsOverlay(); - if (window.glob.platform === "win32" && color && symbolColor) { - currentWindow.setTitleBarOverlay({ color, symbolColor }); - } - - if (window.glob.platform === "darwin") { - const xOffset = parseInt(style.getPropertyValue("--native-titlebar-darwin-x-offset"), 10); - const yOffset = parseInt(style.getPropertyValue("--native-titlebar-darwin-y-offset"), 10); - currentWindow.setWindowButtonPosition({ x: xOffset, y: yOffset }); - } + // Register for changes to the native title bar colors. + window.matchMedia("(prefers-color-scheme: dark)") + .addEventListener("change", applyWindowsOverlay); } - - // 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); + + if (window.glob.platform === "darwin") { + const xOffset = parseInt(style.getPropertyValue("--native-titlebar-darwin-x-offset"), 10); + const yOffset = parseInt(style.getPropertyValue("--native-titlebar-darwin-y-offset"), 10); + currentWindow.setWindowButtonPosition({ x: xOffset, y: yOffset }); + } }