Skip to content

Commit

Permalink
Remove Flipper actions in Dev Menu, add new Open Debugger action (fac…
Browse files Browse the repository at this point in the history
…ebook#39254)

Summary:
Pull Request resolved: facebook#39254

## Context

RFC: Decoupling Flipper from React Native core: react-native-community/discussions-and-proposals#641

## Changes

- Removes Flipper-backed "Launch Debugger" and "Launch React DevTools" actions from the Dev Menu.
- Adds replacement "Launch Debugger" action triggering the new one-click Hermes debugger flow for 0.73.

Changelog:
[Android][Changed] Remove Flipper actions in Dev Menu, add new Open Debugger action

Reviewed By: motiz88

Differential Revision: D46187942

fbshipit-source-id: 1cbc29ff4f29d3088996a48e289df21a695c79fd
  • Loading branch information
huntie authored and facebook-github-bot committed Sep 1, 2023
1 parent 2a7f928 commit 580aa51
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

package com.facebook.react.devsupport;

import android.content.Context;
import android.os.AsyncTask;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -36,15 +35,11 @@
import java.util.concurrent.TimeUnit;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okio.Okio;
import okio.Sink;
import org.json.JSONException;
import org.json.JSONObject;

/**
* Helper class for all things about the debug server running in the engineer's host machine.
Expand Down Expand Up @@ -240,38 +235,6 @@ protected Void doInBackground(Void... params) {
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

public void openUrl(final ReactContext context, final String url, final String errorMessage) {
new AsyncTask<Void, String, Boolean>() {
@Override
protected Boolean doInBackground(Void... ignore) {
return doSync();
}

public boolean doSync() {
try {
String openUrlEndpoint = getOpenUrlEndpoint(context);
String jsonString = new JSONObject().put("url", url).toString();
RequestBody body = RequestBody.create(MediaType.parse("application/json"), jsonString);

Request request = new Request.Builder().url(openUrlEndpoint).post(body).build();
OkHttpClient client = new OkHttpClient();
client.newCall(request).execute();
return true;
} catch (JSONException | IOException e) {
FLog.e(ReactConstants.TAG, "Failed to open URL" + url, e);
return false;
}
}

@Override
protected void onPostExecute(Boolean result) {
if (!result) {
RNLog.w(context, errorMessage);
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

public String getWebsocketProxyURL() {
return String.format(
Locale.US,
Expand All @@ -296,11 +259,6 @@ public void downloadBundleFromURL(
mBundleDownloader.downloadBundleFromURL(callback, outputFile, bundleURL, bundleInfo);
}

private String getOpenUrlEndpoint(Context context) {
return String.format(
Locale.US, "http://%s/open-url", AndroidInfoHelpers.getServerHost(context));
}

public void downloadBundleFromURL(
DevBundleDownloadListener callback,
File outputFile,
Expand Down Expand Up @@ -458,4 +416,29 @@ public String getJSBundleURLForRemoteDebugging(String mainModuleName) {
return null;
}
}

/** Attempt to open the JS debugger on the host machine (on-device CDP debugging). */
public void openDebugger(final ReactContext context, final String errorMessage) {
// TODO(huntie): Requests to dev server should not assume 'http' URL scheme
String requestUrl =
String.format(
Locale.US,
"http://%s/open-debugger?appId=%s",
mPackagerConnectionSettings.getInspectorServerHost(),
mPackageName);
Request request = new Request.Builder().url(requestUrl).method("POST", null).build();

mClient
.newCall(request)
.enqueue(
new Callback() {
@Override
public void onFailure(@NonNull Call _call, @NonNull IOException _e) {
RNLog.w(context, errorMessage);
}

@Override
public void onResponse(@NonNull Call _call, @NonNull Response _response) {}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ public interface CallbackWithBundleLoader {
private static final int JAVA_ERROR_COOKIE = -1;
private static final int JSEXCEPTION_ERROR_COOKIE = -1;
private static final String RELOAD_APP_ACTION_SUFFIX = ".RELOAD_APP_ACTION";
private static final String FLIPPER_DEBUGGER_URL =
"flipper://null/Hermesdebuggerrn?device=React%20Native";
private static final String FLIPPER_DEVTOOLS_URL = "flipper://null/React?device=React%20Native";
private static final String EXOPACKAGE_LOCATION_FORMAT =
"/data/local/tmp/exopackage/%s//secondary-dex";

Expand Down Expand Up @@ -369,8 +366,7 @@ public void onOptionSelected() {
});

if (mDevSettings.isDeviceDebugEnabled()) {
// For on-device debugging we link out to Flipper.
// Since we're assuming Flipper is available, also include the DevTools.
// On-device JS debugging (CDP). Render action to open debugger frontend.

// Reset the old debugger setting so no one gets stuck.
// TODO: Remove in a few weeks.
Expand All @@ -381,17 +377,9 @@ public void onOptionSelected() {
options.put(
mApplicationContext.getString(R.string.catalyst_debug_open),
() ->
mDevServerHelper.openUrl(
mDevServerHelper.openDebugger(
mCurrentContext,
FLIPPER_DEBUGGER_URL,
mApplicationContext.getString(R.string.catalyst_open_flipper_error)));
options.put(
mApplicationContext.getString(R.string.catalyst_devtools_open),
() ->
mDevServerHelper.openUrl(
mCurrentContext,
FLIPPER_DEVTOOLS_URL,
mApplicationContext.getString(R.string.catalyst_open_flipper_error)));
mApplicationContext.getString(R.string.catalyst_open_debugger_error)));
}

options.put(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
<string name="catalyst_reload" project="catalyst" translatable="false">Reload</string>
<string name="catalyst_reload_error" project="catalyst" translatable="false">Failed to load bundle. Try restarting the bundler or reconnecting your device.</string>
<string name="catalyst_change_bundle_location" project="catalyst" translatable="false">Change Bundle Location</string>
<string name="catalyst_open_flipper_error" project="catalyst" translatable="false">Failed to open Flipper. Please check that Metro is running.</string>
<string name="catalyst_devtools_open" project="catalyst" translatable="false">Open React DevTools</string>
<string name="catalyst_open_debugger_error" project="catalyst" translatable="false">Failed to open debugger. Please check that the dev server is running.</string>
<string name="catalyst_debug_open" project="catalyst" translatable="false">Open Debugger</string>
<string name="catalyst_debug_connecting" project="catalyst" translatable="false">Connecting to debugger...</string>
<string name="catalyst_debug_error" project="catalyst" translatable="false">Failed to connect to debugger!</string>
Expand Down

0 comments on commit 580aa51

Please sign in to comment.