|
48 | 48 | import com.facebook.react.common.ReactConstants;
|
49 | 49 | import com.facebook.react.common.ShakeDetector;
|
50 | 50 | import com.facebook.react.common.futures.SimpleSettableFuture;
|
| 51 | +import com.facebook.react.devsupport.DevServerHelper.PackagerCommandListener; |
51 | 52 | import com.facebook.react.devsupport.StackTraceHelper.StackFrame;
|
52 | 53 | import com.facebook.react.modules.debug.DeveloperSettings;
|
53 | 54 |
|
|
82 | 83 | * {@code <activity android:name="com.facebook.react.devsupport.DevSettingsActivity"/>}
|
83 | 84 | * {@code <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>}
|
84 | 85 | */
|
85 |
| -public class DevSupportManagerImpl implements DevSupportManager { |
| 86 | +public class DevSupportManagerImpl implements DevSupportManager, PackagerCommandListener { |
86 | 87 |
|
87 | 88 | private static final int JAVA_ERROR_COOKIE = -1;
|
88 | 89 | private static final int JSEXCEPTION_ERROR_COOKIE = -1;
|
@@ -120,7 +121,6 @@ private static enum ErrorType {
|
120 | 121 | private int mLastErrorCookie = 0;
|
121 | 122 | private @Nullable ErrorType mLastErrorType;
|
122 | 123 |
|
123 |
| - |
124 | 124 | private static class JscProfileTask extends AsyncTask<String, Void, Void> {
|
125 | 125 | private static final MediaType JSON =
|
126 | 126 | MediaType.parse("application/json; charset=utf-8");
|
@@ -178,19 +178,7 @@ public DevSupportManagerImpl(
|
178 | 178 | mApplicationContext = applicationContext;
|
179 | 179 | mJSAppBundleName = packagerPathForJSBundleName;
|
180 | 180 | mDevSettings = new DevInternalSettings(applicationContext, this);
|
181 |
| - mDevServerHelper = new DevServerHelper( |
182 |
| - mDevSettings, |
183 |
| - new DevServerHelper.PackagerCommandListener() { |
184 |
| - @Override |
185 |
| - public void onReload() { |
186 |
| - UiThreadUtil.runOnUiThread(new Runnable() { |
187 |
| - @Override |
188 |
| - public void run() { |
189 |
| - handleReloadJS(); |
190 |
| - } |
191 |
| - }); |
192 |
| - } |
193 |
| - }); |
| 181 | + mDevServerHelper = new DevServerHelper(mDevSettings); |
194 | 182 |
|
195 | 183 | // Prepare shake gesture detector (will be started/stopped from #reload)
|
196 | 184 | mShakeDetector = new ShakeDetector(new ShakeDetector.ShakeListener() {
|
@@ -237,8 +225,11 @@ public void handleException(Exception e) {
|
237 | 225 | if (e instanceof JSException) {
|
238 | 226 | FLog.e(ReactConstants.TAG, "Exception in native call from JS", e);
|
239 | 227 | // TODO #11638796: convert the stack into something useful
|
240 |
| - showNewError(e.getMessage() + "\n\n" + ((JSException) e).getStack(), new StackFrame[] {}, |
241 |
| - JSEXCEPTION_ERROR_COOKIE, ErrorType.JS); |
| 228 | + showNewError( |
| 229 | + e.getMessage() + "\n\n" + ((JSException) e).getStack(), |
| 230 | + new StackFrame[] {}, |
| 231 | + JSEXCEPTION_ERROR_COOKIE, |
| 232 | + ErrorType.JS); |
242 | 233 | } else {
|
243 | 234 | showNewJavaError(e.getMessage(), e);
|
244 | 235 | }
|
@@ -388,7 +379,7 @@ public void onOptionSelected() {
|
388 | 379 | }
|
389 | 380 | });
|
390 | 381 | options.put(
|
391 |
| - mApplicationContext.getString(R.string.catalyst_element_inspector), |
| 382 | + mApplicationContext.getString(R.string.catalyst_element_inspector), |
392 | 383 | new DevOptionHandler() {
|
393 | 384 | @Override
|
394 | 385 | public void onOptionSelected() {
|
@@ -674,6 +665,16 @@ public void isPackagerRunning(DevServerHelper.PackagerStatusCallback callback) {
|
674 | 665 | return mLastErrorStack;
|
675 | 666 | }
|
676 | 667 |
|
| 668 | + @Override |
| 669 | + public void onPackagerReloadCommand() { |
| 670 | + UiThreadUtil.runOnUiThread(new Runnable() { |
| 671 | + @Override |
| 672 | + public void run() { |
| 673 | + handleReloadJS(); |
| 674 | + } |
| 675 | + }); |
| 676 | + } |
| 677 | + |
677 | 678 | private void updateLastErrorInfo(
|
678 | 679 | final String message,
|
679 | 680 | final StackFrame[] stack,
|
@@ -802,6 +803,7 @@ private void reload() {
|
802 | 803 | mIsReceiverRegistered = true;
|
803 | 804 | }
|
804 | 805 |
|
| 806 | + mDevServerHelper.openPackagerConnection(this); |
805 | 807 | if (mDevSettings.isReloadOnJSChangeEnabled()) {
|
806 | 808 | mDevServerHelper.startPollingOnChangeEndpoint(
|
807 | 809 | new DevServerHelper.OnServerContentChangeListener() {
|
@@ -841,6 +843,7 @@ public void onServerContentChanged() {
|
841 | 843 | mDevOptionsDialog.dismiss();
|
842 | 844 | }
|
843 | 845 |
|
| 846 | + mDevServerHelper.closePackagerConnection(); |
844 | 847 | mDevServerHelper.stopPollingOnChangeEndpoint();
|
845 | 848 | }
|
846 | 849 | }
|
|
0 commit comments