Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,35 @@ public void run() {
});
}

public static void restartApp(final ReactApplicationContext mContext, Promise promise) {
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
final Context application = mContext.getApplicationContext();
ReactInstanceManager instanceManager = ((ReactApplication) application).getReactNativeHost().getReactInstanceManager();

instanceManager.recreateReactContextInBackground();
promise.resolve(true);

} catch (Throwable err) {
promise.reject("restartApp failed: "+err.getMessage());
Log.e("pushy", "restartApp failed", err);

final Activity currentActivity = mContext.getCurrentActivity();
if (currentActivity == null) {
return;
}
currentActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
currentActivity.recreate();
}
});
}
}
});
}

public static void setNeedUpdate(UpdateContext updateContext, ReadableMap options, Promise promise) {
final String hash = options.getString("hash");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public void reloadUpdate(ReadableMap options,Promise promise) {
UpdateModuleImpl.reloadUpdate(updateContext, mContext, options,promise);
}

@Override
public void restartApp(Promise promise) {
UpdateModuleImpl.restartApp(updateContext, mContext, promise);
}

@Override
public void setNeedUpdate(ReadableMap options,Promise promise) {
UpdateModuleImpl.setNeedUpdate(updateContext, options,promise);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,29 @@ public void run() {
});
}

@ReactMethod
public void restartApp(final Promise promise) {

UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
final Context application = getReactApplicationContext().getApplicationContext();
ReactInstanceManager instanceManager = updateContext.getCustomReactInstanceManager();
if (instanceManager == null) {
instanceManager = ((ReactApplication) application).getReactNativeHost().getReactInstanceManager();
}
instanceManager.recreateReactContextInBackground();
promise.resolve(true);

} catch (Throwable err) {
promise.reject(err);
Log.e("pushy", "restartApp failed ", err);
}
}
});
}

@ReactMethod
public void setNeedUpdate(ReadableMap options) {
final String hash = options.getString("hash");
Expand Down
20 changes: 20 additions & 0 deletions ios/RCTPushy/RCTPushy.mm
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,26 @@ - (instancetype)init
}
}

RCT_EXPORT_METHOD(restartApp:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
@try {
dispatch_async(dispatch_get_main_queue(), ^{
[self.bridge reload];
});
#if __has_include("RCTReloadCommand.h")
// reload 0.62+
RCTReloadCommandSetBundleURL([[self class] bundleURL]);
RCTTriggerReloadCommandListeners(@"pushy restartApp");
#endif

resolve(@true);
}
@catch (NSException *exception) {
reject(@"执行报错", exception.reason, nil);
}
}

RCT_EXPORT_METHOD(markSuccess:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
Expand Down
1 change: 1 addition & 0 deletions src/NativePushy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface Spec extends TurboModule {
getLocalHashInfo(hash: string): Promise<string>;
setUuid(uuid: string): Promise<void>;
reloadUpdate(options: { hash: string }): Promise<void>;
restartApp(): Promise<void>;
setNeedUpdate(options: { hash: string }): Promise<void>;
markSuccess(): Promise<void>;
downloadPatchFromPpk(options: {
Expand Down
3 changes: 3 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,9 @@ export class Pushy {
delete Pushy.progressHandlers[progressKey];
}
};
restartApp = async () => {
return PushyModule.restartApp();
};
}

// for international users
Expand Down
2 changes: 2 additions & 0 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const defaultContext = {
dismissError: noop,
downloadUpdate: asyncNoop,
downloadAndInstallApk: asyncNoop,
restartApp: asyncNoop,
getCurrentVersionInfo: () => Promise.resolve({}),
parseTestQrCode: () => false,
currentHash: '',
Expand All @@ -33,6 +34,7 @@ export const UpdateContext = createContext<{
metaInfo?: string;
}>;
parseTestQrCode: (code: string) => boolean;
restartApp: () => Promise<void>;
currentHash: string;
packageVersion: string;
client?: Pushy | Cresc;
Expand Down
8 changes: 8 additions & 0 deletions src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@ export const UpdateProvider = ({
[parseTestPayload],
);

const restartApp = useCallback(
async () => {
return client.restartApp();
},
[client],
);

useEffect(() => {
const parseLinking = (url: string | null) => {
if (!url) {
Expand Down Expand Up @@ -361,6 +368,7 @@ export const UpdateProvider = ({
downloadAndInstallApk,
getCurrentVersionInfo,
parseTestQrCode,
restartApp,
}}>
{children}
</UpdateContext.Provider>
Expand Down