Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 464dae1

Browse files
committed
Adding conditional check to restartApp
1 parent 526aeff commit 464dae1

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

CodePush.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ function log(message) {
109109
console.log(`[CodePush] ${message}`)
110110
}
111111

112+
function restartApp(onlyIfUpdateIsPending = false) {
113+
NativeCodePush.restartApp(onlyIfUpdateIsPending);
114+
}
115+
112116
var testConfig;
113117

114118
// This function is only used for tests. Replaces the default SDK, configuration and native bridge
@@ -265,7 +269,7 @@ const CodePush = {
265269
getCurrentPackage,
266270
log,
267271
notifyApplicationReady: NativeCodePush.notifyApplicationReady,
268-
restartApp: NativeCodePush.restartApp,
272+
restartApp,
269273
setUpTestDependencies,
270274
sync,
271275
InstallMode: {

CodePush.m

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,11 @@ - (BOOL)isPendingUpdate:(NSString*)packageHash
203203
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
204204
NSDictionary *pendingUpdate = [preferences objectForKey:PendingUpdateKey];
205205

206-
// If there is a pending update, whose hash is equal to the one
207-
// specified, and its "state" isn't loading, then we consider it "pending".
206+
// If there is a pending update whose "state" isn't loading, then we consider it "pending".
207+
// Additionally, if a specific hash was provided, we ensure it matches that of the pending update.
208208
BOOL updateIsPending = pendingUpdate &&
209209
[pendingUpdate[PendingUpdateIsLoadingKey] boolValue] == NO &&
210-
[pendingUpdate[PendingUpdateHashKey] isEqualToString:packageHash];
210+
(!packageHash || [pendingUpdate[PendingUpdateHashKey] isEqualToString:packageHash]);
211211

212212
return updateIsPending;
213213
}
@@ -467,9 +467,13 @@ - (void)savePendingUpdate:(NSString *)packageHash
467467
/*
468468
* This method is the native side of the CodePush.restartApp() method.
469469
*/
470-
RCT_EXPORT_METHOD(restartApp)
470+
RCT_EXPORT_METHOD(restartApp:(BOOL)onlyIfUpdateIsPending)
471471
{
472-
[self loadBundle];
472+
// If this is an unconditional restart request, or there
473+
// is current pending update, then reload the app.
474+
if (!onlyIfUpdateIsPending || [self isPendingUpdate:nil]) {
475+
[self loadBundle];
476+
}
473477
}
474478

475479
/*

0 commit comments

Comments
 (0)