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:
parent
8d4b15d253
commit
60e0d2c676
|
@ -36,4 +36,14 @@ public class ReactSettingsForTests implements DeveloperSettings {
|
||||||
public boolean isElementInspectorEnabled() {
|
public boolean isElementInspectorEnabled() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isRemoteJSDebugEnabled() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setRemoteJSDebugEnabled(boolean remoteJSDebugEnabled) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@ import com.facebook.react.devsupport.DevSupportManagerFactory;
|
||||||
import com.facebook.react.devsupport.ReactInstanceDevCommandsHandler;
|
import com.facebook.react.devsupport.ReactInstanceDevCommandsHandler;
|
||||||
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
|
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
|
||||||
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
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.AppRegistry;
|
||||||
import com.facebook.react.uimanager.DisplayMetricsHolder;
|
import com.facebook.react.uimanager.DisplayMetricsHolder;
|
||||||
import com.facebook.react.uimanager.UIImplementationProvider;
|
import com.facebook.react.uimanager.UIImplementationProvider;
|
||||||
|
@ -362,8 +363,13 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||||
UiThreadUtil.assertOnUiThread();
|
UiThreadUtil.assertOnUiThread();
|
||||||
|
|
||||||
if (mUseDeveloperSupport && mJSMainModuleName != null) {
|
if (mUseDeveloperSupport && mJSMainModuleName != null) {
|
||||||
if (mDevSupportManager.hasUpToDateJSBundleInCache()) {
|
final DeveloperSettings devSettings = mDevSupportManager.getDevSettings();
|
||||||
// If there is a up-to-date bundle downloaded from server, always use that
|
|
||||||
|
// 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();
|
onJSBundleLoadedFromServer();
|
||||||
} else if (mJSBundleFile == null) {
|
} else if (mJSBundleFile == null) {
|
||||||
mDevSupportManager.handleReloadJS();
|
mDevSupportManager.handleReloadJS();
|
||||||
|
@ -379,6 +385,8 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||||
if (packagerIsRunning) {
|
if (packagerIsRunning) {
|
||||||
mDevSupportManager.handleReloadJS();
|
mDevSupportManager.handleReloadJS();
|
||||||
} else {
|
} else {
|
||||||
|
// If dev server is down, disable the remote JS debugging.
|
||||||
|
devSettings.setRemoteJSDebugEnabled(false);
|
||||||
recreateReactContextInBackgroundFromBundleFile();
|
recreateReactContextInBackgroundFromBundleFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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_RELOAD_ON_JS_CHANGE_KEY = "reload_on_js_change";
|
||||||
private static final String PREFS_INSPECTOR_DEBUG_KEY = "inspector_debug";
|
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_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 SharedPreferences mPreferences;
|
||||||
private final DevSupportManager mDebugManager;
|
private final DevSupportManager mDebugManager;
|
||||||
|
@ -108,4 +109,14 @@ public class DevInternalSettings implements
|
||||||
public void setElementInspectorEnabled(boolean enabled) {
|
public void setElementInspectorEnabled(boolean enabled) {
|
||||||
mPreferences.edit().putBoolean(PREFS_INSPECTOR_DEBUG_KEY, enabled).apply();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,6 @@ public class DevSupportManagerImpl implements DevSupportManager {
|
||||||
private @Nullable DebugOverlayController mDebugOverlayController;
|
private @Nullable DebugOverlayController mDebugOverlayController;
|
||||||
private @Nullable ReactContext mCurrentContext;
|
private @Nullable ReactContext mCurrentContext;
|
||||||
private DevInternalSettings mDevSettings;
|
private DevInternalSettings mDevSettings;
|
||||||
private boolean mIsUsingJSProxy = false;
|
|
||||||
private boolean mIsReceiverRegistered = false;
|
private boolean mIsReceiverRegistered = false;
|
||||||
private boolean mIsShakeDetectorStarted = false;
|
private boolean mIsShakeDetectorStarted = false;
|
||||||
private boolean mIsDevSupportEnabled = false;
|
private boolean mIsDevSupportEnabled = false;
|
||||||
|
@ -139,10 +138,10 @@ public class DevSupportManagerImpl implements DevSupportManager {
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
if (DevServerHelper.getReloadAppAction(context).equals(action)) {
|
if (DevServerHelper.getReloadAppAction(context).equals(action)) {
|
||||||
if (intent.getBooleanExtra(DevServerHelper.RELOAD_APP_EXTRA_JS_PROXY, false)) {
|
if (intent.getBooleanExtra(DevServerHelper.RELOAD_APP_EXTRA_JS_PROXY, false)) {
|
||||||
mIsUsingJSProxy = true;
|
mDevSettings.setRemoteJSDebugEnabled(true);
|
||||||
mDevServerHelper.launchJSDevtools();
|
mDevServerHelper.launchJSDevtools();
|
||||||
} else {
|
} else {
|
||||||
mIsUsingJSProxy = false;
|
mDevSettings.setRemoteJSDebugEnabled(false);
|
||||||
}
|
}
|
||||||
handleReloadJS();
|
handleReloadJS();
|
||||||
}
|
}
|
||||||
|
@ -265,13 +264,13 @@ public class DevSupportManagerImpl implements DevSupportManager {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
options.put(
|
options.put(
|
||||||
mIsUsingJSProxy ?
|
mDevSettings.isRemoteJSDebugEnabled() ?
|
||||||
mApplicationContext.getString(R.string.catalyst_debugjs_off) :
|
mApplicationContext.getString(R.string.catalyst_debugjs_off) :
|
||||||
mApplicationContext.getString(R.string.catalyst_debugjs),
|
mApplicationContext.getString(R.string.catalyst_debugjs),
|
||||||
new DevOptionHandler() {
|
new DevOptionHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void onOptionSelected() {
|
public void onOptionSelected() {
|
||||||
mIsUsingJSProxy = !mIsUsingJSProxy;
|
mDevSettings.setRemoteJSDebugEnabled(!mDevSettings.isRemoteJSDebugEnabled());
|
||||||
handleReloadJS();
|
handleReloadJS();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -297,7 +296,7 @@ public class DevSupportManagerImpl implements DevSupportManager {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
options.put(
|
options.put(
|
||||||
mApplicationContext.getString(R.string.catalyst_element_inspector),
|
mApplicationContext.getString(R.string.catalyst_element_inspector),
|
||||||
new DevOptionHandler() {
|
new DevOptionHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void onOptionSelected() {
|
public void onOptionSelected() {
|
||||||
|
@ -340,7 +339,7 @@ public class DevSupportManagerImpl implements DevSupportManager {
|
||||||
mCurrentContext.getCatalystInstance().supportsProfiling()) {
|
mCurrentContext.getCatalystInstance().supportsProfiling()) {
|
||||||
options.put(
|
options.put(
|
||||||
mApplicationContext.getString(
|
mApplicationContext.getString(
|
||||||
mIsCurrentlyProfiling ? R.string.catalyst_stop_profile :
|
mIsCurrentlyProfiling ? R.string.catalyst_stop_profile :
|
||||||
R.string.catalyst_start_profile),
|
R.string.catalyst_start_profile),
|
||||||
new DevOptionHandler() {
|
new DevOptionHandler() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -581,13 +580,13 @@ public class DevSupportManagerImpl implements DevSupportManager {
|
||||||
ProgressDialog progressDialog = new ProgressDialog(mApplicationContext);
|
ProgressDialog progressDialog = new ProgressDialog(mApplicationContext);
|
||||||
progressDialog.setTitle(R.string.catalyst_jsload_title);
|
progressDialog.setTitle(R.string.catalyst_jsload_title);
|
||||||
progressDialog.setMessage(mApplicationContext.getString(
|
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.setIndeterminate(true);
|
||||||
progressDialog.setCancelable(false);
|
progressDialog.setCancelable(false);
|
||||||
progressDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
|
progressDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
|
||||||
progressDialog.show();
|
progressDialog.show();
|
||||||
|
|
||||||
if (mIsUsingJSProxy) {
|
if (mDevSettings.isRemoteJSDebugEnabled()) {
|
||||||
reloadJSInProxyMode(progressDialog);
|
reloadJSInProxyMode(progressDialog);
|
||||||
} else {
|
} else {
|
||||||
reloadJSFromServer(progressDialog);
|
reloadJSFromServer(progressDialog);
|
||||||
|
|
|
@ -38,4 +38,15 @@ public interface DeveloperSettings {
|
||||||
* @return Whether element inspector is enabled.
|
* @return Whether element inspector is enabled.
|
||||||
*/
|
*/
|
||||||
boolean isElementInspectorEnabled();
|
boolean isElementInspectorEnabled();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Whether remote JS debugging is enabled.
|
||||||
|
*/
|
||||||
|
boolean isRemoteJSDebugEnabled();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable/Disable remote JS debugging.
|
||||||
|
*/
|
||||||
|
void setRemoteJSDebugEnabled(boolean remoteJSDebugEnabled);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue