Skip to content

Commit ab2c81f

Browse files
motiz88facebook-github-bot
authored andcommitted
Bring RNDT shell to front when paused on breakpoint (#51748)
Summary: Pull Request resolved: #51748 Changelog: [Internal] Implements the first RNDT shell-specific feature based on facebook/react-native-devtools-frontend#168 - namely, the ability for RNDT to foreground itself when certain events occur. This is most noticeable when pausing on a breakpoint. Reviewed By: huntie, vzaidman Differential Revision: D75795689 fbshipit-source-id: a073bf8ea96ba70d835007f5af6069d49a693d81
1 parent 75be907 commit ab2c81f

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

packages/debugger-shell/src/electron/MainInstanceEntryPoint.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010

1111
// $FlowFixMe[unclear-type] We have no Flow types for the Electron API.
12-
const {BrowserWindow, app, shell} = require('electron') as any;
12+
const {BrowserWindow, app, shell, ipcMain} = require('electron') as any;
1313
const util = require('util');
1414

1515
const windowMetadata = new WeakMap<
@@ -66,6 +66,7 @@ function handleLaunchArgs(argv: string[]) {
6666
height: 600,
6767
webPreferences: {
6868
partition: 'persist:react-native-devtools',
69+
preload: require.resolve('./preload.js'),
6970
},
7071
});
7172

@@ -102,3 +103,16 @@ app.whenReady().then(() => {
102103
app.on('window-all-closed', function () {
103104
app.quit();
104105
});
106+
107+
ipcMain.on('bringToFront', (event, title) => {
108+
const webContents = event.sender;
109+
const win = BrowserWindow.fromWebContents(webContents);
110+
if (win) {
111+
win.focus();
112+
}
113+
if (process.platform === 'darwin') {
114+
app.focus({
115+
steal: true,
116+
});
117+
}
118+
});
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
*/
9+
10+
const {contextBridge, ipcRenderer} = require('electron');
11+
12+
contextBridge.executeInMainWorld({
13+
func: ipcDevTools => {
14+
let didDecorateInspectorFrontendHostInstance = false;
15+
// reactNativeDecorateInspectorFrontendHostInstance was introduced in
16+
// https://github.com/facebook/react-native-devtools-frontend/pull/168
17+
globalThis.reactNativeDecorateInspectorFrontendHostInstance =
18+
InspectorFrontendHostInstance => {
19+
didDecorateInspectorFrontendHostInstance = true;
20+
InspectorFrontendHostInstance.bringToFront = () => {
21+
ipcDevTools.bringToFront();
22+
};
23+
};
24+
25+
document.addEventListener('DOMContentLoaded', () => {
26+
if (!didDecorateInspectorFrontendHostInstance) {
27+
console.error(
28+
'reactNativeDecorateInspectorFrontendHostInstance was not called at startup. ' +
29+
'This version of the DevTools frontend may not be compatible with @react-native/debugger-shell.',
30+
);
31+
}
32+
});
33+
},
34+
args: [
35+
{
36+
bringToFront() {
37+
ipcRenderer.send('bringToFront');
38+
},
39+
},
40+
],
41+
});

0 commit comments

Comments
 (0)