first commit

This commit is contained in:
2026-03-10 16:18:05 +00:00
commit 11f9c069b5
31635 changed files with 3187747 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
/**
* 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
*/
declare const $$EXPORT_DEFAULT_DECLARATION$$: { revision: "dev" };
declare type $$EXPORT_DEFAULT_DECLARATION$$ =
typeof $$EXPORT_DEFAULT_DECLARATION$$;
export default $$EXPORT_DEFAULT_DECLARATION$$;

View File

@@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.default = void 0;
var _default = (exports.default = {
revision: "dev",
});

View File

@@ -0,0 +1,11 @@
/**
* 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
*/
declare export default { revision: "dev" };

View File

@@ -0,0 +1,19 @@
/**
* 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.
*
* %s
* @flow strict-local
* @format
*/
'use strict';
module.exports = {
default: {
revision: %s,
},
__esModule: true,
};

View File

@@ -0,0 +1,9 @@
/**
* 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
*/

View File

@@ -0,0 +1,162 @@
"use strict";
var _SettingsStore = _interopRequireDefault(require("./SettingsStore.js"));
function _interopRequireDefault(e) {
return e && e.__esModule ? e : { default: e };
}
const path = require("path");
const util = require("util");
const { BrowserWindow, Menu, app, shell, ipcMain } = require("electron");
const appSettings = new _SettingsStore.default();
const windowMetadata = new WeakMap();
function handleLaunchArgs(argv) {
const {
values: { frontendUrl, windowKey },
} = util.parseArgs({
options: {
frontendUrl: {
type: "string",
},
windowKey: {
type: "string",
},
},
args: argv,
});
let frontendWindow = BrowserWindow.getAllWindows().find((window) => {
const metadata = windowMetadata.get(window);
if (!metadata) {
return false;
}
return metadata.windowKey === windowKey;
});
if (frontendWindow) {
if (frontendWindow.isVisible()) {
frontendWindow.flashFrame(true);
setTimeout(() => {
frontendWindow.flashFrame(false);
}, 1000);
}
} else {
frontendWindow = new BrowserWindow({
...(getSavedWindowPosition(windowKey) ?? {
width: 1200,
height: 600,
}),
webPreferences: {
partition: "persist:react-native-devtools",
preload: require.resolve("./preload.js"),
},
icon: path.join(__dirname, "resources", "icon.png"),
});
frontendWindow.setMenuBarVisibility(false);
setupWindowResizeListeners(frontendWindow, windowKey);
}
frontendWindow.webContents.setWindowOpenHandler(({ url }) => {
shell.openExternal(url);
return {
action: "deny",
};
});
frontendWindow.loadURL(frontendUrl);
windowMetadata.set(frontendWindow, {
windowKey,
});
if (process.platform === "darwin") {
app.focus({
steal: true,
});
}
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) {
return appSettings.get("windowArrangements", {})[windowKey];
}
function saveWindowPosition(windowKey, position) {
const windowArrangements = appSettings.get("windowArrangements", {});
windowArrangements[windowKey] = position;
appSettings.set("windowArrangements", windowArrangements);
}
function setupWindowResizeListeners(browserWindow, windowKey) {
const savePosition = () => {
if (!browserWindow.isDestroyed()) {
const [x, y] = browserWindow.getPosition();
const [width, height] = browserWindow.getSize();
saveWindowPosition(windowKey, {
x,
y,
width,
height,
});
}
};
browserWindow.on("moved", savePosition);
browserWindow.on("resized", savePosition);
browserWindow.on("closed", savePosition);
}
app.whenReady().then(() => {
handleLaunchArgs(process.argv.slice(app.isPackaged ? 1 : 2));
configureAppMenu();
app.on(
"second-instance",
(event, electronArgv, workingDirectory, additionalData) => {
handleLaunchArgs(additionalData.argv);
},
);
});
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,
});
}
});

View File

@@ -0,0 +1,9 @@
/**
* 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
*/

View File

@@ -0,0 +1,39 @@
/**
* 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
* @oncall react_native
*/
type Options = Readonly<{ name?: string; defaults?: Object }>;
/**
* A data persistence layer for storing application settings, modelled after
* [`electron-store`](https://www.npmjs.com/package/electron-store).
*
* Values are saved in a `config.json` file in `app.getPath('userData')`.
*
* Compatibility:
* - Maintains API and file format compatibility with `electron-store@8.2.0`.
* - Supports the Electron main process only.
*/
declare class SettingsStore {
path: string;
constructor(options?: Options);
get(key: string, defaultValue?: any): any;
set(key: string, value: any): void;
has(key: string): boolean;
reset(...keys: Array<string>): void;
delete(key: string): void;
clear(): void;
get store(): { [$$Key$$: string]: unknown };
set store(value: unknown);
_deserialize: (value: string) => unknown;
_serialize: (value: unknown) => string;
_ensureDirectory(): void;
_write(value: unknown): void;
}
export default SettingsStore;

