Allow launching inspector from dev menu

Reviewed By: davidaurelio

Differential Revision: D4095356

fbshipit-source-id: 46e43578cdcd663316efb82dffde27b77294c5c0
This commit is contained in:
Alexander Blom
2016-11-15 08:55:39 -08:00
committed by Facebook Github Bot
parent 18184a83f1
commit f571d28e68
7 changed files with 102 additions and 26 deletions

View File

@@ -19,6 +19,16 @@ public class Inspector {
private final HybridData mHybridData;
public static boolean isSupported() {
try {
// This isn't a very nice way to do this but it works :|
instance().getPagesNative();
return true;
} catch (UnsatisfiedLinkError e) {
return false;
}
}
public static List<Page> getPages() {
try {
return Arrays.asList(instance().getPagesNative());

View File

@@ -162,6 +162,12 @@ public class DevServerHelper {
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
public void openInspector(String id) {
if (mInspectorPackagerConnection != null) {
mInspectorPackagerConnection.sendOpenEvent(id);
}
}
public void closeInspectorConnection() {
new AsyncTask<Void, Void, Void>() {
@Override

View File

@@ -42,6 +42,7 @@ import com.facebook.infer.annotation.Assertions;
import com.facebook.react.R;
import com.facebook.react.bridge.CatalystInstance;
import com.facebook.react.bridge.DefaultNativeModuleCallExceptionHandler;
import com.facebook.react.bridge.Inspector;
import com.facebook.react.bridge.JavaJSExecutor;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReadableArray;
@@ -358,6 +359,19 @@ public class DevSupportManagerImpl implements DevSupportManager, PackagerCommand
handleReloadJS();
}
});
if (Inspector.isSupported()) {
options.put(
"Debug JS on-device (experimental)", new DevOptionHandler() {
@Override
public void onOptionSelected() {
List<Inspector.Page> pages = Inspector.getPages();
if (pages.size() > 0) {
// TODO: We should get the actual page id instead of the first one.
mDevServerHelper.openInspector(String.valueOf(pages.get(0).getId()));
}
}
});
}
options.put(
mDevSettings.isReloadOnJSChangeEnabled()
? mApplicationContext.getString(R.string.catalyst_live_reload_off)

View File

@@ -48,6 +48,15 @@ public class InspectorPackagerConnection {
mConnection.close();
}
public void sendOpenEvent(String pageId) {
try {
JSONObject payload = makePageIdPayload(pageId);
sendEvent("open", payload);
} catch (JSONException | IOException e) {
FLog.e(TAG, "Failed to open page", e);
}
}
void handleProxyMessage(JSONObject message)
throws JSONException, IOException {
String event = message.getString("event");