feat: add hide menu bar items on macOS (#50)

Co-authored-by: V <vendicated@riseup.net>
This commit is contained in:
Ryan Cao 2023-07-11 19:35:15 +00:00 committed by GitHub
parent 13d87dc85e
commit 72f83c3ac4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 74 additions and 49 deletions

View file

@ -4,9 +4,10 @@
* 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 { IpcEvents } from "shared/IpcEvents";
import { isTruthy } from "shared/utils/guards";
import { once } from "shared/utils/once";
import type { SettingsStore } from "shared/utils/SettingsStore";
@ -105,13 +106,10 @@ function initTray(win: BrowserWindow) {
function initMenuBar(win: BrowserWindow) {
const isWindows = process.platform === "win32";
const isDarwin = process.platform === "darwin";
const wantCtrlQ = !isWindows || VencordSettings.store.winCtrlQ;
const menu = Menu.buildFromTemplate([
{
label: "Vencord Desktop",
role: "appMenu",
submenu: [
const subMenu = [
{
label: "About Vencord Desktop",
click: createAboutWindow
@ -133,6 +131,14 @@ function initMenuBar(win: BrowserWindow) {
app.quit();
}
},
isDarwin && {
label: "Hide",
role: "hide"
},
isDarwin && {
label: "Hide others",
role: "hideOthers"
},
{
label: "Quit",
accelerator: wantCtrlQ ? "CmdOrCtrl+Q" : void 0,
@ -158,7 +164,13 @@ function initMenuBar(win: BrowserWindow) {
role: "zoomIn",
visible: false
}
]
] satisfies Array<MenuItemConstructorOptions | false>;
const menu = Menu.buildFromTemplate([
{
label: "Vencord Desktop",
role: "appMenu",
submenu: subMenu.filter(isTruthy)
},
{ role: "fileMenu" },
{ role: "editMenu" },

View 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;
}