From f635c574d9720bb395154855d08ab2f2adea8f0a Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Wed, 22 May 2024 11:35:18 -0700 Subject: [PATCH] Expose DevSettings.openDebugger method to JS Summary: Changelog: [Internal] Adds a private API that gives JS the ability to trigger the same "open debugger" action as in the Dev Menu. This is in preparation for changes to LogBox. For simplicity, this method operates on a best-effort basis - i.e. it doesn't report the success or failure (or failure reason) of the launch. Differential Revision: D57681447 --- .../react-native/React/CoreModules/RCTDevSettings.mm | 12 ++++++++++++ .../react/modules/debug/DevSettingsModule.kt | 4 ++++ .../src/private/specs/modules/NativeDevSettings.js | 1 + 3 files changed, 17 insertions(+) diff --git a/packages/react-native/React/CoreModules/RCTDevSettings.mm b/packages/react-native/React/CoreModules/RCTDevSettings.mm index 887a69c06c1b37..8f61c6d0090ba1 100644 --- a/packages/react-native/React/CoreModules/RCTDevSettings.mm +++ b/packages/react-native/React/CoreModules/RCTDevSettings.mm @@ -501,6 +501,15 @@ - (void)setupHMRClientWithAdditionalBundleURL:(NSURL *)bundleURL } } +RCT_EXPORT_METHOD(openDebugger) +{ +#ifdef RCT_ENABLE_INSPECTOR + [RCTInspectorDevServerHelper + openDebugger:self.bundleManager.bundleURL + withErrorMessage:@"Failed to open debugger. Please check that the dev server is running and reload the app."]; +#endif +} + #pragma mark - Internal /** @@ -608,6 +617,9 @@ - (void)setupHMRClientWithBundleURL:(NSURL *)bundleURL - (void)setupHMRClientWithAdditionalBundleURL:(NSURL *)bundleURL { } +- (void)openDebugger +{ +} - (void)addMenuItem:(NSString *)title { } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DevSettingsModule.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DevSettingsModule.kt index 258f8042c5fec1..a482235ab8392e 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DevSettingsModule.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DevSettingsModule.kt @@ -61,6 +61,10 @@ public class DevSettingsModule( } } + override fun openDebugger() { + devSupportManager.openDebugger() + } + override fun setIsShakeToShowDevMenuEnabled(enabled: Boolean) { // iOS only } diff --git a/packages/react-native/src/private/specs/modules/NativeDevSettings.js b/packages/react-native/src/private/specs/modules/NativeDevSettings.js index 26085ad6bc3a38..2afb1d54f3649d 100644 --- a/packages/react-native/src/private/specs/modules/NativeDevSettings.js +++ b/packages/react-native/src/private/specs/modules/NativeDevSettings.js @@ -21,6 +21,7 @@ export interface Spec extends TurboModule { +setProfilingEnabled: (isProfilingEnabled: boolean) => void; +toggleElementInspector: () => void; +addMenuItem: (title: string) => void; + +openDebugger?: () => void; // Events +addListener: (eventName: string) => void;