Skip to content

Commit

Permalink
Make "Debug JS" dev menu option persist across app restarts on RN And…
Browse files Browse the repository at this point in the history
…roid

Summary:
1. Make "Remote JS Debug" and "Start/Stop Profile" options persist across app restarts.
2. Check and confirm:
       - All options in the Android dev menu are persisted now.
       - The behavior is the same on Android and iOS now.

Reviewed By: mkonicek

Differential Revision: D3340097

fbshipit-source-id: 4087b6605031c650e164282244cedb006f8f6fd3
  • Loading branch information
Siqi Liu authored and Facebook Github Bot 8 committed May 27, 2016
1 parent 8d4b15d commit 60e0d2c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,14 @@ public boolean isJSMinifyEnabled() {
public boolean isElementInspectorEnabled() {
return false;
}

@Override
public boolean isRemoteJSDebugEnabled() {
return false;
}

@Override
public void setRemoteJSDebugEnabled(boolean remoteJSDebugEnabled) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import com.facebook.react.devsupport.ReactInstanceDevCommandsHandler;
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.modules.debug.DeveloperSettings;
import com.facebook.react.uimanager.AppRegistry;
import com.facebook.react.uimanager.DisplayMetricsHolder;
import com.facebook.react.uimanager.UIImplementationProvider;
Expand Down Expand Up @@ -362,8 +363,13 @@ private void recreateReactContextInBackgroundInner() {
UiThreadUtil.assertOnUiThread();

if (mUseDeveloperSupport && mJSMainModuleName != null) {
if (mDevSupportManager.hasUpToDateJSBundleInCache()) {
// If there is a up-to-date bundle downloaded from server, always use that
final DeveloperSettings devSettings = mDevSupportManager.getDevSettings();

// If remote JS debugging is enabled, load from dev server.
if (mDevSupportManager.hasUpToDateJSBundleInCache() &&
!devSettings.isRemoteJSDebugEnabled()) {
// If there is a up-to-date bundle downloaded from server,
// with remote JS debugging disabled, always use that.
onJSBundleLoadedFromServer();
} else if (mJSBundleFile == null) {
mDevSupportManager.handleReloadJS();
Expand All @@ -379,6 +385,8 @@ public void run() {
if (packagerIsRunning) {
mDevSupportManager.handleReloadJS();
} else {
// If dev server is down, disable the remote JS debugging.
devSettings.setRemoteJSDebugEnabled(false);
recreateReactContextInBackgroundFromBundleFile();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class DevInternalSettings implements
private static final String PREFS_RELOAD_ON_JS_CHANGE_KEY = "reload_on_js_change";
private static final String PREFS_INSPECTOR_DEBUG_KEY = "inspector_debug";
private static final String PREFS_HOT_MODULE_REPLACEMENT_KEY = "hot_module_replacement";
private static final String PREFS_REMOTE_JS_DEBUG_KEY = "remote_js_debug";

private final SharedPreferences mPreferences;
private final DevSupportManager mDebugManager;
Expand Down Expand Up @@ -108,4 +109,14 @@ public boolean isElementInspectorEnabled() {
public void setElementInspectorEnabled(boolean enabled) {
mPreferences.edit().putBoolean(PREFS_INSPECTOR_DEBUG_KEY, enabled).apply();
}

@Override
public boolean isRemoteJSDebugEnabled() {
return mPreferences.getBoolean(PREFS_REMOTE_JS_DEBUG_KEY, false);
}

@Override
public void setRemoteJSDebugEnabled(boolean remoteJSDebugEnabled) {
mPreferences.edit().putBoolean(PREFS_REMOTE_JS_DEBUG_KEY, remoteJSDebugEnabled).apply();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ public class DevSupportManagerImpl implements DevSupportManager {
private @Nullable DebugOverlayController mDebugOverlayController;
private @Nullable ReactContext mCurrentContext;
private DevInternalSettings mDevSettings;
private boolean mIsUsingJSProxy = false;
private boolean mIsReceiverRegistered = false;
private boolean mIsShakeDetectorStarted = false;
private boolean mIsDevSupportEnabled = false;
Expand Down Expand Up @@ -139,10 +138,10 @@ public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (DevServerHelper.getReloadAppAction(context).equals(action)) {
if (intent.getBooleanExtra(DevServerHelper.RELOAD_APP_EXTRA_JS_PROXY, false)) {
mIsUsingJSProxy = true;
mDevSettings.setRemoteJSDebugEnabled(true);
mDevServerHelper.launchJSDevtools();
} else {
mIsUsingJSProxy = false;
mDevSettings.setRemoteJSDebugEnabled(false);
}
handleReloadJS();
}
Expand Down Expand Up @@ -265,13 +264,13 @@ public void onOptionSelected() {
}
});
options.put(
mIsUsingJSProxy ?
mDevSettings.isRemoteJSDebugEnabled() ?
mApplicationContext.getString(R.string.catalyst_debugjs_off) :
mApplicationContext.getString(R.string.catalyst_debugjs),
new DevOptionHandler() {
@Override
public void onOptionSelected() {
mIsUsingJSProxy = !mIsUsingJSProxy;
mDevSettings.setRemoteJSDebugEnabled(!mDevSettings.isRemoteJSDebugEnabled());
handleReloadJS();
}
});
Expand All @@ -297,7 +296,7 @@ public void onOptionSelected() {
}
});
options.put(
mApplicationContext.getString(R.string.catalyst_element_inspector),
mApplicationContext.getString(R.string.catalyst_element_inspector),
new DevOptionHandler() {
@Override
public void onOptionSelected() {
Expand Down Expand Up @@ -340,7 +339,7 @@ public void onOptionSelected() {
mCurrentContext.getCatalystInstance().supportsProfiling()) {
options.put(
mApplicationContext.getString(
mIsCurrentlyProfiling ? R.string.catalyst_stop_profile :
mIsCurrentlyProfiling ? R.string.catalyst_stop_profile :
R.string.catalyst_start_profile),
new DevOptionHandler() {
@Override
Expand Down Expand Up @@ -581,13 +580,13 @@ public void handleReloadJS() {
ProgressDialog progressDialog = new ProgressDialog(mApplicationContext);
progressDialog.setTitle(R.string.catalyst_jsload_title);
progressDialog.setMessage(mApplicationContext.getString(
mIsUsingJSProxy ? R.string.catalyst_remotedbg_message : R.string.catalyst_jsload_message));
mDevSettings.isRemoteJSDebugEnabled() ? R.string.catalyst_remotedbg_message : R.string.catalyst_jsload_message));
progressDialog.setIndeterminate(true);
progressDialog.setCancelable(false);
progressDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
progressDialog.show();

if (mIsUsingJSProxy) {
if (mDevSettings.isRemoteJSDebugEnabled()) {
reloadJSInProxyMode(progressDialog);
} else {
reloadJSFromServer(progressDialog);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,15 @@ public interface DeveloperSettings {
* @return Whether element inspector is enabled.
*/
boolean isElementInspectorEnabled();

/**
* @return Whether remote JS debugging is enabled.
*/
boolean isRemoteJSDebugEnabled();

/**
* Enable/Disable remote JS debugging.
*/
void setRemoteJSDebugEnabled(boolean remoteJSDebugEnabled);

}

0 comments on commit 60e0d2c

Please sign in to comment.