Skip to content
Open
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
2 changes: 1 addition & 1 deletion packages/debugger-shell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"fb-dotslash": "0.5.8"
},
"devDependencies": {
"electron": "39.8.10",
"electron": "43.0.0",
"semver": "^7.1.3"
},
"files": [
Expand Down
129 changes: 129 additions & 0 deletions packages/debugger-shell/src/electron/AppMenu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/**
* 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.
*
* @flow strict-local
* @format
*/

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

const {isMacOSAtLeast} = require('./utils');

export function configureAppMenu(): void {
const template = [
...(process.platform === 'darwin' ? [{role: 'appMenu'}] : []),
{
label: 'File',
submenu: [
{
label: 'Reload App',
accelerator:
process.platform === 'darwin' ? 'Command+R' : 'Control+R',
click: () => invokeCommand('inspector-main.reload'),
},
{
label: 'Reload DevTools',
accelerator: process.platform === 'darwin' ? 'Option+R' : 'Alt+R',
click: () => BrowserWindow.getFocusedWindow()?.webContents.reload(),
},
{type: 'separator'},
{
label: 'Quick Open…',
...menuSymbol('doc.text.magnifyingglass'),
accelerator:
process.platform === 'darwin' ? 'Command+P' : 'Control+P',
click: () => invokeCommand('quick-open.show'),
},
{type: 'separator'},
{role: 'close'},
],
},
{
label: 'Edit',
submenu: [
{role: 'undo'},
{role: 'redo'},
{type: 'separator'},
{role: 'cut'},
{role: 'copy'},
{role: 'paste'},
{role: 'selectAll'},
],
},
{
label: 'View',
submenu: [
{
label: 'Command Palette…',
...menuSymbol('filemenu.and.selection'),
accelerator:
process.platform === 'darwin'
? 'Command+Shift+P'
: 'Control+Shift+P',
click: () => invokeCommand('quick-open.show-command-menu'),
},
// Enable Developer Tools only in development
...(!app.isPackaged
? [{type: 'separator'}, {role: 'toggleDevTools'}]
: []),
{type: 'separator'},
{role: 'resetZoom'},
{role: 'zoomIn'},
{role: 'zoomOut'},
{type: 'separator'},
{role: 'togglefullscreen'},
],
},
{role: 'windowMenu'},
{
role: 'help',
submenu: [
{
label: 'Keyboard Shortcuts',
...menuSymbol('keyboard'),
click: () => invokeCommand('settings.shortcuts'),
},
{type: 'separator'},
{
label: 'React Native Website',
click: () => shell.openExternal('https://reactnative.dev'),
},
{
label: 'Release Notes',
click: () =>
shell.openExternal(
'https://github.com/facebook/react-native/releases',
),
},
],
},
];
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
}

function menuSymbol(symbolName: string): {icon?: unknown} {
if (!isMacOSAtLeast(26)) {
return {};
}
return {
icon: nativeImage.createMenuSymbol(symbolName),
};
}

function invokeCommand(commandId: string): void {
const win = BrowserWindow.getFocusedWindow();
win?.webContents.executeJavaScript(
`(async () => {
const UI = await import('./ui/legacy/legacy.js');
return UI.ActionRegistry.ActionRegistry.instance()
.getAction(${JSON.stringify(commandId)})?.execute();
})()`,
true,
);
}
31 changes: 2 additions & 29 deletions packages/debugger-shell/src/electron/MainInstanceEntryPoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
* @format
*/

import {configureAppMenu} from './AppMenu.js';
import SettingsStore from './SettingsStore.js';

const path = require('path');
const util = require('util');

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

const appSettings = new SettingsStore();
const windowMetadata = new WeakMap<
Expand Down Expand Up @@ -102,34 +103,6 @@ function handleLaunchArgs(argv: string[]) {
frontendWindow.focus();
}

function configureAppMenu() {
const template = [
...(process.platform === 'darwin' ? [{role: 'appMenu'}] : []),
{role: 'fileMenu'},
{role: 'editMenu'},
{role: 'viewMenu'},
{role: 'windowMenu'},
{
role: 'help',
submenu: [
{
label: 'React Native Website',
click: () => shell.openExternal('https://reactnative.dev'),
},
{
label: 'Release Notes',
click: () =>
shell.openExternal(
'https://github.com/facebook/react-native/releases',
),
},
],
},
];
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
}

function getSavedWindowPosition(
windowKey: string,
): ?{width: number, height: number, x?: number, y?: number} {
Expand Down
18 changes: 18 additions & 0 deletions packages/debugger-shell/src/electron/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* 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.
*
* @flow strict-local
* @format
*/

/** Equivalent of Swift's `if #available(macOS 26, *)`. */
export function isMacOSAtLeast(major: number): boolean {
return (
process.platform === 'darwin' &&
// $FlowFixMe[prop-missing]
Number.parseInt(process.getSystemVersion().split('.')[0], 10) >= major
);
}
Loading
Loading