From 464dae11ee6538e5114178cc59f5fba877ca74d3 Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Fri, 25 Dec 2015 21:36:02 -0800 Subject: [PATCH] Adding conditional check to restartApp --- CodePush.js | 6 +++++- CodePush.m | 14 +++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CodePush.js b/CodePush.js index 384cc59..107dc9f 100644 --- a/CodePush.js +++ b/CodePush.js @@ -109,6 +109,10 @@ function log(message) { console.log(`[CodePush] ${message}`) } +function restartApp(onlyIfUpdateIsPending = false) { + NativeCodePush.restartApp(onlyIfUpdateIsPending); +} + var testConfig; // This function is only used for tests. Replaces the default SDK, configuration and native bridge @@ -265,7 +269,7 @@ const CodePush = { getCurrentPackage, log, notifyApplicationReady: NativeCodePush.notifyApplicationReady, - restartApp: NativeCodePush.restartApp, + restartApp, setUpTestDependencies, sync, InstallMode: { diff --git a/CodePush.m b/CodePush.m index 84ed52e..4118b97 100644 --- a/CodePush.m +++ b/CodePush.m @@ -203,11 +203,11 @@ static NSString *const PackageIsPendingKey = @"isPending"; NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults]; NSDictionary *pendingUpdate = [preferences objectForKey:PendingUpdateKey]; - // If there is a pending update, whose hash is equal to the one - // specified, and its "state" isn't loading, then we consider it "pending". + // If there is a pending update whose "state" isn't loading, then we consider it "pending". + // Additionally, if a specific hash was provided, we ensure it matches that of the pending update. BOOL updateIsPending = pendingUpdate && [pendingUpdate[PendingUpdateIsLoadingKey] boolValue] == NO && - [pendingUpdate[PendingUpdateHashKey] isEqualToString:packageHash]; + (!packageHash || [pendingUpdate[PendingUpdateHashKey] isEqualToString:packageHash]); return updateIsPending; } @@ -467,9 +467,13 @@ RCT_EXPORT_METHOD(notifyApplicationReady:(RCTPromiseResolveBlock)resolve /* * This method is the native side of the CodePush.restartApp() method. */ -RCT_EXPORT_METHOD(restartApp) +RCT_EXPORT_METHOD(restartApp:(BOOL)onlyIfUpdateIsPending) { - [self loadBundle]; + // If this is an unconditional restart request, or there + // is current pending update, then reload the app. + if (!onlyIfUpdateIsPending || [self isPendingUpdate:nil]) { + [self loadBundle]; + } } /*