From d98cece115062cffdfc82c4bb9b764a9b3d05f8d Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Wed, 17 Jun 2015 17:15:02 -0700 Subject: [PATCH 01/15] Create a new method for NativeWindowObserver for AppCommands --- atom/browser/native_window_observer.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/atom/browser/native_window_observer.h b/atom/browser/native_window_observer.h index 335a63149953..bfb3342cf22a 100644 --- a/atom/browser/native_window_observer.h +++ b/atom/browser/native_window_observer.h @@ -65,6 +65,9 @@ class NativeWindowObserver { // Called when renderer recovers. virtual void OnRendererResponsive() {} + + // Called on Windows when App Commands arrive (WM_APPCOMMAND) + virtual void OnExecuteWindowsCommand(int command) {} }; } // namespace atom From 37d18d512b1289bbea6cc61ab89938b9a28b4fff Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Wed, 17 Jun 2015 17:15:52 -0700 Subject: [PATCH 02/15] Create a method to signal our Observer method --- atom/browser/native_window.cc | 5 +++++ atom/browser/native_window.h | 1 + 2 files changed, 6 insertions(+) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index df717c8dec98..b49f2978ed2b 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -580,6 +580,11 @@ void NativeWindow::NotifyWindowUnresponsive() { OnRendererUnresponsive()); } +void NativeWindow::NotifyExecuteWindowsCommand(int command_id) { + FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnExecuteWindowsCommand(command_id)); +} + + void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback, const SkBitmap& bitmap, content::ReadbackResponse response) { diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 4441726e3396..4f302f832092 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -198,6 +198,7 @@ class NativeWindow : public content::WebContentsObserver, void NotifyWindowLeaveFullScreen(); void NotifyWindowEnterHtmlFullScreen(); void NotifyWindowLeaveHtmlFullScreen(); + void NotifyExecuteWindowsCommand(int command_id); void AddObserver(NativeWindowObserver* obs) { observers_.AddObserver(obs); From 794f89abf5a31dd5cb637b918b320e149e889af7 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Wed, 17 Jun 2015 17:16:08 -0700 Subject: [PATCH 03/15] In our widget delegate, signal our Observer --- atom/browser/native_window_views.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 14a890475e55..f03ec73a1d78 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -855,7 +855,10 @@ bool NativeWindowViews::ExecuteWindowsCommand(int command_id) { is_minimized_ = false; } else if ((command_id & sc_mask) == SC_MAXIMIZE) { NotifyWindowMaximize(); + } else { + NotifyExecuteWindowsCommand(command_id & sc_mask); } + return false; } #endif From cec6895e679755b7b3bba39e17130dec421dc2de Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Wed, 17 Jun 2015 17:31:50 -0700 Subject: [PATCH 04/15] Emit the message as an event --- atom/browser/api/atom_api_window.cc | 4 ++++ atom/browser/api/atom_api_window.h | 1 + 2 files changed, 5 insertions(+) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 2dae7f8617f5..3f960ad8c211 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -162,6 +162,10 @@ void Window::OnDevToolsClosed() { devtools_web_contents_.Reset(); } +void Window::OnExecuteWindowsCommand(int command_id) { + Emit("app-command", command_id); +} + // static mate::Wrappable* Window::New(v8::Isolate* isolate, const mate::Dictionary& options) { diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 41383ea3e0ff..604b477cd1d2 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -71,6 +71,7 @@ class Window : public mate::TrackableObject, void OnDevToolsFocus() override; void OnDevToolsOpened() override; void OnDevToolsClosed() override; + void OnExecuteWindowsCommand(int command_id) override; private: // APIs for NativeWindow. From c2290ad058a606b09d566ba4fa72adabce7cebf2 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Fri, 19 Jun 2015 12:16:12 -0700 Subject: [PATCH 05/15] Add enum for media keys on Win32 --- atom/browser/api/lib/app-command.coffee | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 atom/browser/api/lib/app-command.coffee diff --git a/atom/browser/api/lib/app-command.coffee b/atom/browser/api/lib/app-command.coffee new file mode 100644 index 000000000000..ad45bd713869 --- /dev/null +++ b/atom/browser/api/lib/app-command.coffee @@ -0,0 +1,55 @@ +module.exports = + APPCOMMAND_BROWSER_BACKWARD: 1 + APPCOMMAND_BROWSER_FORWARD: 2 + APPCOMMAND_BROWSER_REFRESH: 3 + APPCOMMAND_BROWSER_STOP: 4 + APPCOMMAND_BROWSER_SEARCH: 5 + APPCOMMAND_BROWSER_FAVORITES: 6 + APPCOMMAND_BROWSER_HOME: 7 + APPCOMMAND_VOLUME_MUTE: 8 + APPCOMMAND_VOLUME_DOWN: 9 + APPCOMMAND_VOLUME_UP: 10 + APPCOMMAND_MEDIA_NEXTTRACK: 11 + APPCOMMAND_MEDIA_PREVIOUSTRACK: 12 + APPCOMMAND_MEDIA_STOP: 13 + APPCOMMAND_MEDIA_PLAY_PAUSE: 14 + APPCOMMAND_LAUNCH_MAIL: 15 + APPCOMMAND_LAUNCH_MEDIA_SELECT: 16 + APPCOMMAND_LAUNCH_APP1: 17 + APPCOMMAND_LAUNCH_APP2: 18 + APPCOMMAND_BASS_DOWN: 19 + APPCOMMAND_BASS_BOOST: 20 + APPCOMMAND_BASS_UP: 21 + APPCOMMAND_TREBLE_DOWN: 22 + APPCOMMAND_TREBLE_UP: 23 + APPCOMMAND_MICROPHONE_VOLUME_MUTE: 24 + APPCOMMAND_MICROPHONE_VOLUME_DOWN: 25 + APPCOMMAND_MICROPHONE_VOLUME_UP: 26 + APPCOMMAND_HELP: 27 + APPCOMMAND_FIND: 28 + APPCOMMAND_NEW: 29 + APPCOMMAND_OPEN: 30 + APPCOMMAND_CLOSE: 31 + APPCOMMAND_SAVE: 32 + APPCOMMAND_PRINT: 33 + APPCOMMAND_UNDO: 34 + APPCOMMAND_REDO: 35 + APPCOMMAND_COPY: 36 + APPCOMMAND_CUT: 37 + APPCOMMAND_PASTE: 38 + APPCOMMAND_REPLY_TO_MAIL: 39 + APPCOMMAND_FORWARD_MAIL: 40 + APPCOMMAND_SEND_MAIL: 41 + APPCOMMAND_SPELL_CHECK: 42 + APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE:43 + APPCOMMAND_MIC_ON_OFF_TOGGLE: 44 + APPCOMMAND_CORRECTION_LIST: 45 + APPCOMMAND_MEDIA_PLAY: 46 + APPCOMMAND_MEDIA_PAUSE: 47 + APPCOMMAND_MEDIA_RECORD: 48 + APPCOMMAND_MEDIA_FAST_FORWARD: 49 + APPCOMMAND_MEDIA_REWIND: 50 + APPCOMMAND_MEDIA_CHANNEL_UP: 51 + APPCOMMAND_MEDIA_CHANNEL_DOWN: 52 + APPCOMMAND_DELETE: 53 + APPCOMMAND_DWM_FLIP3D: 54 From 55a8862374231edfee1eeb8836a9e5f8a0abc4c1 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Fri, 19 Jun 2015 12:48:02 -0700 Subject: [PATCH 06/15] Add appcommand to files --- filenames.gypi | 1 + 1 file changed, 1 insertion(+) diff --git a/filenames.gypi b/filenames.gypi index 562e65280d59..98ea65442a88 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -9,6 +9,7 @@ ], 'coffee_sources': [ 'atom/browser/api/lib/app.coffee', + 'atom/browser/api/lib/app-command.coffee', 'atom/browser/api/lib/atom-delegate.coffee', 'atom/browser/api/lib/auto-updater.coffee', 'atom/browser/api/lib/browser-window.coffee', From b98154431c336618532629a6bf713cc500da18b5 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Fri, 19 Jun 2015 12:58:47 -0700 Subject: [PATCH 07/15] :memo: app commands --- docs/api/browser-window.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index b9c78b940ab3..31e7ca536650 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -219,6 +219,23 @@ Emitted when devtools is closed. Emitted when devtools is focused / opened. +### Event: 'app-command' (Windows): + +Emitted when an [App Command](https://msdn.microsoft.com/en-us/library/windows/desktop/ms646275(v=vs.85).aspx) is invoked. These are typically related to keyboard media keys or browser commands, as well as the "Back" button built into some mice on Windows. + + +```js +AppCommands = require('app-command'); + +someWindow.on('app-command', function(e, cmd) => { + // Navigate the window back when the user hits their mouse back button + if (cmd === AppCommands.APPCOMMAND_BROWSER_BACKWARD && + someWindow.webContents.canGoBack()) { + someWindow.webContents.goBack(); + } +}); +``` + ### Class Method: BrowserWindow.getAllWindows() Returns an array of all opened browser windows. From 1509aca78878f1a736361fedfc79277da67a47e8 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Fri, 19 Jun 2015 13:00:37 -0700 Subject: [PATCH 08/15] Invisible character tyranny --- atom/browser/api/lib/app-command.coffee | 108 ++++++++++++------------ 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/atom/browser/api/lib/app-command.coffee b/atom/browser/api/lib/app-command.coffee index ad45bd713869..94455dd150f4 100644 --- a/atom/browser/api/lib/app-command.coffee +++ b/atom/browser/api/lib/app-command.coffee @@ -1,55 +1,55 @@ module.exports = - APPCOMMAND_BROWSER_BACKWARD: 1 - APPCOMMAND_BROWSER_FORWARD: 2 - APPCOMMAND_BROWSER_REFRESH: 3 - APPCOMMAND_BROWSER_STOP: 4 - APPCOMMAND_BROWSER_SEARCH: 5 - APPCOMMAND_BROWSER_FAVORITES: 6 - APPCOMMAND_BROWSER_HOME: 7 - APPCOMMAND_VOLUME_MUTE: 8 - APPCOMMAND_VOLUME_DOWN: 9 - APPCOMMAND_VOLUME_UP: 10 - APPCOMMAND_MEDIA_NEXTTRACK: 11 - APPCOMMAND_MEDIA_PREVIOUSTRACK: 12 - APPCOMMAND_MEDIA_STOP: 13 - APPCOMMAND_MEDIA_PLAY_PAUSE: 14 - APPCOMMAND_LAUNCH_MAIL: 15 - APPCOMMAND_LAUNCH_MEDIA_SELECT: 16 - APPCOMMAND_LAUNCH_APP1: 17 - APPCOMMAND_LAUNCH_APP2: 18 - APPCOMMAND_BASS_DOWN: 19 - APPCOMMAND_BASS_BOOST: 20 - APPCOMMAND_BASS_UP: 21 - APPCOMMAND_TREBLE_DOWN: 22 - APPCOMMAND_TREBLE_UP: 23 - APPCOMMAND_MICROPHONE_VOLUME_MUTE: 24 - APPCOMMAND_MICROPHONE_VOLUME_DOWN: 25 - APPCOMMAND_MICROPHONE_VOLUME_UP: 26 - APPCOMMAND_HELP: 27 - APPCOMMAND_FIND: 28 - APPCOMMAND_NEW: 29 - APPCOMMAND_OPEN: 30 - APPCOMMAND_CLOSE: 31 - APPCOMMAND_SAVE: 32 - APPCOMMAND_PRINT: 33 - APPCOMMAND_UNDO: 34 - APPCOMMAND_REDO: 35 - APPCOMMAND_COPY: 36 - APPCOMMAND_CUT: 37 - APPCOMMAND_PASTE: 38 - APPCOMMAND_REPLY_TO_MAIL: 39 - APPCOMMAND_FORWARD_MAIL: 40 - APPCOMMAND_SEND_MAIL: 41 - APPCOMMAND_SPELL_CHECK: 42 - APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE:43 - APPCOMMAND_MIC_ON_OFF_TOGGLE: 44 - APPCOMMAND_CORRECTION_LIST: 45 - APPCOMMAND_MEDIA_PLAY: 46 - APPCOMMAND_MEDIA_PAUSE: 47 - APPCOMMAND_MEDIA_RECORD: 48 - APPCOMMAND_MEDIA_FAST_FORWARD: 49 - APPCOMMAND_MEDIA_REWIND: 50 - APPCOMMAND_MEDIA_CHANNEL_UP: 51 - APPCOMMAND_MEDIA_CHANNEL_DOWN: 52 - APPCOMMAND_DELETE: 53 - APPCOMMAND_DWM_FLIP3D: 54 + APPCOMMAND_BROWSER_BACKWARD: 1 + APPCOMMAND_BROWSER_FORWARD: 2 + APPCOMMAND_BROWSER_REFRESH: 3 + APPCOMMAND_BROWSER_STOP: 4 + APPCOMMAND_BROWSER_SEARCH: 5 + APPCOMMAND_BROWSER_FAVORITES: 6 + APPCOMMAND_BROWSER_HOME: 7 + APPCOMMAND_VOLUME_MUTE: 8 + APPCOMMAND_VOLUME_DOWN: 9 + APPCOMMAND_VOLUME_UP: 10 + APPCOMMAND_MEDIA_NEXTTRACK: 11 + APPCOMMAND_MEDIA_PREVIOUSTRACK: 12 + APPCOMMAND_MEDIA_STOP: 13 + APPCOMMAND_MEDIA_PLAY_PAUSE: 14 + APPCOMMAND_LAUNCH_MAIL: 15 + APPCOMMAND_LAUNCH_MEDIA_SELECT: 16 + APPCOMMAND_LAUNCH_APP1: 17 + APPCOMMAND_LAUNCH_APP2: 18 + APPCOMMAND_BASS_DOWN: 19 + APPCOMMAND_BASS_BOOST: 20 + APPCOMMAND_BASS_UP: 21 + APPCOMMAND_TREBLE_DOWN: 22 + APPCOMMAND_TREBLE_UP: 23 + APPCOMMAND_MICROPHONE_VOLUME_MUTE: 24 + APPCOMMAND_MICROPHONE_VOLUME_DOWN: 25 + APPCOMMAND_MICROPHONE_VOLUME_UP: 26 + APPCOMMAND_HELP: 27 + APPCOMMAND_FIND: 28 + APPCOMMAND_NEW: 29 + APPCOMMAND_OPEN: 30 + APPCOMMAND_CLOSE: 31 + APPCOMMAND_SAVE: 32 + APPCOMMAND_PRINT: 33 + APPCOMMAND_UNDO: 34 + APPCOMMAND_REDO: 35 + APPCOMMAND_COPY: 36 + APPCOMMAND_CUT: 37 + APPCOMMAND_PASTE: 38 + APPCOMMAND_REPLY_TO_MAIL: 39 + APPCOMMAND_FORWARD_MAIL: 40 + APPCOMMAND_SEND_MAIL: 41 + APPCOMMAND_SPELL_CHECK: 42 + APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE:43 + APPCOMMAND_MIC_ON_OFF_TOGGLE: 44 + APPCOMMAND_CORRECTION_LIST: 45 + APPCOMMAND_MEDIA_PLAY: 46 + APPCOMMAND_MEDIA_PAUSE: 47 + APPCOMMAND_MEDIA_RECORD: 48 + APPCOMMAND_MEDIA_FAST_FORWARD: 49 + APPCOMMAND_MEDIA_REWIND: 50 + APPCOMMAND_MEDIA_CHANNEL_UP: 51 + APPCOMMAND_MEDIA_CHANNEL_DOWN: 52 + APPCOMMAND_DELETE: 53 + APPCOMMAND_DWM_FLIP3D: 54 From 210417b4282361e0e12e2dcd1be472927d70e9e0 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Fri, 19 Jun 2015 13:04:28 -0700 Subject: [PATCH 09/15] cpplint see me rollin', he hatin' --- atom/browser/native_window.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index b49f2978ed2b..47231e435d64 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -581,7 +581,9 @@ void NativeWindow::NotifyWindowUnresponsive() { } void NativeWindow::NotifyExecuteWindowsCommand(int command_id) { - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnExecuteWindowsCommand(command_id)); + FOR_EACH_OBSERVER(NativeWindowObserver, + observers_, + OnExecuteWindowsCommand(command_id)); } From cde7c6a4ef92b18a54779f3d0354e21370bfde71 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Thu, 25 Jun 2015 11:25:55 -0500 Subject: [PATCH 10/15] Move app commands to strings --- atom/browser/api/atom_api_window.cc | 4 +- atom/browser/api/atom_api_window.h | 2 +- atom/browser/api/lib/app-command.coffee | 55 ----------- atom/browser/native_window.cc | 117 +++++++++++++++++++++++- atom/browser/native_window.h | 3 + atom/browser/native_window_observer.h | 2 +- filenames.gypi | 1 - vendor/brightray | 2 +- vendor/native_mate | 2 +- 9 files changed, 125 insertions(+), 63 deletions(-) delete mode 100644 atom/browser/api/lib/app-command.coffee diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 3f960ad8c211..be615c9ad111 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -162,8 +162,8 @@ void Window::OnDevToolsClosed() { devtools_web_contents_.Reset(); } -void Window::OnExecuteWindowsCommand(int command_id) { - Emit("app-command", command_id); +void Window::OnExecuteWindowsCommand(std::string& command_name) { + Emit("app-command", command_name); } // static diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 604b477cd1d2..248abf6f4300 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -71,7 +71,7 @@ class Window : public mate::TrackableObject, void OnDevToolsFocus() override; void OnDevToolsOpened() override; void OnDevToolsClosed() override; - void OnExecuteWindowsCommand(int command_id) override; + void OnExecuteWindowsCommand(std::string& command_name) override; private: // APIs for NativeWindow. diff --git a/atom/browser/api/lib/app-command.coffee b/atom/browser/api/lib/app-command.coffee deleted file mode 100644 index 94455dd150f4..000000000000 --- a/atom/browser/api/lib/app-command.coffee +++ /dev/null @@ -1,55 +0,0 @@ -module.exports = - APPCOMMAND_BROWSER_BACKWARD: 1 - APPCOMMAND_BROWSER_FORWARD: 2 - APPCOMMAND_BROWSER_REFRESH: 3 - APPCOMMAND_BROWSER_STOP: 4 - APPCOMMAND_BROWSER_SEARCH: 5 - APPCOMMAND_BROWSER_FAVORITES: 6 - APPCOMMAND_BROWSER_HOME: 7 - APPCOMMAND_VOLUME_MUTE: 8 - APPCOMMAND_VOLUME_DOWN: 9 - APPCOMMAND_VOLUME_UP: 10 - APPCOMMAND_MEDIA_NEXTTRACK: 11 - APPCOMMAND_MEDIA_PREVIOUSTRACK: 12 - APPCOMMAND_MEDIA_STOP: 13 - APPCOMMAND_MEDIA_PLAY_PAUSE: 14 - APPCOMMAND_LAUNCH_MAIL: 15 - APPCOMMAND_LAUNCH_MEDIA_SELECT: 16 - APPCOMMAND_LAUNCH_APP1: 17 - APPCOMMAND_LAUNCH_APP2: 18 - APPCOMMAND_BASS_DOWN: 19 - APPCOMMAND_BASS_BOOST: 20 - APPCOMMAND_BASS_UP: 21 - APPCOMMAND_TREBLE_DOWN: 22 - APPCOMMAND_TREBLE_UP: 23 - APPCOMMAND_MICROPHONE_VOLUME_MUTE: 24 - APPCOMMAND_MICROPHONE_VOLUME_DOWN: 25 - APPCOMMAND_MICROPHONE_VOLUME_UP: 26 - APPCOMMAND_HELP: 27 - APPCOMMAND_FIND: 28 - APPCOMMAND_NEW: 29 - APPCOMMAND_OPEN: 30 - APPCOMMAND_CLOSE: 31 - APPCOMMAND_SAVE: 32 - APPCOMMAND_PRINT: 33 - APPCOMMAND_UNDO: 34 - APPCOMMAND_REDO: 35 - APPCOMMAND_COPY: 36 - APPCOMMAND_CUT: 37 - APPCOMMAND_PASTE: 38 - APPCOMMAND_REPLY_TO_MAIL: 39 - APPCOMMAND_FORWARD_MAIL: 40 - APPCOMMAND_SEND_MAIL: 41 - APPCOMMAND_SPELL_CHECK: 42 - APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE:43 - APPCOMMAND_MIC_ON_OFF_TOGGLE: 44 - APPCOMMAND_CORRECTION_LIST: 45 - APPCOMMAND_MEDIA_PLAY: 46 - APPCOMMAND_MEDIA_PAUSE: 47 - APPCOMMAND_MEDIA_RECORD: 48 - APPCOMMAND_MEDIA_FAST_FORWARD: 49 - APPCOMMAND_MEDIA_REWIND: 50 - APPCOMMAND_MEDIA_CHANNEL_UP: 51 - APPCOMMAND_MEDIA_CHANNEL_DOWN: 52 - APPCOMMAND_DELETE: 53 - APPCOMMAND_DWM_FLIP3D: 54 diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 47231e435d64..308a4842d139 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -581,9 +581,11 @@ void NativeWindow::NotifyWindowUnresponsive() { } void NativeWindow::NotifyExecuteWindowsCommand(int command_id) { + std::string command = AppCommandToString(command_id); + FOR_EACH_OBSERVER(NativeWindowObserver, observers_, - OnExecuteWindowsCommand(command_id)); + OnExecuteWindowsCommand(command)); } @@ -593,4 +595,117 @@ void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback, callback.Run(bitmap); } +const char* NativeWindow::AppCommandToString(int command_id) { + switch(command_id) { + case APPCOMMAND_BROWSER_BACKWARD: + return "browser-backward"; + case APPCOMMAND_BROWSER_FORWARD: + return "browser-forward"; + case APPCOMMAND_BROWSER_REFRESH: + return "browser-refresh"; + case APPCOMMAND_BROWSER_STOP: + return "browser-stop"; + case APPCOMMAND_BROWSER_SEARCH: + return "browser-search"; + case APPCOMMAND_BROWSER_FAVORITES: + return "browser-favorites"; + case APPCOMMAND_BROWSER_HOME: + return "browser-home"; + case APPCOMMAND_VOLUME_MUTE: + return "volume-mute"; + case APPCOMMAND_VOLUME_DOWN: + return "volume-down"; + case APPCOMMAND_VOLUME_UP: + return "volume-up"; + case APPCOMMAND_MEDIA_NEXTTRACK: + return "media-nexttrack"; + case APPCOMMAND_MEDIA_PREVIOUSTRACK: + return "media-previoustrack"; + case APPCOMMAND_MEDIA_STOP: + return "media-stop"; + case APPCOMMAND_MEDIA_PLAY_PAUSE: + return "media-play_pause"; + case APPCOMMAND_LAUNCH_MAIL: + return "launch-mail"; + case APPCOMMAND_LAUNCH_MEDIA_SELECT: + return "launch-media-select"; + case APPCOMMAND_LAUNCH_APP1: + return "launch-app1"; + case APPCOMMAND_LAUNCH_APP2: + return "launch-app2"; + case APPCOMMAND_BASS_DOWN: + return "bass-down"; + case APPCOMMAND_BASS_BOOST: + return "bass-boost"; + case APPCOMMAND_BASS_UP: + return "bass-up"; + case APPCOMMAND_TREBLE_DOWN: + return "treble-down"; + case APPCOMMAND_TREBLE_UP: + return "treble-up"; + case APPCOMMAND_MICROPHONE_VOLUME_MUTE: + return "microphone-volume-mute"; + case APPCOMMAND_MICROPHONE_VOLUME_DOWN: + return "microphone-volume-down"; + case APPCOMMAND_MICROPHONE_VOLUME_UP: + return "microphone-volume-up"; + case APPCOMMAND_HELP: + return "help"; + case APPCOMMAND_FIND: + return "find"; + case APPCOMMAND_NEW: + return "new"; + case APPCOMMAND_OPEN: + return "open"; + case APPCOMMAND_CLOSE: + return "close"; + case APPCOMMAND_SAVE: + return "save"; + case APPCOMMAND_PRINT: + return "print"; + case APPCOMMAND_UNDO: + return "undo"; + case APPCOMMAND_REDO: + return "redo"; + case APPCOMMAND_COPY: + return "copy"; + case APPCOMMAND_CUT: + return "cut"; + case APPCOMMAND_PASTE: + return "paste"; + case APPCOMMAND_REPLY_TO_MAIL: + return "reply-to-mail"; + case APPCOMMAND_FORWARD_MAIL: + return "forward-mail"; + case APPCOMMAND_SEND_MAIL: + return "send-mail"; + case APPCOMMAND_SPELL_CHECK: + return "spell-check"; + case APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE: + return "dictate-or-command-control-toggle"; + case APPCOMMAND_MIC_ON_OFF_TOGGLE: + return "mic-on-off-toggle"; + case APPCOMMAND_CORRECTION_LIST: + return "correction-list"; + case APPCOMMAND_MEDIA_PLAY: + return "media-play"; + case APPCOMMAND_MEDIA_PAUSE: + return "media-pause"; + case APPCOMMAND_MEDIA_RECORD: + return "media-record"; + case APPCOMMAND_MEDIA_FAST_FORWARD: + return "media-fast-forward"; + case APPCOMMAND_MEDIA_REWIND: + return "media-rewind"; + case APPCOMMAND_MEDIA_CHANNEL_UP: + return "media-channel-up"; + case APPCOMMAND_MEDIA_CHANNEL_DOWN: + return "media-channel-down"; + case APPCOMMAND_DELETE: + return "delete"; + default: + return ""; + } +} + } // namespace atom diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 4f302f832092..d034baf739ec 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -261,6 +261,9 @@ class NativeWindow : public content::WebContentsObserver, const SkBitmap& bitmap, content::ReadbackResponse response); + // Convert Win32 WM_APPCOMMANDS to strings + const char* AppCommandToString(int command_id); + // Observers of this window. ObserverList observers_; diff --git a/atom/browser/native_window_observer.h b/atom/browser/native_window_observer.h index bfb3342cf22a..c8a2c5e3c703 100644 --- a/atom/browser/native_window_observer.h +++ b/atom/browser/native_window_observer.h @@ -67,7 +67,7 @@ class NativeWindowObserver { virtual void OnRendererResponsive() {} // Called on Windows when App Commands arrive (WM_APPCOMMAND) - virtual void OnExecuteWindowsCommand(int command) {} + virtual void OnExecuteWindowsCommand(std::string& command_name) {} }; } // namespace atom diff --git a/filenames.gypi b/filenames.gypi index 98ea65442a88..562e65280d59 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -9,7 +9,6 @@ ], 'coffee_sources': [ 'atom/browser/api/lib/app.coffee', - 'atom/browser/api/lib/app-command.coffee', 'atom/browser/api/lib/atom-delegate.coffee', 'atom/browser/api/lib/auto-updater.coffee', 'atom/browser/api/lib/browser-window.coffee', diff --git a/vendor/brightray b/vendor/brightray index b05e019d2f66..2dc473cada4f 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit b05e019d2f66023fad1ae2f16cc765e3d62ffd5e +Subproject commit 2dc473cada4f118880241c6cd62ffb59dc58ef50 diff --git a/vendor/native_mate b/vendor/native_mate index cc4e2fcd94b5..ad207eeabb01 160000 --- a/vendor/native_mate +++ b/vendor/native_mate @@ -1 +1 @@ -Subproject commit cc4e2fcd94b5a22e6720f0fba1c586a89640f1f6 +Subproject commit ad207eeabb0185f74c017e70ca3411d522627ff0 From 2a2158e0e34e9f2b715d37462ba84b08fa678bf3 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Thu, 25 Jun 2015 11:20:33 -0600 Subject: [PATCH 11/15] :memo: consistency --- docs/api/browser-window.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 31e7ca536650..81649ebdd3b6 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -219,7 +219,7 @@ Emitted when devtools is closed. Emitted when devtools is focused / opened. -### Event: 'app-command' (Windows): +### Event: 'app-command': Emitted when an [App Command](https://msdn.microsoft.com/en-us/library/windows/desktop/ms646275(v=vs.85).aspx) is invoked. These are typically related to keyboard media keys or browser commands, as well as the "Back" button built into some mice on Windows. @@ -236,6 +236,8 @@ someWindow.on('app-command', function(e, cmd) => { }); ``` +__Note__: This event is only fired on Windows + ### Class Method: BrowserWindow.getAllWindows() Returns an array of all opened browser windows. From 528e0f3efbdc781c6d5df8bef58c05b646d17826 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Thu, 25 Jun 2015 11:31:32 -0600 Subject: [PATCH 12/15] Revert submodule change --- vendor/brightray | 2 +- vendor/native_mate | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vendor/brightray b/vendor/brightray index 2dc473cada4f..b05e019d2f66 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit 2dc473cada4f118880241c6cd62ffb59dc58ef50 +Subproject commit b05e019d2f66023fad1ae2f16cc765e3d62ffd5e diff --git a/vendor/native_mate b/vendor/native_mate index ad207eeabb01..cc4e2fcd94b5 160000 --- a/vendor/native_mate +++ b/vendor/native_mate @@ -1 +1 @@ -Subproject commit ad207eeabb0185f74c017e70ca3411d522627ff0 +Subproject commit cc4e2fcd94b5a22e6720f0fba1c586a89640f1f6 From 58efb3c01804efed79475d776d416296eef551cb Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Thu, 25 Jun 2015 15:09:25 -0600 Subject: [PATCH 13/15] I forget cpplint every time --- atom/browser/api/atom_api_window.cc | 2 +- atom/browser/api/atom_api_window.h | 2 +- atom/browser/native_window.cc | 2 +- atom/browser/native_window_observer.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index be615c9ad111..9e8076fe8c91 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -162,7 +162,7 @@ void Window::OnDevToolsClosed() { devtools_web_contents_.Reset(); } -void Window::OnExecuteWindowsCommand(std::string& command_name) { +void Window::OnExecuteWindowsCommand(const std::string& command_name) { Emit("app-command", command_name); } diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 248abf6f4300..5867b1e6281a 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -71,7 +71,7 @@ class Window : public mate::TrackableObject, void OnDevToolsFocus() override; void OnDevToolsOpened() override; void OnDevToolsClosed() override; - void OnExecuteWindowsCommand(std::string& command_name) override; + void OnExecuteWindowsCommand(const std::string& command_name) override; private: // APIs for NativeWindow. diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 308a4842d139..38bbedf39d5f 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -596,7 +596,7 @@ void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback, } const char* NativeWindow::AppCommandToString(int command_id) { - switch(command_id) { + switch (command_id) { case APPCOMMAND_BROWSER_BACKWARD: return "browser-backward"; case APPCOMMAND_BROWSER_FORWARD: diff --git a/atom/browser/native_window_observer.h b/atom/browser/native_window_observer.h index c8a2c5e3c703..5b0a0c56b3de 100644 --- a/atom/browser/native_window_observer.h +++ b/atom/browser/native_window_observer.h @@ -67,7 +67,7 @@ class NativeWindowObserver { virtual void OnRendererResponsive() {} // Called on Windows when App Commands arrive (WM_APPCOMMAND) - virtual void OnExecuteWindowsCommand(std::string& command_name) {} + virtual void OnExecuteWindowsCommand(const std::string& command_name) {} }; } // namespace atom From bff66caaa6c369ea7060204f00b44f796e9cf2dd Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 26 Jun 2015 11:16:50 +0800 Subject: [PATCH 14/15] Only convert command ID on Windows --- atom/browser/native_window.cc | 121 ---------------------------- atom/browser/native_window.h | 4 - atom/browser/native_window_views.cc | 69 +++++++++++++++- 3 files changed, 68 insertions(+), 126 deletions(-) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 38bbedf39d5f..399b49349de7 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -580,14 +580,6 @@ void NativeWindow::NotifyWindowUnresponsive() { OnRendererUnresponsive()); } -void NativeWindow::NotifyExecuteWindowsCommand(int command_id) { - std::string command = AppCommandToString(command_id); - - FOR_EACH_OBSERVER(NativeWindowObserver, - observers_, - OnExecuteWindowsCommand(command)); -} - void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback, const SkBitmap& bitmap, @@ -595,117 +587,4 @@ void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback, callback.Run(bitmap); } -const char* NativeWindow::AppCommandToString(int command_id) { - switch (command_id) { - case APPCOMMAND_BROWSER_BACKWARD: - return "browser-backward"; - case APPCOMMAND_BROWSER_FORWARD: - return "browser-forward"; - case APPCOMMAND_BROWSER_REFRESH: - return "browser-refresh"; - case APPCOMMAND_BROWSER_STOP: - return "browser-stop"; - case APPCOMMAND_BROWSER_SEARCH: - return "browser-search"; - case APPCOMMAND_BROWSER_FAVORITES: - return "browser-favorites"; - case APPCOMMAND_BROWSER_HOME: - return "browser-home"; - case APPCOMMAND_VOLUME_MUTE: - return "volume-mute"; - case APPCOMMAND_VOLUME_DOWN: - return "volume-down"; - case APPCOMMAND_VOLUME_UP: - return "volume-up"; - case APPCOMMAND_MEDIA_NEXTTRACK: - return "media-nexttrack"; - case APPCOMMAND_MEDIA_PREVIOUSTRACK: - return "media-previoustrack"; - case APPCOMMAND_MEDIA_STOP: - return "media-stop"; - case APPCOMMAND_MEDIA_PLAY_PAUSE: - return "media-play_pause"; - case APPCOMMAND_LAUNCH_MAIL: - return "launch-mail"; - case APPCOMMAND_LAUNCH_MEDIA_SELECT: - return "launch-media-select"; - case APPCOMMAND_LAUNCH_APP1: - return "launch-app1"; - case APPCOMMAND_LAUNCH_APP2: - return "launch-app2"; - case APPCOMMAND_BASS_DOWN: - return "bass-down"; - case APPCOMMAND_BASS_BOOST: - return "bass-boost"; - case APPCOMMAND_BASS_UP: - return "bass-up"; - case APPCOMMAND_TREBLE_DOWN: - return "treble-down"; - case APPCOMMAND_TREBLE_UP: - return "treble-up"; - case APPCOMMAND_MICROPHONE_VOLUME_MUTE: - return "microphone-volume-mute"; - case APPCOMMAND_MICROPHONE_VOLUME_DOWN: - return "microphone-volume-down"; - case APPCOMMAND_MICROPHONE_VOLUME_UP: - return "microphone-volume-up"; - case APPCOMMAND_HELP: - return "help"; - case APPCOMMAND_FIND: - return "find"; - case APPCOMMAND_NEW: - return "new"; - case APPCOMMAND_OPEN: - return "open"; - case APPCOMMAND_CLOSE: - return "close"; - case APPCOMMAND_SAVE: - return "save"; - case APPCOMMAND_PRINT: - return "print"; - case APPCOMMAND_UNDO: - return "undo"; - case APPCOMMAND_REDO: - return "redo"; - case APPCOMMAND_COPY: - return "copy"; - case APPCOMMAND_CUT: - return "cut"; - case APPCOMMAND_PASTE: - return "paste"; - case APPCOMMAND_REPLY_TO_MAIL: - return "reply-to-mail"; - case APPCOMMAND_FORWARD_MAIL: - return "forward-mail"; - case APPCOMMAND_SEND_MAIL: - return "send-mail"; - case APPCOMMAND_SPELL_CHECK: - return "spell-check"; - case APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE: - return "dictate-or-command-control-toggle"; - case APPCOMMAND_MIC_ON_OFF_TOGGLE: - return "mic-on-off-toggle"; - case APPCOMMAND_CORRECTION_LIST: - return "correction-list"; - case APPCOMMAND_MEDIA_PLAY: - return "media-play"; - case APPCOMMAND_MEDIA_PAUSE: - return "media-pause"; - case APPCOMMAND_MEDIA_RECORD: - return "media-record"; - case APPCOMMAND_MEDIA_FAST_FORWARD: - return "media-fast-forward"; - case APPCOMMAND_MEDIA_REWIND: - return "media-rewind"; - case APPCOMMAND_MEDIA_CHANNEL_UP: - return "media-channel-up"; - case APPCOMMAND_MEDIA_CHANNEL_DOWN: - return "media-channel-down"; - case APPCOMMAND_DELETE: - return "delete"; - default: - return ""; - } -} - } // namespace atom diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index d034baf739ec..4441726e3396 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -198,7 +198,6 @@ class NativeWindow : public content::WebContentsObserver, void NotifyWindowLeaveFullScreen(); void NotifyWindowEnterHtmlFullScreen(); void NotifyWindowLeaveHtmlFullScreen(); - void NotifyExecuteWindowsCommand(int command_id); void AddObserver(NativeWindowObserver* obs) { observers_.AddObserver(obs); @@ -261,9 +260,6 @@ class NativeWindow : public content::WebContentsObserver, const SkBitmap& bitmap, content::ReadbackResponse response); - // Convert Win32 WM_APPCOMMANDS to strings - const char* AppCommandToString(int command_id); - // Observers of this window. ObserverList observers_; diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index f03ec73a1d78..35cee1054f1b 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -124,6 +124,70 @@ bool IsAltModifier(const content::NativeWebKeyboardEvent& event) { (modifiers == (Modifiers::AltKey | Modifiers::IsRight)); } +#if defined(OS_WIN) +// Convert Win32 WM_APPCOMMANDS to strings. +const char* AppCommandToString(int command_id) { + switch (command_id) { + case APPCOMMAND_BROWSER_BACKWARD : return "browser-backward"; + case APPCOMMAND_BROWSER_FORWARD : return "browser-forward"; + case APPCOMMAND_BROWSER_REFRESH : return "browser-refresh"; + case APPCOMMAND_BROWSER_STOP : return "browser-stop"; + case APPCOMMAND_BROWSER_SEARCH : return "browser-search"; + case APPCOMMAND_BROWSER_FAVORITES : return "browser-favorites"; + case APPCOMMAND_BROWSER_HOME : return "browser-home"; + case APPCOMMAND_VOLUME_MUTE : return "volume-mute"; + case APPCOMMAND_VOLUME_DOWN : return "volume-down"; + case APPCOMMAND_VOLUME_UP : return "volume-up"; + case APPCOMMAND_MEDIA_NEXTTRACK : return "media-nexttrack"; + case APPCOMMAND_MEDIA_PREVIOUSTRACK : return "media-previoustrack"; + case APPCOMMAND_MEDIA_STOP : return "media-stop"; + case APPCOMMAND_MEDIA_PLAY_PAUSE : return "media-play_pause"; + case APPCOMMAND_LAUNCH_MAIL : return "launch-mail"; + case APPCOMMAND_LAUNCH_MEDIA_SELECT : return "launch-media-select"; + case APPCOMMAND_LAUNCH_APP1 : return "launch-app1"; + case APPCOMMAND_LAUNCH_APP2 : return "launch-app2"; + case APPCOMMAND_BASS_DOWN : return "bass-down"; + case APPCOMMAND_BASS_BOOST : return "bass-boost"; + case APPCOMMAND_BASS_UP : return "bass-up"; + case APPCOMMAND_TREBLE_DOWN : return "treble-down"; + case APPCOMMAND_TREBLE_UP : return "treble-up"; + case APPCOMMAND_MICROPHONE_VOLUME_MUTE : return "microphone-volume-mute"; + case APPCOMMAND_MICROPHONE_VOLUME_DOWN : return "microphone-volume-down"; + case APPCOMMAND_MICROPHONE_VOLUME_UP : return "microphone-volume-up"; + case APPCOMMAND_HELP : return "help"; + case APPCOMMAND_FIND : return "find"; + case APPCOMMAND_NEW : return "new"; + case APPCOMMAND_OPEN : return "open"; + case APPCOMMAND_CLOSE : return "close"; + case APPCOMMAND_SAVE : return "save"; + case APPCOMMAND_PRINT : return "print"; + case APPCOMMAND_UNDO : return "undo"; + case APPCOMMAND_REDO : return "redo"; + case APPCOMMAND_COPY : return "copy"; + case APPCOMMAND_CUT : return "cut"; + case APPCOMMAND_PASTE : return "paste"; + case APPCOMMAND_REPLY_TO_MAIL : return "reply-to-mail"; + case APPCOMMAND_FORWARD_MAIL : return "forward-mail"; + case APPCOMMAND_SEND_MAIL : return "send-mail"; + case APPCOMMAND_SPELL_CHECK : return "spell-check"; + case APPCOMMAND_MIC_ON_OFF_TOGGLE : return "mic-on-off-toggle"; + case APPCOMMAND_CORRECTION_LIST : return "correction-list"; + case APPCOMMAND_MEDIA_PLAY : return "media-play"; + case APPCOMMAND_MEDIA_PAUSE : return "media-pause"; + case APPCOMMAND_MEDIA_RECORD : return "media-record"; + case APPCOMMAND_MEDIA_FAST_FORWARD : return "media-fast-forward"; + case APPCOMMAND_MEDIA_REWIND : return "media-rewind"; + case APPCOMMAND_MEDIA_CHANNEL_UP : return "media-channel-up"; + case APPCOMMAND_MEDIA_CHANNEL_DOWN : return "media-channel-down"; + case APPCOMMAND_DELETE : return "delete"; + case APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE: + return "dictate-or-command-control-toggle"; + default: + return "unkown"; + } +} +#endif + class NativeWindowClientView : public views::ClientView { public: NativeWindowClientView(views::Widget* widget, @@ -856,7 +920,10 @@ bool NativeWindowViews::ExecuteWindowsCommand(int command_id) { } else if ((command_id & sc_mask) == SC_MAXIMIZE) { NotifyWindowMaximize(); } else { - NotifyExecuteWindowsCommand(command_id & sc_mask); + std::string command = AppCommandToString(command_id & sc_mask); + FOR_EACH_OBSERVER(NativeWindowObserver, + observers_, + OnExecuteWindowsCommand(command)); } return false; From b5ff77ef0d7623aea10015c14268c0d9e038e256 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 26 Jun 2015 11:20:12 +0800 Subject: [PATCH 15/15] Small cleanups --- atom/browser/native_window.cc | 1 - atom/browser/native_window_views.cc | 1 - docs/api/browser-window.md | 10 +++------- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 399b49349de7..df717c8dec98 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -580,7 +580,6 @@ void NativeWindow::NotifyWindowUnresponsive() { OnRendererUnresponsive()); } - void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback, const SkBitmap& bitmap, content::ReadbackResponse response) { diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 35cee1054f1b..96997222e27e 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -925,7 +925,6 @@ bool NativeWindowViews::ExecuteWindowsCommand(int command_id) { observers_, OnExecuteWindowsCommand(command)); } - return false; } #endif diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 81649ebdd3b6..ca6e9b99b283 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -223,20 +223,16 @@ Emitted when devtools is focused / opened. Emitted when an [App Command](https://msdn.microsoft.com/en-us/library/windows/desktop/ms646275(v=vs.85).aspx) is invoked. These are typically related to keyboard media keys or browser commands, as well as the "Back" button built into some mice on Windows. - ```js -AppCommands = require('app-command'); - -someWindow.on('app-command', function(e, cmd) => { +someWindow.on('app-command', function(e, cmd) { // Navigate the window back when the user hits their mouse back button - if (cmd === AppCommands.APPCOMMAND_BROWSER_BACKWARD && - someWindow.webContents.canGoBack()) { + if (cmd === 'browser-backward' && someWindow.webContents.canGoBack()) { someWindow.webContents.goBack(); } }); ``` -__Note__: This event is only fired on Windows +__Note__: This event is only fired on Windows. ### Class Method: BrowserWindow.getAllWindows()