View File

@@ -0,0 +1,95 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.default = void 0;
const { app } = require("electron");
const fs = require("fs");
const path = require("path");
class SettingsStore {
#defaultValues = {};
constructor(options = {}) {
options = {
name: "config",
...options,
};
this.#defaultValues = {
...this.#defaultValues,
...options.defaults,
};
this.path = path.resolve(
app.getPath("userData"),
`${options.name ?? "config"}.json`,
);
}
get(key, defaultValue) {
const store = this.store;
return store[key] !== undefined ? store[key] : defaultValue;
}
set(key, value) {
const { store } = this;
if (typeof key === "object") {
for (const [k, v] of Object.entries(key)) {
store[k] = v;
}
} else {
store[key] = value;
}
this.store = store;
}
has(key) {
return key in this.store;
}
reset(...keys) {
for (const key of keys) {
if (this.#defaultValues[key] != null) {
this.set(key, this.#defaultValues[key]);
}
}
}
delete(key) {
const { store } = this;
delete store[key];
this.store = store;
}
clear() {
this.store = {};
for (const key of Object.keys(this.#defaultValues)) {
this.reset(key);
}
}
get store() {
try {
const data = fs.readFileSync(this.path, "utf8");
const deserializedData = this._deserialize(data);
return {
...deserializedData,
};
} catch (error) {
if (error?.code === "ENOENT") {
this._ensureDirectory();
return {};
}
throw error;
}
}
set store(value) {
this._ensureDirectory();
this._write(value);
}
_deserialize = (value) => JSON.parse(value);
_serialize = (value) => JSON.stringify(value, undefined, "\t") ?? "";
_ensureDirectory() {
fs.mkdirSync(path.dirname(this.path), {
recursive: true,
});
}
_write(value) {
const data = this._serialize(value);
fs.writeFileSync(this.path, data, {
mode: 0o666,
});
}
}
exports.default = SettingsStore;

View File

@@ -0,0 +1,42 @@
/**
* 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
* @format
* @oncall react_native
*/
type Options = $ReadOnly<{
name?: string,
defaults?: Object,
}>;
/**
* A data persistence layer for storing application settings, modelled after
* [`electron-store`](https://www.npmjs.com/package/electron-store).
*
* Values are saved in a `config.json` file in `app.getPath('userData')`.
*
* Compatibility:
* - Maintains API and file format compatibility with `electron-store@8.2.0`.
* - Supports the Electron main process only.
*/
declare export default class SettingsStore {
path: string;
constructor(options?: Options): void;
get(key: string, defaultValue?: any): any;
set(key: string, value: any): void;
has(key: string): boolean;
reset(...keys: Array<string>): void;
delete(key: string): void;
clear(): void;
get store(): { [string]: mixed };
set store(value: mixed): void;
_deserialize: (value: string) => mixed;
_serialize: (value: mixed) => string;
_ensureDirectory(): void;
_write(value: mixed): void;
}

View File

@@ -0,0 +1,9 @@
/**
* 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
*/

View File

@@ -0,0 +1,34 @@
"use strict";
var _BuildInfo = _interopRequireDefault(require("./BuildInfo"));
function _interopRequireDefault(e) {
return e && e.__esModule ? e : { default: e };
}
const pkg = require("../../package.json");
const util = require("util");
const { app } = require("electron");
app.setName(pkg.productName ?? pkg.name);
app.setVersion(pkg.version + "-" + _BuildInfo.default.revision);
const {
values: { version = false },
} = util.parseArgs({
options: {
version: {
type: "boolean",
},
},
args: process.argv.slice(app.isPackaged ? 1 : 2),
strict: false,
});
if (version) {
console.log(`${pkg.name} v${app.getVersion()}`);
app.exit(0);
}
const gotTheLock = app.requestSingleInstanceLock({
argv: process.argv.slice(app.isPackaged ? 1 : 2),
});
if (!gotTheLock) {
app.quit();
} else {
require("./MainInstanceEntryPoint.js");
}

View File

@@ -0,0 +1,9 @@
/**
* 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
*/

View File

@@ -0,0 +1,9 @@
/**
* 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
*/

View File

@@ -0,0 +1,31 @@
"use strict";
const { contextBridge, ipcRenderer } = require("electron");
contextBridge.executeInMainWorld({
func: (ipcDevTools) => {
let didDecorateInspectorFrontendHostInstance = false;
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");
},
},
],
});

View File

@@ -0,0 +1,9 @@
/**
* 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
*/

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 KiB