2024-08-27 07:03:43 +02:00
|
|
|
// Copyright 2024, Command Line Inc.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
import * as electron from "electron";
|
|
|
|
import { fireAndForget } from "../frontend/util/util";
|
|
|
|
import { unamePlatform } from "./platform";
|
|
|
|
import { updater } from "./updater";
|
|
|
|
|
|
|
|
type AppMenuCallbacks = {
|
|
|
|
createNewWaveWindow: () => Promise<void>;
|
|
|
|
relaunchBrowserWindows: () => Promise<void>;
|
|
|
|
};
|
|
|
|
|
2024-10-05 01:34:05 +02:00
|
|
|
function getWindowWebContents(window: electron.BaseWindow): electron.WebContents {
|
|
|
|
if (window == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (window instanceof electron.BrowserWindow) {
|
|
|
|
return window.webContents;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2024-08-27 07:03:43 +02:00
|
|
|
function getAppMenu(callbacks: AppMenuCallbacks): Electron.Menu {
|
|
|
|
const fileMenu: Electron.MenuItemConstructorOptions[] = [
|
|
|
|
{
|
|
|
|
label: "New Window",
|
|
|
|
accelerator: "CommandOrControl+Shift+N",
|
|
|
|
click: () => fireAndForget(callbacks.createNewWaveWindow),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: "close",
|
|
|
|
accelerator: "", // clear the accelerator
|
|
|
|
click: () => {
|
|
|
|
electron.BrowserWindow.getFocusedWindow()?.close();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const appMenu: Electron.MenuItemConstructorOptions[] = [
|
|
|
|
{
|
|
|
|
label: "About Wave Terminal",
|
|
|
|
click: (_, window) => {
|
2024-10-05 01:34:05 +02:00
|
|
|
getWindowWebContents(window)?.send("menu-item-about");
|
2024-08-27 07:03:43 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Check for Updates",
|
|
|
|
click: () => {
|
|
|
|
fireAndForget(() => updater?.checkForUpdates(true));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "separator",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
if (unamePlatform === "darwin") {
|
|
|
|
appMenu.push(
|
|
|
|
{
|
|
|
|
role: "services",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "separator",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: "hide",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: "hideOthers",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "separator",
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
appMenu.push({
|
|
|
|
role: "quit",
|
|
|
|
});
|
|
|
|
const editMenu: Electron.MenuItemConstructorOptions[] = [
|
|
|
|
{
|
|
|
|
role: "undo",
|
|
|
|
accelerator: unamePlatform === "darwin" ? "Command+Z" : "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: "redo",
|
|
|
|
accelerator: unamePlatform === "darwin" ? "Command+Shift+Z" : "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "separator",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: "cut",
|
|
|
|
accelerator: unamePlatform === "darwin" ? "Command+X" : "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: "copy",
|
|
|
|
accelerator: unamePlatform === "darwin" ? "Command+C" : "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: "paste",
|
|
|
|
accelerator: unamePlatform === "darwin" ? "Command+V" : "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: "pasteAndMatchStyle",
|
|
|
|
accelerator: unamePlatform === "darwin" ? "Command+Shift+V" : "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: "delete",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: "selectAll",
|
|
|
|
accelerator: unamePlatform === "darwin" ? "Command+A" : "",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const viewMenu: Electron.MenuItemConstructorOptions[] = [
|
|
|
|
{
|
|
|
|
role: "forceReload",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Relaunch All Windows",
|
|
|
|
click: () => {
|
|
|
|
callbacks.relaunchBrowserWindows();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: "toggleDevTools",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "separator",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Actual Size",
|
|
|
|
accelerator: "CommandOrControl+0",
|
|
|
|
click: (_, window) => {
|
2024-10-05 01:34:05 +02:00
|
|
|
getWindowWebContents(window)?.setZoomFactor(1);
|
2024-08-27 07:03:43 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Zoom In",
|
|
|
|
accelerator: "CommandOrControl+=",
|
|
|
|
click: (_, window) => {
|
2024-10-05 01:34:05 +02:00
|
|
|
const wc = getWindowWebContents(window);
|
|
|
|
if (wc == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wc.setZoomFactor(wc.getZoomFactor() + 0.2);
|
2024-08-27 07:03:43 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Zoom In (hidden)",
|
|
|
|
accelerator: "CommandOrControl+Shift+=",
|
|
|
|
click: (_, window) => {
|
2024-10-05 01:34:05 +02:00
|
|
|
const wc = getWindowWebContents(window);
|
|
|
|
if (wc == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wc.setZoomFactor(wc.getZoomFactor() + 0.2);
|
2024-08-27 07:03:43 +02:00
|
|
|
},
|
|
|
|
visible: false,
|
|
|
|
acceleratorWorksWhenHidden: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Zoom Out",
|
|
|
|
accelerator: "CommandOrControl+-",
|
|
|
|
click: (_, window) => {
|
2024-10-05 01:34:05 +02:00
|
|
|
const wc = getWindowWebContents(window);
|
|
|
|
if (wc == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wc.setZoomFactor(wc.getZoomFactor() - 0.2);
|
2024-08-27 07:03:43 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "separator",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: "togglefullscreen",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const windowMenu: Electron.MenuItemConstructorOptions[] = [
|
|
|
|
{ role: "minimize", accelerator: "" },
|
|
|
|
{ role: "zoom" },
|
|
|
|
{ type: "separator" },
|
|
|
|
{ role: "front" },
|
|
|
|
{ type: "separator" },
|
|
|
|
{ role: "window" },
|
|
|
|
];
|
|
|
|
const menuTemplate: Electron.MenuItemConstructorOptions[] = [
|
|
|
|
{
|
|
|
|
role: "appMenu",
|
|
|
|
submenu: appMenu,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: "fileMenu",
|
|
|
|
submenu: fileMenu,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: "editMenu",
|
|
|
|
submenu: editMenu,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: "viewMenu",
|
|
|
|
submenu: viewMenu,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: "windowMenu",
|
|
|
|
submenu: windowMenu,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
return electron.Menu.buildFromTemplate(menuTemplate);
|
|
|
|
}
|
|
|
|
|
|
|
|
export { getAppMenu };
|