From c42c1b7bbdb9fea46c3b6c9ad8a620fd9fcd5559 Mon Sep 17 00:00:00 2001 From: Sqaaakoi Date: Sat, 5 Apr 2025 02:44:47 +1300 Subject: [PATCH] Fix Visual Refresh titlebar (#1104) --- src/main/ipc.ts | 35 ++++++++++++------- src/preload/VesktopNative.ts | 4 +-- src/renderer/patches/index.ts | 2 +- .../{nativeFocus.tsx => windowMethods.tsx} | 11 ++++-- src/renderer/patches/windowsTitleBar.tsx | 22 +++++++++--- 5 files changed, 52 insertions(+), 22 deletions(-) rename src/renderer/patches/{nativeFocus.tsx => windowMethods.tsx} (53%) diff --git a/src/main/ipc.ts b/src/main/ipc.ts index 1dfb8e6..fa0fe33 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -7,7 +7,17 @@ if (process.platform === "linux") import("./venmic"); import { execFile } from "child_process"; -import { app, BrowserWindow, clipboard, dialog, nativeImage, RelaunchOptions, session, shell } from "electron"; +import { + app, + BrowserWindow, + clipboard, + dialog, + IpcMainInvokeEvent, + nativeImage, + RelaunchOptions, + session, + shell +} from "electron"; import { mkdirSync, readFileSync, watch } from "fs"; import { open, readFile } from "fs/promises"; import { release } from "os"; @@ -68,28 +78,29 @@ handle(IpcEvents.SHOW_ITEM_IN_FOLDER, (_, path) => { shell.showItemInFolder(path); }); +function getWindow(e: IpcMainInvokeEvent, key?: string) { + return key ? PopoutWindows.get(key)! : (BrowserWindow.fromWebContents(e.sender) ?? mainWin); +} + handle(IpcEvents.FOCUS, () => { mainWin.show(); mainWin.setSkipTaskbar(false); }); handle(IpcEvents.CLOSE, (e, key?: string) => { - const popout = PopoutWindows.get(key!); - if (popout) return popout.close(); - - const win = BrowserWindow.fromWebContents(e.sender) ?? e.sender; - win.close(); + getWindow(e, key).close(); }); -handle(IpcEvents.MINIMIZE, e => { - mainWin.minimize(); +handle(IpcEvents.MINIMIZE, (e, key?: string) => { + getWindow(e, key).minimize(); }); -handle(IpcEvents.MAXIMIZE, e => { - if (mainWin.isMaximized()) { - mainWin.unmaximize(); +handle(IpcEvents.MAXIMIZE, (e, key?: string) => { + const win = getWindow(e, key); + if (win.isMaximized()) { + win.unmaximize(); } else { - mainWin.maximize(); + win.maximize(); } }); diff --git a/src/preload/VesktopNative.ts b/src/preload/VesktopNative.ts index 69884cd..ec993c1 100644 --- a/src/preload/VesktopNative.ts +++ b/src/preload/VesktopNative.ts @@ -55,8 +55,8 @@ export const VesktopNative = { win: { focus: () => invoke(IpcEvents.FOCUS), close: (key?: string) => invoke(IpcEvents.CLOSE, key), - minimize: () => invoke(IpcEvents.MINIMIZE), - maximize: () => invoke(IpcEvents.MAXIMIZE) + minimize: (key?: string) => invoke(IpcEvents.MINIMIZE, key), + maximize: (key?: string) => invoke(IpcEvents.MAXIMIZE, key) }, capturer: { getLargeThumbnail: (id: string) => invoke(IpcEvents.CAPTURER_GET_LARGE_THUMBNAIL, id) diff --git a/src/renderer/patches/index.ts b/src/renderer/patches/index.ts index c82f481..0bb3aeb 100644 --- a/src/renderer/patches/index.ts +++ b/src/renderer/patches/index.ts @@ -14,5 +14,5 @@ import "./screenShareFixes"; import "./spellCheck"; import "./windowsTitleBar"; import "./streamerMode"; -import "./nativeFocus"; +import "./windowMethods"; import "./hideDownloadAppsButton"; diff --git a/src/renderer/patches/nativeFocus.tsx b/src/renderer/patches/windowMethods.tsx similarity index 53% rename from src/renderer/patches/nativeFocus.tsx rename to src/renderer/patches/windowMethods.tsx index fe8720d..948a5d5 100644 --- a/src/renderer/patches/nativeFocus.tsx +++ b/src/renderer/patches/windowMethods.tsx @@ -9,13 +9,18 @@ import { addPatch } from "./shared"; addPatch({ patches: [ { - find: ".DEEP_LINK]:{", + find: ",setSystemTrayApplications", replacement: [ + { + // eslint-disable-next-line no-useless-escape + match: /\i\.window\.(close|minimize|maximize)/, + replace: `VesktopNative.win.$1` + }, { // TODO: Fix eslint rule // eslint-disable-next-line no-useless-escape - match: /(?<=\.DEEP_LINK.{0,200}?)\i\.\i\.focus\(\)/, - replace: "VesktopNative.win.focus()" + match: /(focus(\(\i\)){).{0,150}?\.focus\(\i,\i\)/, + replace: "$1VesktopNative.win.focus$2" } ] } diff --git a/src/renderer/patches/windowsTitleBar.tsx b/src/renderer/patches/windowsTitleBar.tsx index f5ef07c..1b9e180 100644 --- a/src/renderer/patches/windowsTitleBar.tsx +++ b/src/renderer/patches/windowsTitleBar.tsx @@ -19,11 +19,25 @@ if (Settings.store.customTitleBar) // eslint-disable-next-line no-useless-escape match: /case \i\.\i\.WINDOWS:/, replace: 'case "WEB":' + } + ] + }, + // Visual Refresh + { + find: '"data-windows":', + replacement: [ + { + // TODO: Fix eslint rule + // eslint-disable-next-line no-useless-escape + match: /\i===\i\.PlatformTypes\.WINDOWS/g, + replace: "true" }, - ...["close", "minimize", "maximize"].map(op => ({ - match: new RegExp(String.raw`\i\.\i\.${op}\b`), - replace: `VesktopNative.win.${op}` - })) + { + // TODO: Fix eslint rule + // eslint-disable-next-line no-useless-escape + match: /\i===\i\.PlatformTypes\.WEB/g, + replace: "false" + } ] } ]