Merge pull request #2002 from atom/app-commands-win32
Windows App Commands
This commit is contained in:
commit
e6f3c4c22b
5 changed files with 92 additions and 0 deletions
|
@ -162,6 +162,10 @@ void Window::OnDevToolsClosed() {
|
||||||
devtools_web_contents_.Reset();
|
devtools_web_contents_.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::OnExecuteWindowsCommand(const std::string& command_name) {
|
||||||
|
Emit("app-command", command_name);
|
||||||
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
mate::Wrappable* Window::New(v8::Isolate* isolate,
|
mate::Wrappable* Window::New(v8::Isolate* isolate,
|
||||||
const mate::Dictionary& options) {
|
const mate::Dictionary& options) {
|
||||||
|
|
|
@ -71,6 +71,7 @@ class Window : public mate::TrackableObject<Window>,
|
||||||
void OnDevToolsFocus() override;
|
void OnDevToolsFocus() override;
|
||||||
void OnDevToolsOpened() override;
|
void OnDevToolsOpened() override;
|
||||||
void OnDevToolsClosed() override;
|
void OnDevToolsClosed() override;
|
||||||
|
void OnExecuteWindowsCommand(const std::string& command_name) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// APIs for NativeWindow.
|
// APIs for NativeWindow.
|
||||||
|
|
|
@ -65,6 +65,9 @@ class NativeWindowObserver {
|
||||||
|
|
||||||
// Called when renderer recovers.
|
// Called when renderer recovers.
|
||||||
virtual void OnRendererResponsive() {}
|
virtual void OnRendererResponsive() {}
|
||||||
|
|
||||||
|
// Called on Windows when App Commands arrive (WM_APPCOMMAND)
|
||||||
|
virtual void OnExecuteWindowsCommand(const std::string& command_name) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -124,6 +124,70 @@ bool IsAltModifier(const content::NativeWebKeyboardEvent& event) {
|
||||||
(modifiers == (Modifiers::AltKey | Modifiers::IsRight));
|
(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 {
|
class NativeWindowClientView : public views::ClientView {
|
||||||
public:
|
public:
|
||||||
NativeWindowClientView(views::Widget* widget,
|
NativeWindowClientView(views::Widget* widget,
|
||||||
|
@ -855,6 +919,11 @@ bool NativeWindowViews::ExecuteWindowsCommand(int command_id) {
|
||||||
is_minimized_ = false;
|
is_minimized_ = false;
|
||||||
} else if ((command_id & sc_mask) == SC_MAXIMIZE) {
|
} else if ((command_id & sc_mask) == SC_MAXIMIZE) {
|
||||||
NotifyWindowMaximize();
|
NotifyWindowMaximize();
|
||||||
|
} else {
|
||||||
|
std::string command = AppCommandToString(command_id & sc_mask);
|
||||||
|
FOR_EACH_OBSERVER(NativeWindowObserver,
|
||||||
|
observers_,
|
||||||
|
OnExecuteWindowsCommand(command));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -219,6 +219,21 @@ Emitted when devtools is closed.
|
||||||
|
|
||||||
Emitted when devtools is focused / opened.
|
Emitted when devtools is focused / opened.
|
||||||
|
|
||||||
|
### 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.
|
||||||
|
|
||||||
|
```js
|
||||||
|
someWindow.on('app-command', function(e, cmd) {
|
||||||
|
// Navigate the window back when the user hits their mouse back button
|
||||||
|
if (cmd === 'browser-backward' && someWindow.webContents.canGoBack()) {
|
||||||
|
someWindow.webContents.goBack();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
__Note__: This event is only fired on Windows.
|
||||||
|
|
||||||
### Class Method: BrowserWindow.getAllWindows()
|
### Class Method: BrowserWindow.getAllWindows()
|
||||||
|
|
||||||
Returns an array of all opened browser windows.
|
Returns an array of all opened browser windows.
|
||||||
|
|
Loading…
Reference in a new issue