change UPDATE_INSTALLED behaviour

This commit is contained in:
Geoffrey Goh
2015-11-18 15:27:05 -08:00
parent d4153d294c
commit 9fdaf510fb
6 changed files with 35 additions and 17 deletions

View File

@@ -196,11 +196,10 @@ function sync(options = {}, syncStatusChangeCallback, downloadProgressCallback)
remotePackage.download(downloadProgressCallback)
.then((localPackage) => {
syncStatusChangeCallback(CodePush.SyncStatus.INSTALLING_UPDATE);
return localPackage.install(syncOptions.rollbackTimeout, syncOptions.installMode)
})
.then(() => {
syncStatusChangeCallback(CodePush.SyncStatus.UPDATE_INSTALLED);
resolve(CodePush.SyncStatus.UPDATE_INSTALLED)
return localPackage.install(syncOptions.rollbackTimeout, syncOptions.installMode, () => {
syncStatusChangeCallback(CodePush.SyncStatus.UPDATE_INSTALLED);
resolve(CodePush.SyncStatus.UPDATE_INSTALLED);
});
})
.catch(reject)
.done();

View File

@@ -239,19 +239,22 @@ RCT_EXPORT_METHOD(installUpdate:(NSDictionary*)updatePackage
if (error) {
reject(error);
} else {
if (installMode == CodePushInstallModeImmediate) {
[self initializeUpdateWithRollbackTimeout:rollbackTimeout needsRestart:YES];
} else {
if (installMode != CodePushInstallModeImmediate) {
_resumablePendingUpdateAvailable = (installMode == CodePushInstallModeOnNextResume);
[self savePendingUpdate:updatePackage[@"packageHash"]
rollbackTimeout:rollbackTimeout];
// Signal to JS that the update has been applied.
resolve(nil);
}
// Signal to JS that the update has been applied.
resolve(nil);
}
});
}
// Only to be used in the case of installing updates with InstallMode.IMMEDIATE
RCT_EXPORT_METHOD(restartApp:(int)rollbackTimeout){
[self initializeUpdateWithRollbackTimeout:rollbackTimeout needsRestart:YES];
}
RCT_EXPORT_METHOD(downloadUpdate:(NSDictionary*)updatePackage
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)

View File

@@ -27,7 +27,7 @@
- (void)setUp
{
app = @"CodePushDemoAppTests/InstallUpdateTests/InstallUpdateTestApp.ios";
app = @"CodePushDemoAppTests/InstallUpdateTests/DownloadAndInstallUpdateTest";
#if __LP64__
RCTAssert(false, @"Tests should be run on 32-bit device simulators (e.g. iPhone 5)");
#endif
@@ -68,9 +68,12 @@
moduleProvider:nil
launchOptions:nil];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"DownloadAndInstallUpdateTest"
moduleName:@"CodePushDemoApp"
initialProperties:nil];
UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
rootViewController.view = rootView;
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
BOOL foundElement = NO;
@@ -98,8 +101,9 @@
}];
}
XCTAssertNil(redboxError, @"RedBox error: %@", redboxError);
NSLog(foundElement ? @"Yes" : @"No");
XCTAssertTrue(foundElement, @"Cound't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS);
XCTAssertNil(redboxError, @"RedBox error: %@", redboxError);
}

View File

@@ -62,4 +62,5 @@ var styles = StyleSheet.create({
}
});
CodePushDemoApp.displayName = 'CodePushDemoApp';
AppRegistry.registerComponent('CodePushDemoApp', () => CodePushDemoApp);

View File

@@ -5,6 +5,7 @@ var CodePushSdk = require('react-native-code-push');
var NativeBridge = require('react-native').NativeModules.CodePush;
var {
AppRegistry,
Text,
View,
} = React;
@@ -39,7 +40,10 @@ var DownloadAndInstallUpdateTest = React.createClass({
runTest() {
var update = require("./TestPackage");
NativeBridge.downloadUpdate(update).done((downloadedPackage) => {
NativeBridge.installUpdate(downloadedPackage, /*rollbackTimeout*/ 1000, CodePushSdk.InstallMode.IMMEDIATE);
NativeBridge.installUpdate(downloadedPackage, /*rollbackTimeout*/ 1000, CodePushSdk.InstallMode.IMMEDIATE)
.then(() => {
NativeBridge.restartApp(/*rollbackTimeout*/ 1000);
});
});
},
@@ -56,5 +60,6 @@ var DownloadAndInstallUpdateTest = React.createClass({
});
DownloadAndInstallUpdateTest.displayName = 'DownloadAndInstallUpdateTest';
AppRegistry.registerComponent('CodePushDemoApp', () => DownloadAndInstallUpdateTest);
module.exports = DownloadAndInstallUpdateTest;

View File

@@ -36,8 +36,14 @@ module.exports = (NativeCodePush) => {
};
var local = {
install: function install(rollbackTimeout = 0, installMode = NativeCodePush.codePushInstallModeOnNextRestart) {
return NativeCodePush.installUpdate(this, rollbackTimeout, installMode);
install: function install(rollbackTimeout = 0, installMode = NativeCodePush.codePushInstallModeOnNextRestart, updateInstalledCallback) {
return NativeCodePush.installUpdate(this, rollbackTimeout, installMode)
.then(function() {
updateInstalledCallback && updateInstalledCallback();
if (installMode == NativeCodePush.codePushInstallModeImmediate) {
NativeCodePush.restartApp(rollbackTimeout);
}
});
}
};