Make "Debug JS" dev menu option persist across app restarts on RN Android

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
This commit is contained in:
Siqi Liu 2016-05-27 09:45:02 -07:00 committed by Facebook Github Bot 8
parent 8d4b15d253
commit 60e0d2c676
5 changed files with 50 additions and 11 deletions

View File

@ -36,4 +36,14 @@ public class ReactSettingsForTests implements DeveloperSettings {
public boolean isElementInspectorEnabled() {
return false;
}
@Override
public boolean isRemoteJSDebugEnabled() {
return false;
}
@Override
public void setRemoteJSDebugEnabled(boolean remoteJSDebugEnabled) {
}
}

View File

@ -59,6 +59,7 @@ import com.facebook.react.devsupport.DevSupportManagerFactory;
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;
@ -362,8 +363,13 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
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();
@ -379,6 +385,8 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
if (packagerIsRunning) {
mDevSupportManager.handleReloadJS();
} else {
// If dev server is down, disable the remote JS debugging.
devSettings.setRemoteJSDebugEnabled(false);
recreateReactContextInBackgroundFromBundleFile();
}
}

View File

@ -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;
@ -108,4 +109,14 @@ public class DevInternalSettings implements
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();
}
}

View File

@ -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;
@ -139,10 +138,10 @@ public class DevSupportManagerImpl implements DevSupportManager {
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();
}
@ -265,13 +264,13 @@ public class DevSupportManagerImpl implements DevSupportManager {
}
});
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();
}
});
@ -581,13 +580,13 @@ public class DevSupportManagerImpl implements DevSupportManager {
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);

View File

@ -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);
}