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

Commit a44c792

Browse files
committed
feedback
1 parent a3e3936 commit a44c792

File tree

19 files changed

+161
-129
lines changed

19 files changed

+161
-129
lines changed

CodePush.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async function checkForUpdate(deploymentKey = null) {
6060
if (!update || update.updateAppVersion || (update.packageHash === localPackage.packageHash)) {
6161
return null;
6262
} else {
63-
const remotePackage = { ...update, ...PackageMixins.remote };
63+
const remotePackage = { ...update, ...PackageMixins.remote(sdk.reportStatusDownload) };
6464
remotePackage.failedInstall = await NativeCodePush.isFailedUpdate(remotePackage.packageHash);
6565
remotePackage.deploymentKey = deploymentKey || nativeConfig.deploymentKey;
6666
return remotePackage;
@@ -102,8 +102,8 @@ function getPromisifiedSdk(requestFetchAdapter, config) {
102102
});
103103
});
104104
};
105-
106-
sdk.reportStatus = (package, status) => {
105+
106+
sdk.reportStatusDeploy = (package, status) => {
107107
return new Promise((resolve, reject) => {
108108
module.exports.AcquisitionSdk.prototype.reportStatusDeploy.call(sdk, package, status, (err) => {
109109
if (err) {
@@ -114,7 +114,19 @@ function getPromisifiedSdk(requestFetchAdapter, config) {
114114
});
115115
});
116116
};
117-
117+
118+
sdk.reportStatusDownload = (package, status) => {
119+
return new Promise((resolve, reject) => {
120+
module.exports.AcquisitionSdk.prototype.reportStatusDownload.call(sdk, package, (err) => {
121+
if (err) {
122+
reject(err);
123+
} else {
124+
resolve();
125+
}
126+
});
127+
});
128+
};
129+
118130
return sdk;
119131
}
120132

@@ -129,13 +141,12 @@ async function notifyApplicationReady() {
129141
if (statusReport) {
130142
const config = await getConfiguration();
131143
if (statusReport.appVersion) {
132-
config.appVersion = statusReport.appVersion;
133144
const sdk = getPromisifiedSdk(requestFetchAdapter, config);
134-
sdk.reportStatus();
145+
sdk.reportStatusDeploy();
135146
} else {
136147
config.deploymentKey = statusReport.package.deploymentKey;
137148
const sdk = getPromisifiedSdk(requestFetchAdapter, config);
138-
sdk.reportStatus(statusReport.package, statusReport.status);
149+
sdk.reportStatusDeploy(statusReport.package, statusReport.status);
139150
}
140151
}
141152
}

CodePush.m

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ @implementation CodePush {
1313

1414
RCT_EXPORT_MODULE()
1515

16+
static BOOL didRollback = NO;
1617
static BOOL testConfigurationFlag = NO;
1718

1819
// These constants represent valid deployment statuses
@@ -189,13 +190,15 @@ - (void)initializeUpdateAfterRestart
189190
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
190191
NSDictionary *pendingUpdate = [preferences objectForKey:PendingUpdateKey];
191192
if (pendingUpdate) {
193+
didRollback = NO;
192194
_isFirstRunAfterUpdate = YES;
193195
BOOL updateIsLoading = [pendingUpdate[PendingUpdateIsLoadingKey] boolValue];
194196
if (updateIsLoading) {
195197
// Pending update was initialized, but notifyApplicationReady was not called.
196198
// Therefore, deduce that it is a broken update and rollback.
197199
NSLog(@"Update did not finish loading the last time, rolling back to a previous version.");
198200
[self rollbackPackage];
201+
didRollback = YES;
199202
} else {
200203
// Mark that we tried to initialize the new update, so that if it crashes,
201204
// we will know that we need to rollback when the app next starts.
@@ -220,7 +223,7 @@ - (BOOL)isFailedHash:(NSString*)packageHash
220223
{
221224
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
222225
NSMutableArray *failedUpdates = [preferences objectForKey:FailedUpdatesKey];
223-
if (failedUpdates == nil) {
226+
if (failedUpdates == nil || packageHash == nil) {
224227
return NO;
225228
} else {
226229
for (NSDictionary *failedPackage in failedUpdates)
@@ -535,42 +538,46 @@ - (void)savePendingUpdate:(NSString *)packageHash
535538
RCT_EXPORT_METHOD(getNewStatusReport:(RCTPromiseResolveBlock)resolve
536539
rejecter:(RCTPromiseRejectBlock)reject)
537540
{
538-
// Check if the current appVersion has been reported.
539-
NSString *appVersion = [[CodePushConfig current] appVersion];
540-
if ([self isDeploymentStatusNotYetReported:appVersion]) {
541-
[self recordDeploymentStatusReported:appVersion
542-
status:DeploymentSucceeded];
543-
resolve(@{ @"appVersion": appVersion });
544-
return;
541+
if (didRollback) {
542+
// Check if there was a rollback that was not yet reported
543+
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
544+
NSMutableArray *failedUpdates = [preferences objectForKey:FailedUpdatesKey];
545+
if (failedUpdates) {
546+
NSDictionary* lastFailedPackage = [failedUpdates lastObject];
547+
if (lastFailedPackage) {
548+
NSString* lastFailedPackageIdentifier = [self getPackageStatusReportIdentifier:lastFailedPackage];
549+
if (lastFailedPackageIdentifier && [self isDeploymentStatusNotYetReported:lastFailedPackageIdentifier]) {
550+
[self recordDeploymentStatusReported:lastFailedPackageIdentifier
551+
status:DeploymentFailed];
552+
resolve(@{ @"package": lastFailedPackage, @"status": DeploymentFailed });
553+
return;
554+
}
555+
}
556+
}
545557
}
546558

547-
// Check if there was a rollback that was not yet reported
548-
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
549-
NSMutableArray *failedUpdates = [preferences objectForKey:FailedUpdatesKey];
550-
if (failedUpdates) {
551-
NSDictionary* lastFailedPackage = [failedUpdates lastObject];
552-
if (lastFailedPackage) {
553-
NSString* lastFailedPackageIdentifier = [self getPackageStatusReportIdentifier:lastFailedPackage];
554-
if (lastFailedPackageIdentifier && [self isDeploymentStatusNotYetReported:lastFailedPackageIdentifier]) {
555-
[self recordDeploymentStatusReported:lastFailedPackageIdentifier
556-
status:DeploymentFailed];
557-
resolve(@{ @"package": lastFailedPackage, @"status": DeploymentFailed });
559+
if (_isFirstRunAfterUpdate) {
560+
// Check if the current CodePush package has been reported
561+
NSError *error;
562+
NSDictionary* currentPackage = [CodePushPackage getCurrentPackage:&error];
563+
if (currentPackage) {
564+
NSString* currentPackageIdentifier = [self getPackageStatusReportIdentifier:currentPackage];
565+
if (currentPackageIdentifier && [self isDeploymentStatusNotYetReported:currentPackageIdentifier]) {
566+
[self recordDeploymentStatusReported:currentPackageIdentifier
567+
status:DeploymentSucceeded];
568+
resolve(@{ @"package": currentPackage, @"status": DeploymentSucceeded });
558569
return;
559570
}
560571
}
561572
}
562573

563-
// Check if the current CodePush package has been reported
564-
NSError *error;
565-
NSDictionary* currentPackage = [CodePushPackage getCurrentPackage:&error];
566-
if (currentPackage) {
567-
NSString* currentPackageIdentifier = [self getPackageStatusReportIdentifier:currentPackage];
568-
if (currentPackageIdentifier && [self isDeploymentStatusNotYetReported:currentPackageIdentifier]) {
569-
[self recordDeploymentStatusReported:currentPackageIdentifier
570-
status:DeploymentSucceeded];
571-
resolve(@{ @"package": currentPackage, @"status": DeploymentSucceeded });
572-
return;
573-
}
574+
// Check if the current appVersion has been reported.
575+
NSString *appVersion = [[CodePushConfig current] appVersion];
576+
if ([self isDeploymentStatusNotYetReported:appVersion]) {
577+
[self recordDeploymentStatusReported:appVersion
578+
status:DeploymentSucceeded];
579+
resolve(@{ @"appVersion": appVersion });
580+
return;
574581
}
575582

576583
resolve([NSNull null]);

CodePushConfig.m

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ @implementation CodePushConfig {
99

1010
static NSString * const AppVersionConfigKey = @"appVersion";
1111
static NSString * const BuildVdersionConfigKey = @"buildVersion";
12+
static NSString * const ClientUniqueIDConfigKey = @"clientUniqueId";
1213
static NSString * const DeploymentKeyConfigKey = @"deploymentKey";
1314
static NSString * const ServerURLConfigKey = @"serverUrl";
14-
static NSString * const ClientUniqueIDConfigKey = @"clientUniqueId";
1515

1616
+ (instancetype)current
1717
{
@@ -34,12 +34,7 @@ - (instancetype)init
3434
NSString *serverURL = [infoDictionary objectForKey:@"CodePushServerURL"];
3535

3636
NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
37-
NSString* clientUniqueId = [userDefaults stringForKey:ClientUniqueIDConfigKey];
38-
if (clientUniqueId == nil) {
39-
clientUniqueId = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
40-
[userDefaults setObject:clientUniqueId forKey:ClientUniqueIDConfigKey];
41-
[userDefaults synchronize];
42-
}
37+
NSString* clientUniqueId = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
4338

4439
if (!serverURL) {
4540
serverURL = @"https://codepush.azurewebsites.net/";
@@ -49,8 +44,8 @@ - (instancetype)init
4944
appVersion,AppVersionConfigKey,
5045
buildVersion,BuildVdersionConfigKey,
5146
serverURL,ServerURLConfigKey,
52-
deploymentKey,DeploymentKeyConfigKey,
5347
clientUniqueId,ClientUniqueIDConfigKey,
48+
deploymentKey,DeploymentKeyConfigKey,
5449
nil];
5550

5651
return self;

Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/FirstUpdateTest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ let FirstUpdateTest = createTestCaseComponent(
2424
},
2525
async () => {
2626
let update = await CodePush.checkForUpdate();
27-
assert.equal(JSON.stringify(update), JSON.stringify({ ...serverPackage, ...PackageMixins.remote, failedInstall: false }), "checkForUpdate did not return the update from the server");
27+
assert.equal(JSON.stringify(update), JSON.stringify({ ...serverPackage, ...PackageMixins.remote(), failedInstall: false }), "checkForUpdate did not return the update from the server");
2828
}
2929
);
3030

Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NewUpdateTest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let NewUpdateTest = createTestCaseComponent(
2323
},
2424
async () => {
2525
let update = await CodePush.checkForUpdate();
26-
assert.equal(JSON.stringify(update), JSON.stringify({ ...serverPackage, ...PackageMixins.remote, failedInstall: false }), "checkForUpdate did not return the update from the server");
26+
assert.equal(JSON.stringify(update), JSON.stringify({ ...serverPackage, ...PackageMixins.remote(), failedInstall: false }), "checkForUpdate did not return the update from the server");
2727
}
2828
);
2929

Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SwitchDeploymentKeyTest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ let SwitchDeploymentKeyTest = createTestCaseComponent(
2525
},
2626
async () => {
2727
let update = await CodePush.checkForUpdate(deploymentKey);
28-
assert.equal(JSON.stringify(update), JSON.stringify({ ...serverPackage, ...PackageMixins.remote, failedInstall: false, deploymentKey }), "checkForUpdate did not return the update from the server");
28+
assert.equal(JSON.stringify(update), JSON.stringify({ ...serverPackage, ...PackageMixins.remote(), failedInstall: false, deploymentKey }), "checkForUpdate did not return the update from the server");
2929
}
3030
);
3131

Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests/testcases/DownloadProgressTest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ let DownloadProgressTest = createTestCaseComponent(
2828
"should successfully download all the bytes contained in the test packages",
2929
() => {
3030
testPackages.forEach((aPackage, index) => {
31-
testPackages[index] = Object.assign(aPackage, PackageMixins.remote);
31+
testPackages[index] = Object.assign(aPackage, PackageMixins.remote());
3232
});
3333
return Promise.resolve();
3434
},

Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ let RollbackTest = React.createClass({
2727
await NativeCodePush.downloadAndReplaceCurrentBundle("http://localhost:8081/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV1Pass.includeRequire.runModule.bundle?platform=ios&dev=true");
2828
}
2929

30-
remotePackage = Object.assign(remotePackage, PackageMixins.remote);
30+
remotePackage = Object.assign(remotePackage, PackageMixins.remote());
3131

3232
let localPackage = await remotePackage.download();
3333
return await localPackage.install(NativeCodePush.codePushInstallModeImmediate);

Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeImmediateTest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let InstallModeImmediateTest = createTestCaseComponent(
2121
remotePackage.downloadUrl = "http://localhost:8081/CodePushDemoAppTests/InstallUpdateTests/resources/PassInstallModeImmediateTest.includeRequire.runModule.bundle?platform=ios&dev=true"
2222
}
2323

24-
remotePackage = Object.assign(remotePackage, PackageMixins.remote);
24+
remotePackage = Object.assign(remotePackage, PackageMixins.remote());
2525
},
2626
async () => {
2727
let localPackage = await remotePackage.download();

Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeOnNextRestartTest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ let InstallModeOnNextRestartTest = createTestCaseComponent(
2222
remotePackage.downloadUrl = "http://localhost:8081/CodePushDemoAppTests/InstallUpdateTests/resources/PassInstallModeOnNextRestartTest.includeRequire.runModule.bundle?platform=ios&dev=true"
2323
}
2424

25-
remotePackage = Object.assign(remotePackage, PackageMixins.remote);
25+
remotePackage = Object.assign(remotePackage, PackageMixins.remote());
2626
},
2727
async () => {
2828
let localPackage = await remotePackage.download();

0 commit comments

Comments
 (0)