From 5796ba32a64d3f4902d57b9a9e4a3631c1319e16 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Mon, 25 Jul 2016 15:21:46 -0700 Subject: [PATCH 1/4] Electron: Use default labels and accelerators Less code for us to maintain. This also gives us free internationalization in a future Electron version (they'll set the label dynamically based on the 'role') One slight regression with this change, but it will be fixed in a future Electron once this PR is merged: https://github.com/electron/electron/pull/6600 --- src/main/menu.js | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/src/main/menu.js b/src/main/menu.js index f8fac0c9..8e4ecac8 100644 --- a/src/main/menu.js +++ b/src/main/menu.js @@ -99,10 +99,6 @@ function getMenuTemplate () { type: 'separator' }, { - label: process.platform === 'win32' - ? 'Close' - : 'Close Window', - accelerator: 'CmdOrCtrl+W', role: 'close' } ] @@ -111,23 +107,16 @@ function getMenuTemplate () { label: 'Edit', submenu: [ { - label: 'Cut', - accelerator: 'CmdOrCtrl+X', role: 'cut' }, { - label: 'Copy', - accelerator: 'CmdOrCtrl+C', role: 'copy' }, { label: 'Paste Torrent Address', - accelerator: 'CmdOrCtrl+V', role: 'paste' }, { - label: 'Select All', - accelerator: 'CmdOrCtrl+A', role: 'selectall' }, { @@ -285,7 +274,6 @@ function getMenuTemplate () { label: config.APP_NAME, submenu: [ { - label: 'About ' + config.APP_NAME, role: 'about' }, { @@ -300,7 +288,6 @@ function getMenuTemplate () { type: 'separator' }, { - label: 'Services', role: 'services', submenu: [] }, @@ -308,17 +295,12 @@ function getMenuTemplate () { type: 'separator' }, { - label: 'Hide ' + config.APP_NAME, - accelerator: 'Command+H', role: 'hide' }, { - label: 'Hide Others', - accelerator: 'Command+Alt+H', role: 'hideothers' }, { - label: 'Show All', role: 'unhide' }, { @@ -334,19 +316,15 @@ function getMenuTemplate () { // Add Window menu (OS X) template.splice(5, 0, { - label: 'Window', role: 'window', submenu: [ { - label: 'Minimize', - accelerator: 'CmdOrCtrl+M', role: 'minimize' }, { type: 'separator' }, { - label: 'Bring All to Front', role: 'front' } ] From 6e1ff18eb9ba37b688ade640782e2e661d470d34 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Mon, 25 Jul 2016 15:29:53 -0700 Subject: [PATCH 2/4] macOS: add missing Edit menu roles --- src/main/menu.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/menu.js b/src/main/menu.js index 8e4ecac8..0bf40f79 100644 --- a/src/main/menu.js +++ b/src/main/menu.js @@ -106,6 +106,15 @@ function getMenuTemplate () { { label: 'Edit', submenu: [ + { + role: 'undo' + }, + { + role: 'redo' + }, + { + type: 'separator' + }, { role: 'cut' }, @@ -116,6 +125,9 @@ function getMenuTemplate () { label: 'Paste Torrent Address', role: 'paste' }, + { + role: 'delete' + }, { role: 'selectall' }, From 1b3b6fef10d938cd2a665546b302272b952ca75a Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Mon, 25 Jul 2016 15:30:02 -0700 Subject: [PATCH 3/4] Electron: Use 'quit' role --- src/main/menu.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/menu.js b/src/main/menu.js index 0bf40f79..19078d9e 100644 --- a/src/main/menu.js +++ b/src/main/menu.js @@ -319,9 +319,7 @@ function getMenuTemplate () { type: 'separator' }, { - label: 'Quit', - accelerator: 'Command+Q', - click: () => app.quit() + role: 'quit' } ] }) From ad62bbd9d3bcb1699dfd18e45743f14dde74e600 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Mon, 25 Jul 2016 15:37:29 -0700 Subject: [PATCH 4/4] Linux: Support showing badge count This was a macOS-only API before, but it's cross-platform now via `app.setBadgeCount()` --- src/main/dock.js | 9 ++++----- src/renderer/main.js | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/dock.js b/src/main/dock.js index 2d17a296..a6f36525 100644 --- a/src/main/dock.js +++ b/src/main/dock.js @@ -30,12 +30,11 @@ function downloadFinished (path) { } /** - * Display string in dock badging area. (OS X) + * Display a counter badge for the app. (OS X, Linux) */ -function setBadge (text) { - if (!app.dock) return - log(`setBadge: ${text}`) - app.dock.setBadge(String(text)) +function setBadge (count) { + log(`setBadge: ${count}`) + app.setBadgeCount(Number(count)) } function getMenuTemplate () { diff --git a/src/renderer/main.js b/src/renderer/main.js index 5d108c07..d83295b9 100644 --- a/src/renderer/main.js +++ b/src/renderer/main.js @@ -146,7 +146,7 @@ function updateElectron () { } if (state.dock.badge !== state.prev.badge) { state.prev.badge = state.dock.badge - ipcRenderer.send('setBadge', state.dock.badge || '') + ipcRenderer.send('setBadge', state.dock.badge || 0) } }