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

@@ -10,7 +10,13 @@
const [s, ns] = process.hrtime();
let launchStartTime: number | undefined = s * 1e3 + ns / 1e6;
import {app, BrowserWindow, ipcMain, Notification} from 'electron';
import {
app,
BrowserWindow,
ipcMain,
Notification,
globalShortcut,
} from 'electron';
import path from 'path';
import url from 'url';
import fs from 'fs';
@@ -199,6 +205,10 @@ app.on('ready', () => {
});
});
app.on('will-quit', () => {
globalShortcut.unregisterAll();
});
ipcMain.on('componentDidMount', _event => {
if (deeplinkURL) {
win.webContents.send('flipper-protocol-handler', deeplinkURL);