From 7a4fc365b8e83f509b90803cddc262a1a8ded2e8 Mon Sep 17 00:00:00 2001 From: iamEvan <47493765+iamEvanYT@users.noreply.github.com> Date: Mon, 26 May 2025 23:24:58 +0100 Subject: [PATCH 1/5] feat: mica-electron package --- bun.lock | 3 +++ package.json | 1 + 2 files changed, 4 insertions(+) diff --git a/bun.lock b/bun.lock index 8cf9cc60..dfe9ef1a 100644 --- a/bun.lock +++ b/bun.lock @@ -12,6 +12,7 @@ "electron-context-menu": "^4.0.5", "electron-updater": "^6.6.2", "knex": "^3.1.0", + "mica-electron": "^1.5.16", "mime-types": "^3.0.1", "posthog-node": "^4.17.1", "sharp": "^0.34.1", @@ -1376,6 +1377,8 @@ "merge2": ["merge2@1.4.1", "", {}, "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg=="], + "mica-electron": ["mica-electron@1.5.16", "", {}, "sha512-08/o9vv4cr4ozltO2U4/37R70Y6hqAjH2nr7GzpDLAdqCWkeAAge5ZPrzl+ndUDhO6IsoL2gFmpbU17Jj406Zg=="], + "micromatch": ["micromatch@4.0.8", "", { "dependencies": { "braces": "^3.0.3", "picomatch": "^2.3.1" } }, "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA=="], "mime": ["mime@2.6.0", "", { "bin": { "mime": "cli.js" } }, "sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg=="], diff --git a/package.json b/package.json index baf6afd8..af2dcc04 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "electron-context-menu": "^4.0.5", "electron-updater": "^6.6.2", "knex": "^3.1.0", + "mica-electron": "^1.5.16", "mime-types": "^3.0.1", "posthog-node": "^4.17.1", "sharp": "^0.34.1", From 0171fcc635625b5f8979659fa188aca5f952b4a8 Mon Sep 17 00:00:00 2001 From: iamEvan <47493765+iamEvanYT@users.noreply.github.com> Date: Mon, 26 May 2025 23:29:21 +0100 Subject: [PATCH 2/5] feat: integrate MicaBrowserWindow for enhanced window effects --- src/main/browser/window.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/browser/window.ts b/src/main/browser/window.ts index 6a1a7f3c..a65fcdb0 100644 --- a/src/main/browser/window.ts +++ b/src/main/browser/window.ts @@ -5,13 +5,14 @@ import { PageBounds } from "@/ipc/browser/page"; import { FLAGS } from "@/modules/flags"; import { TypedEventEmitter } from "@/modules/typed-event-emitter"; import { getLastUsedSpace } from "@/sessions/spaces"; -import { BrowserWindow, nativeTheme, WebContents } from "electron"; +import { nativeTheme, WebContents } from "electron"; import "./close-preventer"; import { WindowEventType } from "@/modules/windows"; import { windowEvents } from "@/modules/windows"; import { initializePortalComponentWindows } from "@/browser/components/portal-component-windows"; import { defaultSessionReady } from "@/browser/sessions"; import { fireWindowStateChanged } from "@/ipc/browser/interface"; +import { MicaBrowserWindow } from "mica-electron"; type BrowserWindowType = "normal" | "popup"; @@ -29,7 +30,7 @@ type BrowserWindowEvents = { export class TabbedBrowserWindow extends TypedEventEmitter { id: number; - window: BrowserWindow; + window: MicaBrowserWindow; public viewManager: ViewManager; public coreWebContents: WebContents[]; @@ -46,7 +47,7 @@ export class TabbedBrowserWindow extends TypedEventEmitter constructor(browser: Browser, type: BrowserWindowType, options: BrowserWindowCreationOptions = {}) { super(); - this.window = new BrowserWindow({ + this.window = new MicaBrowserWindow({ minWidth: type === "normal" ? 800 : 250, minHeight: type === "normal" ? 400 : 200, width: 1280, @@ -74,6 +75,17 @@ export class TabbedBrowserWindow extends TypedEventEmitter ...(options.window || {}) }); + // Apply Mica effect on Windows + if (process.platform === "win32") { + this.window.setRoundedCorner(); + + // Window 7+ + this.window.setAcrylic(); + + // Window 11 + this.window.setMicaAcrylicEffect(); + } + // Hide the window buttons before the component is mounted if (type === "normal") { this.setWindowButtonVisibility(false); From 89beba12c7e86f46798e78b1616ef4b5046b2070 Mon Sep 17 00:00:00 2001 From: iamEvan <47493765+iamEvanYT@users.noreply.github.com> Date: Mon, 26 May 2025 23:59:07 +0100 Subject: [PATCH 3/5] fix --- src/main/browser/window.ts | 34 +++++++++++++++++++++++++--------- src/main/modules/flags.ts | 4 ++++ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/main/browser/window.ts b/src/main/browser/window.ts index a65fcdb0..5cbf4588 100644 --- a/src/main/browser/window.ts +++ b/src/main/browser/window.ts @@ -28,6 +28,20 @@ type BrowserWindowEvents = { destroy: []; }; +function applyMicaEffect(window: MicaBrowserWindow) { + // if (window.isMaximized()) { + // window.setSquareCorner(); + // } else { + // window.setRoundedCorner(); + // } + + // Window 7+ + window.setAcrylic(); + + // Window 11 + window.setMicaAcrylicEffect(); +} + export class TabbedBrowserWindow extends TypedEventEmitter { id: number; window: MicaBrowserWindow; @@ -76,15 +90,15 @@ export class TabbedBrowserWindow extends TypedEventEmitter }); // Apply Mica effect on Windows - if (process.platform === "win32") { - this.window.setRoundedCorner(); - - // Window 7+ - this.window.setAcrylic(); - - // Window 11 - this.window.setMicaAcrylicEffect(); - } + const useMicaElectron = process.platform === "win32" && FLAGS.USE_MICA_ELECTRON; + const updateMicaEffect = () => { + if (useMicaElectron) { + applyMicaEffect(this.window); + return true; + } + return false; + }; + updateMicaEffect(); // Hide the window buttons before the component is mounted if (type === "normal") { @@ -113,9 +127,11 @@ export class TabbedBrowserWindow extends TypedEventEmitter this.window.on("maximize", () => { fireWindowStateChanged(this); + updateMicaEffect(); }); this.window.on("unmaximize", () => { fireWindowStateChanged(this); + updateMicaEffect(); }); // Focus on the focused tab diff --git a/src/main/modules/flags.ts b/src/main/modules/flags.ts index 4d161717..c32a0e94 100644 --- a/src/main/modules/flags.ts +++ b/src/main/modules/flags.ts @@ -3,6 +3,7 @@ import { DEBUG_AREA } from "./output"; type Flags = { SCRUBBED_USER_AGENT: boolean; + USE_MICA_ELECTRON: boolean; ERROR_PAGE_LOAD_MODE: "replace" | "load"; SHOW_DEBUG_PRINTS: boolean; SHOW_DEBUG_ERRORS: boolean | DEBUG_AREA[]; @@ -17,6 +18,9 @@ export const FLAGS: Flags = { // Transform the user agent SCRUBBED_USER_AGENT: true, + // Use Mica Electron + USE_MICA_ELECTRON: true, + // Replace - Use window.location.replace to load the error page. // Load - Add the page to the history stack by loading it normally. ERROR_PAGE_LOAD_MODE: "replace", From 40008eb959019c98a82dfd70cf7c118d09098a33 Mon Sep 17 00:00:00 2001 From: iamEvan <47493765+iamEvanYT@users.noreply.github.com> Date: Tue, 27 May 2025 00:00:33 +0100 Subject: [PATCH 4/5] feat: update logic --- src/main/browser/window.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/browser/window.ts b/src/main/browser/window.ts index 5cbf4588..b2439230 100644 --- a/src/main/browser/window.ts +++ b/src/main/browser/window.ts @@ -12,7 +12,7 @@ import { windowEvents } from "@/modules/windows"; import { initializePortalComponentWindows } from "@/browser/components/portal-component-windows"; import { defaultSessionReady } from "@/browser/sessions"; import { fireWindowStateChanged } from "@/ipc/browser/interface"; -import { MicaBrowserWindow } from "mica-electron"; +import { IS_WINDOWS_11, MicaBrowserWindow } from "mica-electron"; type BrowserWindowType = "normal" | "popup"; @@ -35,11 +35,13 @@ function applyMicaEffect(window: MicaBrowserWindow) { // window.setRoundedCorner(); // } - // Window 7+ - window.setAcrylic(); - - // Window 11 - window.setMicaAcrylicEffect(); + if (IS_WINDOWS_11) { + // Window 11 + window.setMicaAcrylicEffect(); + } else { + // Window 7+ + window.setAcrylic(); + } } export class TabbedBrowserWindow extends TypedEventEmitter { From f2e318fb9a148fe9466b15574b0c363517702ce3 Mon Sep 17 00:00:00 2001 From: iamEvan <47493765+iamEvanYT@users.noreply.github.com> Date: Tue, 27 May 2025 00:13:21 +0100 Subject: [PATCH 5/5] fix: corners --- src/main/browser/window.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/browser/window.ts b/src/main/browser/window.ts index b2439230..d60ea747 100644 --- a/src/main/browser/window.ts +++ b/src/main/browser/window.ts @@ -29,11 +29,11 @@ type BrowserWindowEvents = { }; function applyMicaEffect(window: MicaBrowserWindow) { - // if (window.isMaximized()) { - // window.setSquareCorner(); - // } else { - // window.setRoundedCorner(); - // } + if (window.isMaximized()) { + window.setSquareCorner(); + } else { + window.setRoundedCorner(); + } if (IS_WINDOWS_11) { // Window 11