From 0e19f3e250aa817d6d9c83deea095d261a2f942d Mon Sep 17 00:00:00 2001 From: Lauri Nevala Date: Wed, 12 Aug 2020 09:13:28 +0300 Subject: [PATCH] Revert system menu layout (#671) --- src/main/menu.ts | 129 ++++++++++++++++++++++++++++++----------------- 1 file changed, 84 insertions(+), 45 deletions(-) diff --git a/src/main/menu.ts b/src/main/menu.ts index c634631925..f626bfb35b 100644 --- a/src/main/menu.ts +++ b/src/main/menu.ts @@ -15,13 +15,17 @@ export function initMenu(windowManager: WindowManager) { } export function buildMenu(windowManager: WindowManager) { - function macOnly(menuItems: MenuItemConstructorOptions[]) { - if (!isMac) return []; + function ignoreOnMac(menuItems: MenuItemConstructorOptions[]) { + if (isMac) return []; return menuItems; } function activeClusterOnly(menuItems: MenuItemConstructorOptions[]) { - if (!windowManager.activeClusterId) return []; + if (!windowManager.activeClusterId) { + menuItems.forEach(item => { + item.enabled = false + }); + } return menuItems; } @@ -34,8 +38,57 @@ export function buildMenu(windowManager: WindowManager) { }) } + function showAbout(browserWindow: BrowserWindow) { + const appInfo = [ + `${appName}: ${app.getVersion()}`, + `Electron: ${process.versions.electron}`, + `Chrome: ${process.versions.chrome}`, + `Copyright 2020 Lakend Labs, Inc.`, + ] + dialog.showMessageBoxSync(browserWindow, { + title: `${isWindows ? " ".repeat(2) : ""}${appName}`, + type: "info", + buttons: ["Close"], + message: `Lens`, + detail: appInfo.join("\r\n") + }) + } + + const mt: MenuItemConstructorOptions[] = []; + + const macAppMenu: MenuItemConstructorOptions = { + label: app.getName(), + submenu: [ + { + label: "About Lens", + click(menuItem: MenuItem, browserWindow: BrowserWindow) { + showAbout(browserWindow) + } + }, + { type: 'separator' }, + { + label: 'Preferences', + click() { + navigate(preferencesURL()) + } + }, + { type: 'separator' }, + { role: 'services' }, + { type: 'separator' }, + { role: 'hide' }, + { role: 'hideOthers' }, + { role: 'unhide' }, + { type: 'separator' }, + { role: 'quit' } + ] + }; + + if (isMac) { + mt.push(macAppMenu); + } + const fileMenu: MenuItemConstructorOptions = { - label: isMac ? app.getName() : "File", + label: "File", submenu: [ { label: 'Add Cluster', @@ -51,25 +104,20 @@ export function buildMenu(windowManager: WindowManager) { } } ]), - { type: 'separator' }, - { - label: 'Preferences', - click() { - navigate(preferencesURL()) - } - }, - ...macOnly([ + ...ignoreOnMac([ { type: 'separator' }, - { role: 'services' }, + { + label: 'Preferences', + click() { + navigate(preferencesURL()) + } + }, { type: 'separator' }, - { role: 'hide' }, - { role: 'hideOthers' }, - { role: 'unhide' }, - ]), - { type: 'separator' }, - { role: 'quit' } + { role: 'quit' } + ]) ] }; + mt.push(fileMenu) const editMenu: MenuItemConstructorOptions = { label: 'Edit', @@ -85,7 +133,7 @@ export function buildMenu(windowManager: WindowManager) { { role: 'selectAll' }, ] }; - + mt.push(editMenu) const viewMenu: MenuItemConstructorOptions = { label: 'View', submenu: [ @@ -128,16 +176,11 @@ export function buildMenu(windowManager: WindowManager) { { role: 'togglefullscreen' } ] }; + mt.push(viewMenu) const helpMenu: MenuItemConstructorOptions = { role: 'help', submenu: [ - { - label: "What's new?", - click() { - navigate(whatsNewURL()) - }, - }, { label: "License", click: async () => { @@ -157,27 +200,23 @@ export function buildMenu(windowManager: WindowManager) { }, }, { - label: "About Lens", - click(menuItem: MenuItem, browserWindow: BrowserWindow) { - const appInfo = [ - `${appName}: ${app.getVersion()}`, - `Electron: ${process.versions.electron}`, - `Chrome: ${process.versions.chrome}`, - `Copyright 2020 Lakend Labs, Inc.`, - ] - dialog.showMessageBoxSync(browserWindow, { - title: `${isWindows ? " ".repeat(2) : ""}${appName}`, - type: "info", - buttons: ["Close"], - message: `Lens`, - detail: appInfo.join("\r\n") - }) + label: "What's new?", + click() { + navigate(whatsNewURL()) + }, + }, + ...ignoreOnMac([ + { + label: "About Lens", + click(menuItem: MenuItem, browserWindow: BrowserWindow) { + showAbout(browserWindow) + } } - } + ]) ] }; - Menu.setApplicationMenu(Menu.buildFromTemplate([ - fileMenu, editMenu, viewMenu, helpMenu - ])); + mt.push(helpMenu) + + Menu.setApplicationMenu(Menu.buildFromTemplate(mt)); }