Add React Native/Metro hotkeys (#822)

Summary:
This PR fixes https://github.com/facebook/flipper/issues/798 by adding customizable hotkeys to reload and/or open developer menu in React Native apps.

![Screenshot of the Preferences window with hotkeys](https://user-images.githubusercontent.com/6207220/75113976-b27c0280-5652-11ea-8d5d-020d2650425b.png)

#### TODO:

- [x] Add correct icon for removing content of the hotkey input (currently using `undo`) - cc passy 😄

## Changelog

Add customizable hotkeys to reload and/or open developer menu in React Native apps.
Pull Request resolved: https://github.com/facebook/flipper/pull/822

Test Plan:
- Run React Native on version `0.62.0-rc.2` (you can use this app: https://github.com/lucasbento/RNWithFlipper);
- Open the Preferences window (`⌘,`);
- Customise the React Native hotkeys to whatever you want;
- Test them out with Flipper's window active and inactive.

> **Note**: this has been tested only in macOS.

Reviewed By: jknoxville

Differential Revision: D20061833

Pulled By: passy

fbshipit-source-id: 601d29e07d7de2683d2c70c7c87f0d841aa3559e
This commit is contained in:
Lucas Bento
2020-03-03 09:19:05 -08:00
committed by Facebook Github Bot
parent 2d9d0314b9
commit d1fb8bed4a
6 changed files with 405 additions and 9 deletions

View File

@@ -7,6 +7,7 @@
* @format
*/
import {remote} from 'electron';
import androidDevice from './androidDevice';
import metroDevice from './metroDevice';
import iOSDevice from './iOSDevice';
@@ -18,6 +19,7 @@ import notifications from './notifications';
import plugins from './plugins';
import user from './user';
import pluginManager from './pluginManager';
import reactNative from './reactNative';
import {Logger} from '../fb-interfaces/Logger';
import {Store} from '../reducers/index';
@@ -25,6 +27,12 @@ import {Dispatcher} from './types';
import {notNull} from '../utils/typeUtils';
export default function(store: Store, logger: Logger): () => Promise<void> {
// This only runs in development as when the reload
// kicks in it doesn't unregister the shortcuts
if (process.env.NODE_ENV === 'development') {
remote.globalShortcut.unregisterAll();
}
const dispatchers: Array<Dispatcher> = [
application,
store.getState().settingsState.enableAndroid ? androidDevice : null,
@@ -37,6 +45,7 @@ export default function(store: Store, logger: Logger): () => Promise<void> {
plugins,
user,
pluginManager,
reactNative,
].filter(notNull);
const globalCleanup = dispatchers
.map(dispatcher => dispatcher(store, logger))