From 954d51ce8816c8b139017cccd9d98a877ee018c1 Mon Sep 17 00:00:00 2001 From: juggernautjp Date: Sun, 13 Jun 2021 00:39:35 +0900 Subject: [PATCH] Fix menu bug with atom-i18n "Check for Update" and "Reopen Project" menu dose not work. --- src/main-process/application-menu.js | 18 ++++++++++++++---- src/menu-helpers.js | 7 +++++-- src/menu-manager.coffee | 10 +++++++--- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/main-process/application-menu.js b/src/main-process/application-menu.js index e2faa5e76..3accd14a6 100644 --- a/src/main-process/application-menu.js +++ b/src/main-process/application-menu.js @@ -115,16 +115,20 @@ module.exports = class ApplicationMenu { showUpdateMenuItem(state) { const items = this.flattenMenuItems(this.menu); const checkForUpdateItem = items.find( - ({ label }) => label === 'Check for Update' + // ({ label }) => label === 'Check for Update' + ({ id }) => id === 'Check for Update' ); const checkingForUpdateItem = items.find( - ({ label }) => label === 'Checking for Update' + // ({ label }) => label === 'Checking for Update' + ({ id }) => id === 'Checking for Update' ); const downloadingUpdateItem = items.find( - ({ label }) => label === 'Downloading Update' + // ({ label }) => label === 'Downloading Update' + ({ id }) => id === 'Downloading Update' ); const installUpdateItem = items.find( - ({ label }) => label === 'Restart and Install Update' + // ({ label }) => label === 'Restart and Install Update' + ({ id }) => id === 'Restart and Install Update' ); if ( @@ -165,13 +169,16 @@ module.exports = class ApplicationMenu { return [ { label: 'Atom', + id: 'Atom', submenu: [ { label: 'Check for Update', + id: 'Check for Update', metadata: { autoUpdate: true } }, { label: 'Reload', + id: 'Reload', accelerator: 'Command+R', click: () => { const window = this.focusedWindow(); @@ -180,6 +187,7 @@ module.exports = class ApplicationMenu { }, { label: 'Close Window', + id: 'Close Window', accelerator: 'Command+Shift+W', click: () => { const window = this.focusedWindow(); @@ -188,6 +196,7 @@ module.exports = class ApplicationMenu { }, { label: 'Toggle Dev Tools', + id: 'Toggle Dev Tools', accelerator: 'Command+Alt+I', click: () => { const window = this.focusedWindow(); @@ -196,6 +205,7 @@ module.exports = class ApplicationMenu { }, { label: 'Quit', + id: 'Quit', accelerator: 'Command+Q', click: () => app.quit() } diff --git a/src/menu-helpers.js b/src/menu-helpers.js index c9d87a625..d1c6efb15 100644 --- a/src/menu-helpers.js +++ b/src/menu-helpers.js @@ -53,14 +53,16 @@ function unmerge(menu, item) { } } -function findMatchingItemIndex(menu, { type, label, submenu }) { +// function findMatchingItemIndex(menu, { type, label, submenu }) { +function findMatchingItemIndex(menu, { type, id, submenu }) { if (type === 'separator') { return -1; } for (let index = 0; index < menu.length; index++) { const item = menu[index]; if ( - normalizeLabel(item.label) === normalizeLabel(label) && + // normalizeLabel(item.label) === normalizeLabel(label) && + item.id === id && (item.submenu != null) === (submenu != null) ) { return index; @@ -93,6 +95,7 @@ function cloneMenuItem(item) { 'beforeGroupContaining', 'afterGroupContaining' ); + if (item.id === null || item.id === undefined) { item.id = normalizeLabel(item.label) } if (item.submenu != null) { item.submenu = item.submenu.map(submenuItem => cloneMenuItem(submenuItem)); } diff --git a/src/menu-manager.coffee b/src/menu-manager.coffee index aef708029..708e0a1a4 100644 --- a/src/menu-manager.coffee +++ b/src/menu-manager.coffee @@ -78,17 +78,20 @@ class MenuManager # atom.menu.add [ # { # label: 'Hello' - # submenu : [{label: 'World!', command: 'hello:world'}] + # submenu : [{label: 'World!', id: 'World!', command: 'hello:world'}] # } # ] # ``` # # * `items` An {Array} of menu item {Object}s containing the keys: - # * `label` The {String} menu label. + # * `label` The {String} menu label, which is used for localiztion (in `atom-i18n` package). # * `submenu` An optional {Array} of sub menu items. # * `command` An optional {String} command to trigger when the item is # clicked. # + # * `id` (internal) The {String} menu id, which is used only in javascript code, is not used in menu template. + # For further information on the above args, see [Electron MenuItem](https://www.electronjs.org/docs/api/menu-item#class-menuitem)). + # # Returns a {Disposable} on which `.dispose()` can be called to remove the # added menu items. add: (items) -> @@ -201,7 +204,8 @@ class MenuManager [] sortPackagesMenu: -> - packagesMenu = _.find @template, ({label}) -> MenuHelpers.normalizeLabel(label) is 'Packages' + # packagesMenu = _.find @template, ({label}) -> MenuHelpers.normalizeLabel(label) is 'Packages' + packagesMenu = _.find @template, ({id}) -> MenuHelpers.normalizeLabel(id) is 'Packages' return unless packagesMenu?.submenu? packagesMenu.submenu.sort (item1, item2) ->