Files
lens/src/main/menu/menu.ts
T
Janne SavolainenandMikko Aspiala 5c8ca2c038 Implement a lot of technical requirements for behavioural unit tests
Note: the crux of this was to make routing env-agnostic, and not based on URLs as magic strings, but instead something type-enforced.

Note: extension-based routes comply to same exact interface by "late-registering" their routes when installed. Routes are just injectables.

Note: another chunk of global shared state is no more.

Note: a lot of explicit side effects have been cornered to injectables.

Note: a lot of stuff has become reactive as part if this.

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
2022-03-31 15:13:26 +03:00

48 lines
1.3 KiB
TypeScript

/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { app, BrowserWindow, dialog, Menu } from "electron";
import { autorun } from "mobx";
import { appName, isWindows, productName } from "../../common/vars";
import packageJson from "../../../package.json";
import type { MenuItemsOpts } from "./get-app-menu-items.injectable";
export type MenuTopId = "mac" | "file" | "edit" | "view" | "help";
export function initMenu(
getAppMenuItems: () => MenuItemsOpts[],
) {
return autorun(() => buildMenu(getAppMenuItems), {
delay: 100,
});
}
export function showAbout(browserWindow: BrowserWindow) {
const appInfo = [
`${appName}: ${app.getVersion()}`,
`Electron: ${process.versions.electron}`,
`Chrome: ${process.versions.chrome}`,
`Node: ${process.versions.node}`,
packageJson.copyright,
];
dialog.showMessageBoxSync(browserWindow, {
title: `${isWindows ? " ".repeat(2) : ""}${appName}`,
type: "info",
buttons: ["Close"],
message: productName,
detail: appInfo.join("\r\n"),
});
}
export function buildMenu(
getAppMenuItems: () => MenuItemsOpts[],
) {
const menuItems = getAppMenuItems();
Menu.setApplicationMenu(
Menu.buildFromTemplate(menuItems),
);
}