Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/debugger-shell/src/electron/MainInstanceEntryPoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

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

const windowMetadata = new WeakMap<
Expand Down Expand Up @@ -66,6 +66,7 @@ function handleLaunchArgs(argv: string[]) {
height: 600,
webPreferences: {
partition: 'persist:react-native-devtools',
preload: require.resolve('./preload.js'),
},
});

Expand Down Expand Up @@ -102,3 +103,16 @@ app.whenReady().then(() => {
app.on('window-all-closed', function () {
app.quit();
});

ipcMain.on('bringToFront', (event, title) => {
const webContents = event.sender;
const win = BrowserWindow.fromWebContents(webContents);
if (win) {
win.focus();
}
if (process.platform === 'darwin') {
app.focus({
steal: true,
});
}
});
41 changes: 41 additions & 0 deletions packages/debugger-shell/src/electron/preload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/

const {contextBridge, ipcRenderer} = require('electron');

contextBridge.executeInMainWorld({
func: ipcDevTools => {
let didDecorateInspectorFrontendHostInstance = false;
// reactNativeDecorateInspectorFrontendHostInstance was introduced in
// https://github.com/facebook/react-native-devtools-frontend/pull/168
globalThis.reactNativeDecorateInspectorFrontendHostInstance =
InspectorFrontendHostInstance => {
didDecorateInspectorFrontendHostInstance = true;
InspectorFrontendHostInstance.bringToFront = () => {
ipcDevTools.bringToFront();
};
};

document.addEventListener('DOMContentLoaded', () => {
if (!didDecorateInspectorFrontendHostInstance) {
console.error(
'reactNativeDecorateInspectorFrontendHostInstance was not called at startup. ' +
'This version of the DevTools frontend may not be compatible with @react-native/debugger-shell.',
);
}
});
},
args: [
{
bringToFront() {
ipcRenderer.send('bringToFront');
},
},
],
});
Loading