From 01014827749936602253e3eb0a867f758de9013e Mon Sep 17 00:00:00 2001 From: V Date: Sun, 6 Aug 2023 23:58:35 +0200 Subject: [PATCH] [WIP] Port Discord's windows title bar --- src/main/ipc.ts | 14 ++++++++++++- src/preload/VesktopNative.ts | 6 +++++- src/renderer/patches/index.ts | 1 + src/renderer/patches/windowsTitleBar.tsx | 25 ++++++++++++++++++++++++ src/shared/IpcEvents.ts | 3 +++ 5 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 src/renderer/patches/windowsTitleBar.tsx diff --git a/src/main/ipc.ts b/src/main/ipc.ts index 648c34c..a68243d 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -73,7 +73,19 @@ ipcMain.handle(IpcEvents.FOCUS, () => { }); ipcMain.handle(IpcEvents.CLOSE, e => { - e.sender.close(); + mainWin.close(); +}); + +ipcMain.handle(IpcEvents.MINIMIZE, e => { + mainWin.minimize(); +}); + +ipcMain.handle(IpcEvents.MAXIMIZE, e => { + mainWin.maximize(); +}); + +ipcMain.handle(IpcEvents.FULLSCREEN, e => { + mainWin.setFullScreen(true); }); ipcMain.handle(IpcEvents.SPELLCHECK_SET_LANGUAGES, (_, languages: string[]) => { diff --git a/src/preload/VesktopNative.ts b/src/preload/VesktopNative.ts index 6a4415a..6ffe30c 100644 --- a/src/preload/VesktopNative.ts +++ b/src/preload/VesktopNative.ts @@ -51,7 +51,11 @@ export const VesktopNative = { addToDictionary: (word: string) => invoke(IpcEvents.SPELLCHECK_ADD_TO_DICTIONARY, word) }, win: { - focus: () => invoke(IpcEvents.FOCUS) + focus: () => invoke(IpcEvents.FOCUS), + close: () => invoke(IpcEvents.CLOSE), + minimize: () => invoke(IpcEvents.MINIMIZE), + fullscreen: () => invoke(IpcEvents.FULLSCREEN), + maximize: () => invoke(IpcEvents.MAXIMIZE) }, 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 d2bd536..e33c00f 100644 --- a/src/renderer/patches/index.ts +++ b/src/renderer/patches/index.ts @@ -7,3 +7,4 @@ // TODO: Possibly auto generate glob if we have more patches in the future import "./spellCheck"; import "./platformClass"; +import "./windowsTitleBar"; diff --git a/src/renderer/patches/windowsTitleBar.tsx b/src/renderer/patches/windowsTitleBar.tsx new file mode 100644 index 0000000..8f7b977 --- /dev/null +++ b/src/renderer/patches/windowsTitleBar.tsx @@ -0,0 +1,25 @@ +/* + * SPDX-License-Identifier: GPL-3.0 + * Vesktop, a desktop app aiming to give you a snappier Discord Experience + * Copyright (c) 2023 Vendicated and Vencord contributors + */ + +import { addPatch } from "./shared"; + +addPatch({ + patches: [ + { + find: ".wordmarkWindows", + replacement: [ + { + match: /case \i\.\i\.WINDOWS:/, + replace: 'case "WEB":' + }, + ...["close", "minimize", "fullscreen", "maximize"].map(op => ({ + match: new RegExp(String.raw`\i\.default\.${op}\b`), + replace: `VesktopNative.win.${op}` + })) + ] + } + ] +}); diff --git a/src/shared/IpcEvents.ts b/src/shared/IpcEvents.ts index 3a171ec..733f9e6 100644 --- a/src/shared/IpcEvents.ts +++ b/src/shared/IpcEvents.ts @@ -16,6 +16,9 @@ export const enum IpcEvents { RELAUNCH = "VCD_RELAUNCH", CLOSE = "VCD_CLOSE", FOCUS = "VCD_FOCUS", + MINIMIZE = "VCD_MINIMIZE", + FULLSCREEN = "VCD_FULLSCREEN", + MAXIMIZE = "VCD_MAXIMIZE", SHOW_ITEM_IN_FOLDER = "VCD_SHOW_ITEM_IN_FOLDER", GET_SETTINGS = "VCD_GET_SETTINGS",