(
createWindow: (fn?: (win: BrowserWindow) => void, options?: Record<string, any>) => BrowserWindow,
getLoadedPluginVersions: () => {name: string; version: string}[]
)
| 21 | let menu_: Menu; |
| 22 | |
| 23 | export 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 | |
| 75 | export const buildMenu = (template: Electron.MenuItemConstructorOptions[]): Electron.Menu => { |
| 76 | menu_ = Menu.buildFromTemplate(template); |
nothing calls this directly
no test coverage detected