Skip to content

Commit

Permalink
Make package location customizable in dev mode
Browse files Browse the repository at this point in the history
Summary:
@public
With this, you can determine the packager location at run time before we even try to load the bundle.

Changelog: [Android] [Added] - Packager location can be determined at run time

Reviewed By: makovkastar

Differential Revision: D18940087

fbshipit-source-id: fac99f28e119a4e7a2961b5504cfe7d2d409e8f7
  • Loading branch information
Mehdi Mulani authored and facebook-github-bot committed Dec 18, 2019
1 parent fa78a96 commit 3714f36
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ private enum ErrorType {
private @Nullable ErrorType mLastErrorType;
private @Nullable DevBundleDownloadListener mBundleDownloadListener;
private @Nullable List<ErrorCustomizer> mErrorCustomizers;
private @Nullable PackagerLocationCustomizer mPackagerLocationCustomizer;

private InspectorPackagerConnection.BundleStatus mBundleStatus;

Expand Down Expand Up @@ -877,8 +878,19 @@ public void handleReloadJS() {
}

@Override
public void isPackagerRunning(PackagerStatusCallback callback) {
mDevServerHelper.isPackagerRunning(callback);
public void isPackagerRunning(final PackagerStatusCallback callback) {
Runnable checkPackagerRunning =
new Runnable() {
@Override
public void run() {
mDevServerHelper.isPackagerRunning(callback);
}
};
if (mPackagerLocationCustomizer != null) {
mPackagerLocationCustomizer.run(checkPackagerRunning);
} else {
checkPackagerRunning.run();
}
}

@Override
Expand Down Expand Up @@ -1240,4 +1252,9 @@ private void reload() {
private static String getReloadAppAction(Context context) {
return context.getPackageName() + RELOAD_APP_ACTION_SUFFIX;
}

@Override
public void setPackagerLocationCustomizer(PackagerLocationCustomizer packagerLocationCustomizer) {
mPackagerLocationCustomizer = packagerLocationCustomizer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void handleReloadJS() {}
public void reloadJSFromServer(String bundleURL) {}

@Override
public void isPackagerRunning(PackagerStatusCallback callback) {}
public void isPackagerRunning(final PackagerStatusCallback callback) {}

@Override
public @Nullable File downloadBundleResourceFromUrlSync(
Expand All @@ -151,6 +151,10 @@ public void isPackagerRunning(PackagerStatusCallback callback) {}
@Override
public void registerErrorCustomizer(ErrorCustomizer errorCustomizer) {}

@Override
public void setPackagerLocationCustomizer(
PackagerLocationCustomizer packagerLocationCustomizer) {}

@Override
public void handleException(Exception e) {
mDefaultNativeModuleCallExceptionHandler.handleException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,15 @@ public interface DevSupportManager extends NativeModuleCallExceptionHandler {
StackFrame[] getLastErrorStack();

void registerErrorCustomizer(ErrorCustomizer errorCustomizer);

/**
* The PackagerLocationCustomizer allows you to have a dynamic packager location that is
* determined right before loading the packager. Your customizer must call |callback|, as loading
* will be blocked waiting for it to resolve.
*/
public interface PackagerLocationCustomizer {
void run(Runnable callback);
}

void setPackagerLocationCustomizer(PackagerLocationCustomizer packagerLocationCustomizer);
}

0 comments on commit 3714f36

Please sign in to comment.