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

Commit 3e4ac61

Browse files
committed
fix rollback bug
1 parent 17005b4 commit 3e4ac61

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

CodePush.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ function getPromisifiedSdk(requestFetchAdapter, config) {
115115
});
116116
};
117117

118-
sdk.reportStatusDownload = (downloadedPackage, status) => {
118+
sdk.reportStatusDownload = (downloadedPackage) => {
119119
return new Promise((resolve, reject) => {
120120
module.exports.AcquisitionSdk.prototype.reportStatusDownload.call(sdk, downloadedPackage, (err) => {
121121
if (err) {

CodePush.m

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

1414
RCT_EXPORT_MODULE()
1515

16-
static BOOL didRollback = NO;
16+
static BOOL needToReportRollback = NO;
1717
static BOOL isRunningBinaryVersion = NO;
1818
static BOOL testConfigurationFlag = NO;
1919

@@ -195,15 +195,14 @@ - (void)initializeUpdateAfterRestart
195195
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
196196
NSDictionary *pendingUpdate = [preferences objectForKey:PendingUpdateKey];
197197
if (pendingUpdate) {
198-
didRollback = NO;
199198
_isFirstRunAfterUpdate = YES;
200199
BOOL updateIsLoading = [pendingUpdate[PendingUpdateIsLoadingKey] boolValue];
201200
if (updateIsLoading) {
202201
// Pending update was initialized, but notifyApplicationReady was not called.
203202
// Therefore, deduce that it is a broken update and rollback.
204203
NSLog(@"Update did not finish loading the last time, rolling back to a previous version.");
204+
needToReportRollback = YES;
205205
[self rollbackPackage];
206-
didRollback = YES;
207206
} else {
208207
// Mark that we tried to initialize the new update, so that if it crashes,
209208
// we will know that we need to rollback when the app next starts.
@@ -293,7 +292,7 @@ - (void)loadBundle
293292
- (void)recordDeploymentStatusReported:(NSString *)appVersionOrPackageIdentifier
294293
{
295294
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
296-
[preferences setValue:LastDeploymentReportKey forKey:appVersionOrPackageIdentifier];
295+
[preferences setValue:appVersionOrPackageIdentifier forKey:LastDeploymentReportKey];
297296
[preferences synchronize];
298297
}
299298

@@ -534,8 +533,9 @@ - (void)savePendingUpdate:(NSString *)packageHash
534533
RCT_EXPORT_METHOD(getNewStatusReport:(RCTPromiseResolveBlock)resolve
535534
rejecter:(RCTPromiseRejectBlock)reject)
536535
{
537-
if (didRollback) {
536+
if (needToReportRollback) {
538537
// Check if there was a rollback that was not yet reported
538+
needToReportRollback = NO;
539539
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
540540
NSMutableArray *failedUpdates = [preferences objectForKey:FailedUpdatesKey];
541541
if (failedUpdates) {

Examples/CodePushDemoApp/crossplatformdemo.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ let CodePushDemoApp = React.createClass({
8181
}
8282
},
8383

84+
componentDidMount() {
85+
CodePush.notifyApplicationReady();
86+
},
87+
8488
getInitialState() {
8589
return { };
8690
},

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
public class CodePush {
4242

43-
private static boolean didRollback = false;
43+
private static boolean needToReportRollback = false;
4444
private static boolean isRunningBinaryVersion = false;
4545
private static boolean testConfigurationFlag = false;
4646

@@ -237,15 +237,14 @@ private void initializeUpdateAfterRestart() {
237237
JSONObject pendingUpdate = getPendingUpdate();
238238
if (pendingUpdate != null) {
239239
didUpdate = true;
240-
didRollback = false;
241240
try {
242241
boolean updateIsLoading = pendingUpdate.getBoolean(PENDING_UPDATE_IS_LOADING_KEY);
243242
if (updateIsLoading) {
244243
// Pending update was initialized, but notifyApplicationReady was not called.
245244
// Therefore, deduce that it is a broken update and rollback.
246245
CodePushUtils.log("Update did not finish loading the last time, rolling back to a previous version.");
246+
needToReportRollback = true;
247247
rollbackPackage();
248-
didRollback = true;
249248
} else {
250249
// Clear the React dev bundle cache so that new updates can be loaded.
251250
if (this.isDebugMode) {
@@ -457,8 +456,9 @@ protected Void doInBackground(Object... params) {
457456

458457
@ReactMethod
459458
public void getNewStatusReport(Promise promise) {
460-
if (didRollback) {
459+
if (needToReportRollback) {
461460
// Check if there was a rollback that was not yet reported
461+
needToReportRollback = false;
462462
JSONArray failedUpdates = getFailedUpdates();
463463
if (failedUpdates != null && failedUpdates.length() > 0) {
464464
try {

0 commit comments

Comments
 (0)