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

Commit 9fdaf51

Browse files
committed
change UPDATE_INSTALLED behaviour
1 parent d4153d2 commit 9fdaf51

File tree

6 files changed

+35
-17
lines changed

6 files changed

+35
-17
lines changed

CodePush.ios.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,10 @@ function sync(options = {}, syncStatusChangeCallback, downloadProgressCallback)
196196
remotePackage.download(downloadProgressCallback)
197197
.then((localPackage) => {
198198
syncStatusChangeCallback(CodePush.SyncStatus.INSTALLING_UPDATE);
199-
return localPackage.install(syncOptions.rollbackTimeout, syncOptions.installMode)
200-
})
201-
.then(() => {
202-
syncStatusChangeCallback(CodePush.SyncStatus.UPDATE_INSTALLED);
203-
resolve(CodePush.SyncStatus.UPDATE_INSTALLED)
199+
return localPackage.install(syncOptions.rollbackTimeout, syncOptions.installMode, () => {
200+
syncStatusChangeCallback(CodePush.SyncStatus.UPDATE_INSTALLED);
201+
resolve(CodePush.SyncStatus.UPDATE_INSTALLED);
202+
});
204203
})
205204
.catch(reject)
206205
.done();

CodePush.m

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,19 +239,22 @@ - (void)startRollbackTimer:(int)rollbackTimeout
239239
if (error) {
240240
reject(error);
241241
} else {
242-
if (installMode == CodePushInstallModeImmediate) {
243-
[self initializeUpdateWithRollbackTimeout:rollbackTimeout needsRestart:YES];
244-
} else {
242+
if (installMode != CodePushInstallModeImmediate) {
245243
_resumablePendingUpdateAvailable = (installMode == CodePushInstallModeOnNextResume);
246244
[self savePendingUpdate:updatePackage[@"packageHash"]
247245
rollbackTimeout:rollbackTimeout];
248-
// Signal to JS that the update has been applied.
249-
resolve(nil);
250246
}
247+
// Signal to JS that the update has been applied.
248+
resolve(nil);
251249
}
252250
});
253251
}
254252

253+
// Only to be used in the case of installing updates with InstallMode.IMMEDIATE
254+
RCT_EXPORT_METHOD(restartApp:(int)rollbackTimeout){
255+
[self initializeUpdateWithRollbackTimeout:rollbackTimeout needsRestart:YES];
256+
}
257+
255258
RCT_EXPORT_METHOD(downloadUpdate:(NSDictionary*)updatePackage
256259
resolver:(RCTPromiseResolveBlock)resolve
257260
rejecter:(RCTPromiseRejectBlock)reject)

Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ @implementation InstallUpdateTests
2727

2828
- (void)setUp
2929
{
30-
app = @"CodePushDemoAppTests/InstallUpdateTests/InstallUpdateTestApp.ios";
30+
app = @"CodePushDemoAppTests/InstallUpdateTests/DownloadAndInstallUpdateTest";
3131
#if __LP64__
3232
RCTAssert(false, @"Tests should be run on 32-bit device simulators (e.g. iPhone 5)");
3333
#endif
@@ -68,9 +68,12 @@ - (void)testDownloadAndInstallUpdate
6868
moduleProvider:nil
6969
launchOptions:nil];
7070
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
71-
moduleName:@"DownloadAndInstallUpdateTest"
71+
moduleName:@"CodePushDemoApp"
7272
initialProperties:nil];
73-
73+
74+
UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
75+
rootViewController.view = rootView;
76+
7477
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
7578
BOOL foundElement = NO;
7679

@@ -98,8 +101,9 @@ - (void)testDownloadAndInstallUpdate
98101
}];
99102
}
100103

101-
XCTAssertNil(redboxError, @"RedBox error: %@", redboxError);
104+
NSLog(foundElement ? @"Yes" : @"No");
102105
XCTAssertTrue(foundElement, @"Cound't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS);
106+
XCTAssertNil(redboxError, @"RedBox error: %@", redboxError);
103107

104108
}
105109

Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/CodePushDemoApp.ios.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,5 @@ var styles = StyleSheet.create({
6262
}
6363
});
6464

65+
CodePushDemoApp.displayName = 'CodePushDemoApp';
6566
AppRegistry.registerComponent('CodePushDemoApp', () => CodePushDemoApp);

Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/DownloadAndInstallUpdateTest.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var CodePushSdk = require('react-native-code-push');
55
var NativeBridge = require('react-native').NativeModules.CodePush;
66

77
var {
8+
AppRegistry,
89
Text,
910
View,
1011
} = React;
@@ -39,7 +40,10 @@ var DownloadAndInstallUpdateTest = React.createClass({
3940
runTest() {
4041
var update = require("./TestPackage");
4142
NativeBridge.downloadUpdate(update).done((downloadedPackage) => {
42-
NativeBridge.installUpdate(downloadedPackage, /*rollbackTimeout*/ 1000, CodePushSdk.InstallMode.IMMEDIATE);
43+
NativeBridge.installUpdate(downloadedPackage, /*rollbackTimeout*/ 1000, CodePushSdk.InstallMode.IMMEDIATE)
44+
.then(() => {
45+
NativeBridge.restartApp(/*rollbackTimeout*/ 1000);
46+
});
4347
});
4448
},
4549

@@ -56,5 +60,6 @@ var DownloadAndInstallUpdateTest = React.createClass({
5660
});
5761

5862
DownloadAndInstallUpdateTest.displayName = 'DownloadAndInstallUpdateTest';
63+
AppRegistry.registerComponent('CodePushDemoApp', () => DownloadAndInstallUpdateTest);
5964

6065
module.exports = DownloadAndInstallUpdateTest;

package-mixins.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,14 @@ module.exports = (NativeCodePush) => {
3636
};
3737

3838
var local = {
39-
install: function install(rollbackTimeout = 0, installMode = NativeCodePush.codePushInstallModeOnNextRestart) {
40-
return NativeCodePush.installUpdate(this, rollbackTimeout, installMode);
39+
install: function install(rollbackTimeout = 0, installMode = NativeCodePush.codePushInstallModeOnNextRestart, updateInstalledCallback) {
40+
return NativeCodePush.installUpdate(this, rollbackTimeout, installMode)
41+
.then(function() {
42+
updateInstalledCallback && updateInstalledCallback();
43+
if (installMode == NativeCodePush.codePushInstallModeImmediate) {
44+
NativeCodePush.restartApp(rollbackTimeout);
45+
}
46+
});
4147
}
4248
};
4349

0 commit comments

Comments
 (0)