|
12 | 12 | import android.content.Context;
|
13 | 13 | import android.os.AsyncTask;
|
14 | 14 | import android.os.Handler;
|
| 15 | +import android.widget.Toast; |
15 | 16 | import com.facebook.common.logging.FLog;
|
16 | 17 | import com.facebook.infer.annotation.Assertions;
|
| 18 | +import com.facebook.react.R; |
17 | 19 | import com.facebook.react.bridge.UiThreadUtil;
|
18 | 20 | import com.facebook.react.common.ReactConstants;
|
19 | 21 | import com.facebook.react.common.network.OkHttpCallUtil;
|
@@ -73,6 +75,7 @@ public class DevServerHelper {
|
73 | 75 | private static final String PACKAGER_STATUS_URL_FORMAT = "http://%s/status";
|
74 | 76 | private static final String HEAP_CAPTURE_UPLOAD_URL_FORMAT = "http://%s/jscheapcaptureupload";
|
75 | 77 | private static final String INSPECTOR_DEVICE_URL_FORMAT = "http://%s/inspector/device?name=%s&app=%s";
|
| 78 | + private static final String INSPECTOR_ATTACH_URL_FORMAT = "http://%s/nuclide/attach-debugger-nuclide?title=%s&app=%s&device=%s"; |
76 | 79 | private static final String SYMBOLICATE_URL_FORMAT = "http://%s/symbolicate";
|
77 | 80 | private static final String OPEN_STACK_FRAME_URL_FORMAT = "http://%s/open-stack-frame";
|
78 | 81 |
|
@@ -224,6 +227,36 @@ protected Void doInBackground(Void... params) {
|
224 | 227 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
225 | 228 | }
|
226 | 229 |
|
| 230 | + public void attachDebugger(final Context context, final String title) { |
| 231 | + new AsyncTask<Void, String, Boolean>() { |
| 232 | + @Override |
| 233 | + protected Boolean doInBackground(Void... ignore) { |
| 234 | + return doSync(); |
| 235 | + } |
| 236 | + |
| 237 | + public boolean doSync() { |
| 238 | + try { |
| 239 | + String attachToNuclideUrl = getInspectorAttachUrl(title); |
| 240 | + OkHttpClient client = new OkHttpClient(); |
| 241 | + Request request = new Request.Builder().url(attachToNuclideUrl).build(); |
| 242 | + client.newCall(request).execute(); |
| 243 | + return true; |
| 244 | + } catch (IOException e) { |
| 245 | + FLog.e(ReactConstants.TAG, "Failed to send attach request to Inspector", e); |
| 246 | + return false; |
| 247 | + } |
| 248 | + } |
| 249 | + |
| 250 | + @Override |
| 251 | + protected void onPostExecute(Boolean result) { |
| 252 | + if (!result) { |
| 253 | + String message = context.getString(R.string.catalyst_debugjs_nuclide_failure); |
| 254 | + Toast.makeText(context, message, Toast.LENGTH_LONG).show(); |
| 255 | + } |
| 256 | + } |
| 257 | + }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
| 258 | + } |
| 259 | + |
227 | 260 | public void symbolicateStackTrace(
|
228 | 261 | Iterable<StackFrame> stackFrames,
|
229 | 262 | final SymbolicationListener listener) {
|
@@ -321,6 +354,16 @@ public String getInspectorDeviceUrl() {
|
321 | 354 | mPackageName);
|
322 | 355 | }
|
323 | 356 |
|
| 357 | + public String getInspectorAttachUrl(String title) { |
| 358 | + return String.format( |
| 359 | + Locale.US, |
| 360 | + INSPECTOR_ATTACH_URL_FORMAT, |
| 361 | + AndroidInfoHelpers.getServerHost(), |
| 362 | + title, |
| 363 | + mPackageName, |
| 364 | + AndroidInfoHelpers.getFriendlyDeviceName()); |
| 365 | + } |
| 366 | + |
324 | 367 | public BundleDownloader getBundleDownloader() {
|
325 | 368 | return mBundleDownloader;
|
326 | 369 | }
|
|
0 commit comments