mirror of
https://github.com/status-im/react-native.git
synced 2025-02-05 14:13:26 +00:00
Add a debug support to load js bundle from external URL
Summary: Code refactoring on the dev support class. The idea is to make the code more modular. Reviewed By: mhorowitz Differential Revision: D4164676 fbshipit-source-id: 0d29bdaf927cd0e9f399fe6f8e46a16dfa65fb69
This commit is contained in:
parent
92fd0c2a5b
commit
72b517049a
@ -222,16 +222,19 @@ public class DevServerHelper {
|
|||||||
return String.format(Locale.US, RESOURCE_URL_FORMAT, host, resourcePath);
|
return String.format(Locale.US, RESOURCE_URL_FORMAT, host, resourcePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDevServerBundleURL(final String jsModulePath) {
|
||||||
|
return createBundleURL(
|
||||||
|
getDebugServerHost(),
|
||||||
|
jsModulePath,
|
||||||
|
getDevMode(),
|
||||||
|
getHMR(),
|
||||||
|
getJSMinifyMode());
|
||||||
|
}
|
||||||
|
|
||||||
public void downloadBundleFromURL(
|
public void downloadBundleFromURL(
|
||||||
final BundleDownloadCallback callback,
|
final BundleDownloadCallback callback,
|
||||||
final String jsModulePath,
|
final File outputFile,
|
||||||
final File outputFile) {
|
final String bundleURL) {
|
||||||
final String bundleURL = createBundleURL(
|
|
||||||
getDebugServerHost(),
|
|
||||||
jsModulePath,
|
|
||||||
getDevMode(),
|
|
||||||
getHMR(),
|
|
||||||
getJSMinifyMode());
|
|
||||||
final Request request = new Request.Builder()
|
final Request request = new Request.Builder()
|
||||||
.url(bundleURL)
|
.url(bundleURL)
|
||||||
.build();
|
.build();
|
||||||
|
@ -45,6 +45,7 @@ public interface DevSupportManager extends NativeModuleCallExceptionHandler {
|
|||||||
boolean hasUpToDateJSBundleInCache();
|
boolean hasUpToDateJSBundleInCache();
|
||||||
void reloadSettings();
|
void reloadSettings();
|
||||||
void handleReloadJS();
|
void handleReloadJS();
|
||||||
|
void reloadJSFromServer(final String bundleURL);
|
||||||
void isPackagerRunning(DevServerHelper.PackagerStatusCallback callback);
|
void isPackagerRunning(DevServerHelper.PackagerStatusCallback callback);
|
||||||
@Nullable File downloadBundleResourceFromUrlSync(
|
@Nullable File downloadBundleResourceFromUrlSync(
|
||||||
final String resourceURL,
|
final String resourceURL,
|
||||||
|
@ -635,18 +635,12 @@ public class DevSupportManagerImpl implements DevSupportManager, PackagerCommand
|
|||||||
mRedBoxDialog.dismiss();
|
mRedBoxDialog.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
AlertDialog dialog = new AlertDialog.Builder(mApplicationContext)
|
|
||||||
.setTitle(R.string.catalyst_jsload_title)
|
|
||||||
.setMessage(mApplicationContext.getString(
|
|
||||||
mDevSettings.isRemoteJSDebugEnabled() ? R.string.catalyst_remotedbg_message : R.string.catalyst_jsload_message))
|
|
||||||
.create();
|
|
||||||
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
|
|
||||||
dialog.show();
|
|
||||||
|
|
||||||
if (mDevSettings.isRemoteJSDebugEnabled()) {
|
if (mDevSettings.isRemoteJSDebugEnabled()) {
|
||||||
reloadJSInProxyMode(dialog);
|
reloadJSInProxyMode(showProgressDialog());
|
||||||
} else {
|
} else {
|
||||||
reloadJSFromServer(dialog);
|
String bundleURL =
|
||||||
|
mDevServerHelper.getDevServerBundleURL(Assertions.assertNotNull(mJSAppBundleName));
|
||||||
|
reloadJSFromServer(bundleURL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -741,7 +735,22 @@ public class DevSupportManagerImpl implements DevSupportManager, PackagerCommand
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reloadJSFromServer(final AlertDialog progressDialog) {
|
private AlertDialog showProgressDialog() {
|
||||||
|
AlertDialog dialog = new AlertDialog.Builder(mApplicationContext)
|
||||||
|
.setTitle(R.string.catalyst_jsload_title)
|
||||||
|
.setMessage(mApplicationContext.getString(
|
||||||
|
mDevSettings.isRemoteJSDebugEnabled() ?
|
||||||
|
R.string.catalyst_remotedbg_message :
|
||||||
|
R.string.catalyst_jsload_message))
|
||||||
|
.create();
|
||||||
|
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
|
||||||
|
dialog.show();
|
||||||
|
return dialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reloadJSFromServer(final String bundleURL) {
|
||||||
|
final AlertDialog progressDialog = showProgressDialog();
|
||||||
|
|
||||||
mDevServerHelper.downloadBundleFromURL(
|
mDevServerHelper.downloadBundleFromURL(
|
||||||
new DevServerHelper.BundleDownloadCallback() {
|
new DevServerHelper.BundleDownloadCallback() {
|
||||||
@Override
|
@Override
|
||||||
@ -776,8 +785,8 @@ public class DevSupportManagerImpl implements DevSupportManager, PackagerCommand
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Assertions.assertNotNull(mJSAppBundleName),
|
mJSBundleTempFile,
|
||||||
mJSBundleTempFile);
|
bundleURL);
|
||||||
progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCancel(DialogInterface dialog) {
|
public void onCancel(DialogInterface dialog) {
|
||||||
|
@ -126,6 +126,11 @@ public class DisabledDevSupportManager implements DevSupportManager {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reloadJSFromServer(String bundleURL) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void isPackagerRunning(DevServerHelper.PackagerStatusCallback callback) {
|
public void isPackagerRunning(DevServerHelper.PackagerStatusCallback callback) {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user