Port Discord's windows title bar (#86)

This commit is contained in:
V 2023-08-07 00:23:27 +02:00 committed by GitHub
parent 57006e7e52
commit 3108de7c79
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 81 additions and 16 deletions

View file

@ -73,7 +73,19 @@ ipcMain.handle(IpcEvents.FOCUS, () => {
}); });
ipcMain.handle(IpcEvents.CLOSE, e => { ipcMain.handle(IpcEvents.CLOSE, e => {
e.sender.close(); mainWin.close();
});
ipcMain.handle(IpcEvents.MINIMIZE, e => {
mainWin.minimize();
});
ipcMain.handle(IpcEvents.MAXIMIZE, e => {
if (mainWin.isMaximized()) {
mainWin.unmaximize();
} else {
mainWin.maximize();
}
}); });
ipcMain.handle(IpcEvents.SPELLCHECK_SET_LANGUAGES, (_, languages: string[]) => { ipcMain.handle(IpcEvents.SPELLCHECK_SET_LANGUAGES, (_, languages: string[]) => {

View file

@ -315,8 +315,11 @@ function createMainWindow() {
removeSettingsListeners(); removeSettingsListeners();
removeVencordSettingsListeners(); removeVencordSettingsListeners();
const { staticTitle, transparencyOption, enableMenu } = Settings.store; const { staticTitle, transparencyOption, enableMenu, discordWindowsTitleBar } = Settings.store;
const { frameless, macosTranslucency } = VencordSettings.store; const { frameless, macosTranslucency } = VencordSettings.store;
const noFrame = frameless === true || (process.platform === "win32" && discordWindowsTitleBar === true);
const win = (mainWin = new BrowserWindow({ const win = (mainWin = new BrowserWindow({
show: false, show: false,
webPreferences: { webPreferences: {
@ -328,7 +331,7 @@ function createMainWindow() {
spellcheck: true spellcheck: true
}, },
icon: ICON_PATH, icon: ICON_PATH,
frame: frameless !== true, frame: !noFrame,
...(transparencyOption && transparencyOption !== "none" ...(transparencyOption && transparencyOption !== "none"
? { ? {
backgroundColor: "#00000000", backgroundColor: "#00000000",

View file

@ -51,7 +51,10 @@ export const VesktopNative = {
addToDictionary: (word: string) => invoke<void>(IpcEvents.SPELLCHECK_ADD_TO_DICTIONARY, word) addToDictionary: (word: string) => invoke<void>(IpcEvents.SPELLCHECK_ADD_TO_DICTIONARY, word)
}, },
win: { win: {
focus: () => invoke<void>(IpcEvents.FOCUS) focus: () => invoke<void>(IpcEvents.FOCUS),
close: () => invoke<void>(IpcEvents.CLOSE),
minimize: () => invoke<void>(IpcEvents.MINIMIZE),
maximize: () => invoke<void>(IpcEvents.MAXIMIZE)
}, },
capturer: { capturer: {
getLargeThumbnail: (id: string) => invoke<string>(IpcEvents.CAPTURER_GET_LARGE_THUMBNAIL, id) getLargeThumbnail: (id: string) => invoke<string>(IpcEvents.CAPTURER_GET_LARGE_THUMBNAIL, id)

View file

@ -10,7 +10,7 @@ import { Margins } from "@vencord/types/utils";
import { Button, Forms, Select, Switch, Text, useState } from "@vencord/types/webpack/common"; import { Button, Forms, Select, Switch, Text, useState } from "@vencord/types/webpack/common";
import { setBadge } from "renderer/appBadge"; import { setBadge } from "renderer/appBadge";
import { useSettings } from "renderer/settings"; import { useSettings } from "renderer/settings";
import { isMac } from "renderer/utils"; import { isMac, isWindows } from "renderer/utils";
import { isTruthy } from "shared/utils/guards"; import { isTruthy } from "shared/utils/guards";
export default function SettingsUi() { export default function SettingsUi() {
@ -21,6 +21,11 @@ export default function SettingsUi() {
const [autoStartEnabled, setAutoStartEnabled] = useState(autostart.isEnabled()); const [autoStartEnabled, setAutoStartEnabled] = useState(autostart.isEnabled());
const allSwitches: Array<false | [keyof typeof Settings, string, string, boolean?, (() => boolean)?]> = [ const allSwitches: Array<false | [keyof typeof Settings, string, string, boolean?, (() => 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 && ["tray", "Tray Icon", "Add a tray icon for Vesktop", true],
!isMac && [ !isMac && [
"minimizeToTray", "minimizeToTray",
@ -35,13 +40,13 @@ export default function SettingsUi() {
"Disable minimum window size", "Disable minimum window size",
"Allows you to make the window as small as your heart desires" "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", "openLinksWithElectron",
"Open Links in app (experimental)", "Open Links in app (experimental)",
"Opens links in a new Vesktop window instead of your web browser" "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); const switches = allSwitches.filter(isTruthy);

View file

@ -7,3 +7,4 @@
// TODO: Possibly auto generate glob if we have more patches in the future // TODO: Possibly auto generate glob if we have more patches in the future
import "./spellCheck"; import "./spellCheck";
import "./platformClass"; import "./platformClass";
import "./windowsTitleBar";

View file

@ -4,6 +4,9 @@
* Copyright (c) 2023 Vendicated and Vencord contributors * Copyright (c) 2023 Vendicated and Vencord contributors
*/ */
import { Settings } from "renderer/settings";
import { isMac, isWindows } from "renderer/utils";
import { addPatch } from "./shared"; import { addPatch } from "./shared";
addPatch({ 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";
}
}); });

View file

@ -0,0 +1,30 @@
/*
* 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 { Settings } from "renderer/settings";
import { addPatch } from "./shared";
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}`
}))
]
}
]
});

View file

@ -16,6 +16,8 @@ export const enum IpcEvents {
RELAUNCH = "VCD_RELAUNCH", RELAUNCH = "VCD_RELAUNCH",
CLOSE = "VCD_CLOSE", CLOSE = "VCD_CLOSE",
FOCUS = "VCD_FOCUS", FOCUS = "VCD_FOCUS",
MINIMIZE = "VCD_MINIMIZE",
MAXIMIZE = "VCD_MAXIMIZE",
SHOW_ITEM_IN_FOLDER = "VCD_SHOW_ITEM_IN_FOLDER", SHOW_ITEM_IN_FOLDER = "VCD_SHOW_ITEM_IN_FOLDER",
GET_SETTINGS = "VCD_GET_SETTINGS", GET_SETTINGS = "VCD_GET_SETTINGS",

View file

@ -7,21 +7,23 @@
import type { Rectangle } from "electron"; import type { Rectangle } from "electron";
export interface Settings { export interface Settings {
transparencyOption?: "none" | "mica" | "tabbed" | "acrylic";
maximized?: boolean;
minimized?: boolean;
windowBounds?: Rectangle;
discordBranch?: "stable" | "canary" | "ptb"; discordBranch?: "stable" | "canary" | "ptb";
openLinksWithElectron?: boolean;
vencordDir?: string; vencordDir?: string;
disableMinSize?: boolean; transparencyOption?: "none" | "mica" | "tabbed" | "acrylic";
tray?: boolean; tray?: boolean;
minimizeToTray?: boolean; minimizeToTray?: boolean;
skippedUpdate?: string; openLinksWithElectron?: boolean;
staticTitle?: boolean; staticTitle?: boolean;
enableMenu?: boolean; enableMenu?: boolean;
arRPC?: boolean; arRPC?: boolean;
appBadge?: boolean; appBadge?: boolean;
discordWindowsTitleBar?: boolean;
maximized?: boolean;
minimized?: boolean;
windowBounds?: Rectangle;
disableMinSize?: boolean;
skippedUpdate?: string;
firstLaunch?: boolean; firstLaunch?: boolean;
} }