From 57d2b0ebf59a5c15f107ffc52009fc8c76073347 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 7 Dec 2024 03:15:39 +0200 Subject: [PATCH] fix(mica): apply correct mica when switching layouts --- src/public/app/desktop.js | 21 ++++++++++++++++----- src/services/window.ts | 2 +- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/public/app/desktop.js b/src/public/app/desktop.js index bad74c698..5cb52f136 100644 --- a/src/public/app/desktop.js +++ b/src/public/app/desktop.js @@ -48,14 +48,17 @@ function initOnElectron() { const electron = utils.dynamicRequire('electron'); electron.ipcRenderer.on('globalShortcut', async (event, actionName) => appContext.triggerCommand(actionName)); + const electronRemote = utils.dynamicRequire("@electron/remote"); + const currentWindow = electronRemote.getCurrentWindow(); + + initTransparencyEffects(currentWindow); + if (options.get("nativeTitleBarVisible") !== "true") { - initTitleBarButtons(); - } + initTitleBarButtons(currentWindow); + } } -function initTitleBarButtons() { - const electronRemote = utils.dynamicRequire("@electron/remote"); - const currentWindow = electronRemote.getCurrentWindow(); +function initTitleBarButtons(currentWindow) { const style = window.getComputedStyle(document.body); if (window.glob.platform === "win32") { @@ -80,3 +83,11 @@ function initTitleBarButtons() { currentWindow.setWindowButtonPosition({ x: xOffset, y: yOffset }); } } + +function initTransparencyEffects(currentWindow) { + if (window.glob.platform === "win32") { + const isHorizontalLayout = (options.get("layoutOrientation") === "horizontal"); + const backgroundMaterial = isHorizontalLayout ? "tabbed" : "mica"; + currentWindow.setBackgroundMaterial(backgroundMaterial); + } +} \ No newline at end of file diff --git a/src/services/window.ts b/src/services/window.ts index 142ea3cd3..1555d79ae 100644 --- a/src/services/window.ts +++ b/src/services/window.ts @@ -132,7 +132,7 @@ function getWindowExtraOpts() { } // Window effects (Mica) - // TODO: Apply only on Windows and allow the user to choose whether to activate it or not. + // TODO: Deduplicate with src/public/app/desktop.js#initTransparencyEffects const isHorizontalLayout = (optionService.getOption("layoutOrientation") === "horizontal"); extraOpts.backgroundMaterial = isHorizontalLayout ? "tabbed" : "mica";