MCPcopy Index your code
hub / github.com/vercel/hyper / createMenu

Function createMenu

app/menus/menu.ts:23–73  ·  view source on GitHub ↗
(
  createWindow: (fn?: (win: BrowserWindow) => void, options?: Record<string, any>) => BrowserWindow,
  getLoadedPluginVersions: () => {name: string; version: string}[]
)

Source from the content-addressed store, hash-verified

21let menu_: Menu;
22
23export const createMenu = (
24 createWindow: (fn?: (win: BrowserWindow) => void, options?: Record<string, any>) => BrowserWindow,
25 getLoadedPluginVersions: () => {name: string; version: string}[]
26) => {
27 const config = getConfig();
28 // We take only first shortcut in array for each command
29 const allCommandKeys = getDecoratedKeymaps();
30 const commandKeys = Object.keys(allCommandKeys).reduce((result: Record<string, string>, command) => {
31 result[command] = allCommandKeys[command][0];
32 return result;
33 }, {});
34
35 let updateChannel = 'stable';
36
37 if (config?.updateChannel && config.updateChannel === 'canary') {
38 updateChannel = 'canary';
39 }
40
41 const showAbout = () => {
42 const loadedPlugins = getLoadedPluginVersions();
43 const pluginList =
44 loadedPlugins.length === 0 ? 'none' : loadedPlugins.map((plugin) => `\n ${plugin.name} (${plugin.version})`);
45
46 const rendererCounts = Object.values(getRendererTypes()).reduce((acc: Record<string, number>, type) => {
47 acc[type] = acc[type] ? acc[type] + 1 : 1;
48 return acc;
49 }, {});
50 const renderers = Object.entries(rendererCounts)
51 .map(([type, count]) => type + (count > 1 ? ` (${count})` : ''))
52 .join(', ');
53
54 void dialog.showMessageBox({
55 title: `About ${appName}`,
56 message: `${appName} ${appVersion} (${updateChannel})`,
57 detail: `Renderers: ${renderers}\nPlugins: ${pluginList}\n\nCreated by Guillermo Rauch\nCopyright © 2022 Vercel, Inc.`,
58 buttons: [],
59 icon: icon as any
60 });
61 };
62 const menu = [
63 ...(process.platform === 'darwin' ? [darwinMenu(commandKeys, execCommand, showAbout)] : []),
64 shellMenu(commandKeys, execCommand),
65 editMenu(commandKeys, execCommand),
66 viewMenu(commandKeys, execCommand),
67 toolsMenu(commandKeys, execCommand),
68 windowMenu(commandKeys, execCommand),
69 helpMenu(commandKeys, showAbout)
70 ];
71
72 return menu;
73};
74
75export const buildMenu = (template: Electron.MenuItemConstructorOptions[]): Electron.Menu => {
76 menu_ = Menu.buildFromTemplate(template);

Callers

nothing calls this directly

Calls 3

getConfigFunction · 0.90
getDecoratedKeymapsFunction · 0.90
reduceMethod · 0.80

Tested by

no test coverage detected