feat: add hide menu bar items on macOS (#50)
Co-authored-by: V <vendicated@riseup.net>
This commit is contained in:
parent
13d87dc85e
commit
72f83c3ac4
2 changed files with 74 additions and 49 deletions
|
@ -4,9 +4,10 @@
|
||||||
* Copyright (c) 2023 Vendicated and Vencord contributors
|
* Copyright (c) 2023 Vendicated and Vencord contributors
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { app, BrowserWindow, BrowserWindowConstructorOptions, Menu, Tray } from "electron";
|
import { app, BrowserWindow, BrowserWindowConstructorOptions, Menu, MenuItemConstructorOptions, Tray } from "electron";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import { IpcEvents } from "shared/IpcEvents";
|
import { IpcEvents } from "shared/IpcEvents";
|
||||||
|
import { isTruthy } from "shared/utils/guards";
|
||||||
import { once } from "shared/utils/once";
|
import { once } from "shared/utils/once";
|
||||||
import type { SettingsStore } from "shared/utils/SettingsStore";
|
import type { SettingsStore } from "shared/utils/SettingsStore";
|
||||||
|
|
||||||
|
@ -105,60 +106,71 @@ function initTray(win: BrowserWindow) {
|
||||||
|
|
||||||
function initMenuBar(win: BrowserWindow) {
|
function initMenuBar(win: BrowserWindow) {
|
||||||
const isWindows = process.platform === "win32";
|
const isWindows = process.platform === "win32";
|
||||||
|
const isDarwin = process.platform === "darwin";
|
||||||
const wantCtrlQ = !isWindows || VencordSettings.store.winCtrlQ;
|
const wantCtrlQ = !isWindows || VencordSettings.store.winCtrlQ;
|
||||||
|
|
||||||
|
const subMenu = [
|
||||||
|
{
|
||||||
|
label: "About Vencord Desktop",
|
||||||
|
click: createAboutWindow
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Force Update Vencord",
|
||||||
|
async click() {
|
||||||
|
await downloadVencordFiles();
|
||||||
|
app.relaunch();
|
||||||
|
app.quit();
|
||||||
|
},
|
||||||
|
toolTip: "Vencord Desktop will automatically restart after this operation"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Relaunch",
|
||||||
|
accelerator: "CmdOrCtrl+Shift+R",
|
||||||
|
click() {
|
||||||
|
app.relaunch();
|
||||||
|
app.quit();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
isDarwin && {
|
||||||
|
label: "Hide",
|
||||||
|
role: "hide"
|
||||||
|
},
|
||||||
|
isDarwin && {
|
||||||
|
label: "Hide others",
|
||||||
|
role: "hideOthers"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Quit",
|
||||||
|
accelerator: wantCtrlQ ? "CmdOrCtrl+Q" : void 0,
|
||||||
|
visible: !isWindows,
|
||||||
|
role: "quit",
|
||||||
|
click() {
|
||||||
|
app.quit();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Quit",
|
||||||
|
accelerator: isWindows ? "Alt+F4" : void 0,
|
||||||
|
visible: isWindows,
|
||||||
|
role: "quit",
|
||||||
|
click() {
|
||||||
|
app.quit();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// See https://github.com/electron/electron/issues/14742 and https://github.com/electron/electron/issues/5256
|
||||||
|
{
|
||||||
|
label: "Zoom in (hidden, hack for Qwertz and others)",
|
||||||
|
accelerator: "CmdOrCtrl+=",
|
||||||
|
role: "zoomIn",
|
||||||
|
visible: false
|
||||||
|
}
|
||||||
|
] satisfies Array<MenuItemConstructorOptions | false>;
|
||||||
|
|
||||||
const menu = Menu.buildFromTemplate([
|
const menu = Menu.buildFromTemplate([
|
||||||
{
|
{
|
||||||
label: "Vencord Desktop",
|
label: "Vencord Desktop",
|
||||||
role: "appMenu",
|
role: "appMenu",
|
||||||
submenu: [
|
submenu: subMenu.filter(isTruthy)
|
||||||
{
|
|
||||||
label: "About Vencord Desktop",
|
|
||||||
click: createAboutWindow
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "Force Update Vencord",
|
|
||||||
async click() {
|
|
||||||
await downloadVencordFiles();
|
|
||||||
app.relaunch();
|
|
||||||
app.quit();
|
|
||||||
},
|
|
||||||
toolTip: "Vencord Desktop will automatically restart after this operation"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "Relaunch",
|
|
||||||
accelerator: "CmdOrCtrl+Shift+R",
|
|
||||||
click() {
|
|
||||||
app.relaunch();
|
|
||||||
app.quit();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "Quit",
|
|
||||||
accelerator: wantCtrlQ ? "CmdOrCtrl+Q" : void 0,
|
|
||||||
visible: !isWindows,
|
|
||||||
role: "quit",
|
|
||||||
click() {
|
|
||||||
app.quit();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "Quit",
|
|
||||||
accelerator: isWindows ? "Alt+F4" : void 0,
|
|
||||||
visible: isWindows,
|
|
||||||
role: "quit",
|
|
||||||
click() {
|
|
||||||
app.quit();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// See https://github.com/electron/electron/issues/14742 and https://github.com/electron/electron/issues/5256
|
|
||||||
{
|
|
||||||
label: "Zoom in (hidden, hack for Qwertz and others)",
|
|
||||||
accelerator: "CmdOrCtrl+=",
|
|
||||||
role: "zoomIn",
|
|
||||||
visible: false
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{ role: "fileMenu" },
|
{ role: "fileMenu" },
|
||||||
{ role: "editMenu" },
|
{ role: "editMenu" },
|
||||||
|
|
13
src/shared/utils/guards.ts
Normal file
13
src/shared/utils/guards.ts
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0
|
||||||
|
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
|
||||||
|
* Copyright (c) 2023 Vendicated and Vencord contributors
|
||||||
|
*/
|
||||||
|
|
||||||
|
export function isTruthy<T>(item: T): item is Exclude<T, 0 | "" | false | null | undefined> {
|
||||||
|
return Boolean(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isNonNullish<T>(item: T): item is Exclude<T, null | undefined> {
|
||||||
|
return item != null;
|
||||||
|
}
|
Loading…
Reference in a new issue