From 462fc4e6ff6d3395c1c1623ed7f512f185100078 Mon Sep 17 00:00:00 2001 From: V Date: Mon, 7 Aug 2023 00:20:59 +0200 Subject: [PATCH] Add Setting & fix other issues --- src/main/mainWindow.ts | 7 +++-- src/renderer/components/Settings.tsx | 13 +++++--- src/renderer/patches/platformClass.tsx | 9 +++++- src/renderer/patches/windowsTitleBar.tsx | 39 +++++++++++++----------- src/shared/settings.d.ts | 16 +++++----- 5 files changed, 53 insertions(+), 31 deletions(-) diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index 279daba..aab75de 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -315,8 +315,11 @@ function createMainWindow() { removeSettingsListeners(); removeVencordSettingsListeners(); - const { staticTitle, transparencyOption, enableMenu } = Settings.store; + const { staticTitle, transparencyOption, enableMenu, discordWindowsTitleBar } = Settings.store; const { frameless, macosTranslucency } = VencordSettings.store; + + const noFrame = frameless === true || (process.platform === "win32" && discordWindowsTitleBar === true); + const win = (mainWin = new BrowserWindow({ show: false, webPreferences: { @@ -328,7 +331,7 @@ function createMainWindow() { spellcheck: true }, icon: ICON_PATH, - frame: frameless !== true, + frame: !noFrame, ...(transparencyOption && transparencyOption !== "none" ? { backgroundColor: "#00000000", diff --git a/src/renderer/components/Settings.tsx b/src/renderer/components/Settings.tsx index 14b33c8..c712350 100644 --- a/src/renderer/components/Settings.tsx +++ b/src/renderer/components/Settings.tsx @@ -10,7 +10,7 @@ import { Margins } from "@vencord/types/utils"; import { Button, Forms, Select, Switch, Text, useState } from "@vencord/types/webpack/common"; import { setBadge } from "renderer/appBadge"; import { useSettings } from "renderer/settings"; -import { isMac } from "renderer/utils"; +import { isMac, isWindows } from "renderer/utils"; import { isTruthy } from "shared/utils/guards"; export default function SettingsUi() { @@ -21,6 +21,11 @@ export default function SettingsUi() { const [autoStartEnabled, setAutoStartEnabled] = useState(autostart.isEnabled()); const allSwitches: Array boolean)?]> = [ + isWindows && [ + "discordWindowsTitleBar", + "Discord Titlebar", + "Use Discord's custom title bar instead of the Windows one. Requires a full restart." + ], !isMac && ["tray", "Tray Icon", "Add a tray icon for Vesktop", true], !isMac && [ "minimizeToTray", @@ -35,13 +40,13 @@ export default function SettingsUi() { "Disable minimum window size", "Allows you to make the window as small as your heart desires" ], + ["staticTitle", "Static Title", 'Makes the window title "Vesktop" instead of changing to the current page'], + ["enableMenu", "Enable Menu Bar", "Enables the application menu bar. Press ALT to toggle visibility."], [ "openLinksWithElectron", "Open Links in app (experimental)", "Opens links in a new Vesktop window instead of your web browser" - ], - ["staticTitle", "Static Title", 'Makes the window title "Vesktop" instead of changing to the current page'], - ["enableMenu", "Enable Menu Bar", "Enables the application menu bar. Press ALT to toggle visibility."] + ] ]; const switches = allSwitches.filter(isTruthy); diff --git a/src/renderer/patches/platformClass.tsx b/src/renderer/patches/platformClass.tsx index da71127..5605ab8 100644 --- a/src/renderer/patches/platformClass.tsx +++ b/src/renderer/patches/platformClass.tsx @@ -4,6 +4,9 @@ * Copyright (c) 2023 Vendicated and Vencord contributors */ +import { Settings } from "renderer/settings"; +import { isMac, isWindows } from "renderer/utils"; + import { addPatch } from "./shared"; addPatch({ @@ -18,5 +21,9 @@ addPatch({ } ], - getPlatformClass: () => (navigator.platform.toLowerCase().startsWith("mac") ? "platform-osx" : "platform-web") + getPlatformClass() { + if (isMac) return "platform-osx"; + if (isWindows && Settings.store.discordWindowsTitleBar) return "platform-windows"; + return "platform-web"; + } }); diff --git a/src/renderer/patches/windowsTitleBar.tsx b/src/renderer/patches/windowsTitleBar.tsx index 8f7b977..708ec60 100644 --- a/src/renderer/patches/windowsTitleBar.tsx +++ b/src/renderer/patches/windowsTitleBar.tsx @@ -4,22 +4,27 @@ * Copyright (c) 2023 Vendicated and Vencord contributors */ +import { Settings } from "renderer/settings"; + 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}` - })) - ] - } - ] -}); +if (Settings.store.discordWindowsTitleBar) + addPatch({ + patches: [ + { + find: ".wordmarkWindows", + replacement: [ + { + // TODO: Fix eslint rule + // eslint-disable-next-line no-useless-escape + match: /case \i\.\i\.WINDOWS:/, + replace: 'case "WEB":' + }, + ...["close", "minimize", "maximize"].map(op => ({ + match: new RegExp(String.raw`\i\.default\.${op}\b`), + replace: `VesktopNative.win.${op}` + })) + ] + } + ] + }); diff --git a/src/shared/settings.d.ts b/src/shared/settings.d.ts index e387351..a9a0dec 100644 --- a/src/shared/settings.d.ts +++ b/src/shared/settings.d.ts @@ -7,21 +7,23 @@ import type { Rectangle } from "electron"; export interface Settings { - transparencyOption?: "none" | "mica" | "tabbed" | "acrylic"; - maximized?: boolean; - minimized?: boolean; - windowBounds?: Rectangle; discordBranch?: "stable" | "canary" | "ptb"; - openLinksWithElectron?: boolean; vencordDir?: string; - disableMinSize?: boolean; + transparencyOption?: "none" | "mica" | "tabbed" | "acrylic"; tray?: boolean; minimizeToTray?: boolean; - skippedUpdate?: string; + openLinksWithElectron?: boolean; staticTitle?: boolean; enableMenu?: boolean; arRPC?: boolean; appBadge?: boolean; + discordWindowsTitleBar?: boolean; + maximized?: boolean; + minimized?: boolean; + windowBounds?: Rectangle; + disableMinSize?: boolean; + + skippedUpdate?: string; firstLaunch?: boolean; }