Skip to content

Commit 6922cb0

Browse files
committed
feedback
1 parent 1d0581b commit 6922cb0

File tree

2 files changed

+35
-23
lines changed

2 files changed

+35
-23
lines changed

CodePush.m

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
#import "CodePush.h"
88

9-
@implementation CodePush
9+
@implementation CodePush {
10+
BOOL hasRestartListener;
11+
}
1012

1113
RCT_EXPORT_MODULE()
1214

@@ -358,14 +360,17 @@ - (void)startRollbackTimer:(int)rollbackTimeout
358360
rollbackTimeout:rollbackTimeout];
359361

360362
if (installMode == CodePushInstallModeImmediate) {
361-
[self restartPendingUpdate];
363+
[self loadBundle];
362364
} else if (installMode == CodePushInstallModeOnNextResume) {
363-
// Register for app resume notifications so that we
364-
// can check for pending updates which support "restart on resume"
365-
[[NSNotificationCenter defaultCenter] addObserver:self
366-
selector:@selector(restartPendingUpdate)
367-
name:UIApplicationWillEnterForegroundNotification
368-
object:[UIApplication sharedApplication]];
365+
if (!hasRestartListener) {
366+
// Register for app resume notifications so that we
367+
// can check for pending updates which support "restart on resume"
368+
[[NSNotificationCenter defaultCenter] addObserver:self
369+
selector:@selector(loadBundle)
370+
name:UIApplicationWillEnterForegroundNotification
371+
object:[UIApplication sharedApplication]];
372+
hasRestartListener = true;
373+
}
369374
}
370375
// Signal to JS that the update has been applied.
371376
resolve(nil);

android/app/src/main/java/com/microsoft/codepush/react/CodePush.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.microsoft.codepush.react;
22

33
import com.facebook.react.ReactPackage;
4+
import com.facebook.react.bridge.ActivityEventListener;
45
import com.facebook.react.bridge.JavaScriptModule;
56
import com.facebook.react.bridge.LifecycleEventListener;
67
import com.facebook.react.bridge.NativeModule;
@@ -254,6 +255,8 @@ private void handleInitIfPendingUpdate() {
254255

255256
private class CodePushNativeModule extends ReactContextBaseJavaModule {
256257

258+
private LifecycleEventListener lifecycleEventListener = null;
259+
257260
private void loadBundle() {
258261
Intent intent = mainActivity.getIntent();
259262
mainActivity.finish();
@@ -273,22 +276,26 @@ public void installUpdate(ReadableMap updatePackage, int rollbackTimeout, int in
273276
}
274277

275278
if (installMode != CodePushInstallMode.IMMEDIATE.getValue()) {
276-
restartPendingUpdate();
279+
loadBundle();
277280
} else if (installMode == CodePushInstallMode.ON_NEXT_RESUME.getValue()) {
278-
getReactApplicationContext().addLifecycleEventListener(new LifecycleEventListener() {
279-
@Override
280-
public void onHostResume() {
281-
restartPendingUpdate();
282-
}
283-
284-
@Override
285-
public void onHostPause() {
286-
}
287-
288-
@Override
289-
public void onHostDestroy() {
290-
}
291-
});
281+
// Ensure we do not add the listener twice.
282+
if (lifecycleEventListener == null) {
283+
lifecycleEventListener = new LifecycleEventListener() {
284+
@Override
285+
public void onHostResume() {
286+
loadBundle();
287+
}
288+
289+
@Override
290+
public void onHostPause() {
291+
}
292+
293+
@Override
294+
public void onHostDestroy() {
295+
}
296+
};
297+
getReactApplicationContext().addLifecycleEventListener(lifecycleEventListener);
298+
}
292299
}
293300

294301
promise.resolve("");

0 commit comments

Comments
 (0)