Add custom menu
This commit is contained in:
parent
019f0a2023
commit
24aaf68184
|
|
@ -13,6 +13,7 @@ import { terminalManager } from "./pty";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import started from "electron-squirrel-startup";
|
import started from "electron-squirrel-startup";
|
||||||
import { setupLangServer } from "./langserver";
|
import { setupLangServer } from "./langserver";
|
||||||
|
import { setMenu } from "./menu";
|
||||||
/// <reference types="./forge-vite-env.d.ts" />
|
/// <reference types="./forge-vite-env.d.ts" />
|
||||||
|
|
||||||
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
|
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
|
||||||
|
|
@ -21,6 +22,7 @@ if (started) {
|
||||||
}
|
}
|
||||||
|
|
||||||
app.setName("miller");
|
app.setName("miller");
|
||||||
|
setMenu();
|
||||||
|
|
||||||
const createWindow = () => {
|
const createWindow = () => {
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,114 @@
|
||||||
|
const { shell } = require("electron/common");
|
||||||
|
const { app, Menu } = require("electron/main");
|
||||||
|
|
||||||
|
const isMac = process.platform === "darwin";
|
||||||
|
const menuTemplate = [
|
||||||
|
// { role: 'appMenu' }
|
||||||
|
...(isMac
|
||||||
|
? [
|
||||||
|
{
|
||||||
|
label: app.name,
|
||||||
|
submenu: [
|
||||||
|
{ role: "about" },
|
||||||
|
{ type: "separator" },
|
||||||
|
{ role: "services" },
|
||||||
|
{ type: "separator" },
|
||||||
|
{ role: "hide" },
|
||||||
|
{ role: "hideOthers" },
|
||||||
|
{ role: "unhide" },
|
||||||
|
{ type: "separator" },
|
||||||
|
{ role: "quit" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: []),
|
||||||
|
// { role: 'fileMenu' }
|
||||||
|
{
|
||||||
|
label: "File",
|
||||||
|
submenu: [isMac ? { role: "close" } : { role: "quit" }],
|
||||||
|
},
|
||||||
|
// { role: 'editMenu' }
|
||||||
|
// {
|
||||||
|
// label: "Edit",
|
||||||
|
// submenu: [
|
||||||
|
// { role: "undo" },
|
||||||
|
// { role: "redo" },
|
||||||
|
// { type: "separator" },
|
||||||
|
// { role: "cut" },
|
||||||
|
// { role: "copy" },
|
||||||
|
// { role: "paste" },
|
||||||
|
// ...(isMac
|
||||||
|
// ? [
|
||||||
|
// { role: "pasteAndMatchStyle" },
|
||||||
|
// { role: "delete" },
|
||||||
|
// { role: "selectAll" },
|
||||||
|
// { type: "separator" },
|
||||||
|
// {
|
||||||
|
// label: "Speech",
|
||||||
|
// submenu: [
|
||||||
|
// { role: "startSpeaking" },
|
||||||
|
// { role: "stopSpeaking" },
|
||||||
|
// ],
|
||||||
|
// },
|
||||||
|
// ]
|
||||||
|
// : [
|
||||||
|
// { role: "delete" },
|
||||||
|
// { type: "separator" },
|
||||||
|
// { role: "selectAll" },
|
||||||
|
// ]),
|
||||||
|
// ],
|
||||||
|
// },
|
||||||
|
// { role: 'viewMenu' }
|
||||||
|
{
|
||||||
|
label: "View",
|
||||||
|
submenu: [
|
||||||
|
{ role: "toggleDevTools" },
|
||||||
|
{ type: "separator" },
|
||||||
|
{ role: "resetZoom" },
|
||||||
|
{ role: "zoomIn" },
|
||||||
|
{ role: "zoomOut" },
|
||||||
|
{ type: "separator" },
|
||||||
|
{ role: "togglefullscreen" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
// { role: 'windowMenu' }
|
||||||
|
{
|
||||||
|
label: "Window",
|
||||||
|
submenu: [
|
||||||
|
{ role: "minimize" },
|
||||||
|
{ role: "zoom" },
|
||||||
|
...(isMac
|
||||||
|
? [
|
||||||
|
{ type: "separator" },
|
||||||
|
{ role: "front" },
|
||||||
|
{ type: "separator" },
|
||||||
|
{ role: "window" },
|
||||||
|
]
|
||||||
|
: []),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: "help",
|
||||||
|
submenu: [
|
||||||
|
{
|
||||||
|
label: "Learn More",
|
||||||
|
click: async () => {
|
||||||
|
const { shell } = require("electron");
|
||||||
|
await shell.openExternal("https://electronjs.org");
|
||||||
|
},
|
||||||
|
},
|
||||||
|
...(!isMac
|
||||||
|
? [
|
||||||
|
{
|
||||||
|
role: "about",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: []),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export function setMenu() {
|
||||||
|
const menu = Menu.buildFromTemplate(menuTemplate);
|
||||||
|
Menu.setApplicationMenu(menu);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue