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

Commit 32dea6b

Browse files
committed
feedback
1 parent f035e59 commit 32dea6b

23 files changed

+198
-227
lines changed

CodePush.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function checkForUpdate(deploymentKey = null) {
3434
config = configResult;
3535
}
3636

37-
sdk = getSDK(config);
37+
sdk = new module.exports.AcquisitionSdk(requestFetchAdapter, config);
3838

3939
// Allow dynamic overwrite of function. This is only to be used for tests.
4040
return module.exports.getCurrentPackage();
@@ -129,11 +129,6 @@ function getCurrentPackage() {
129129
});
130130
}
131131

132-
function getSDK(config) {
133-
// Allow dynamic overwrite of acquisition SDK. This is only to be used for tests.
134-
return new module.exports.AcquisitionSdk(requestFetchAdapter, config);
135-
}
136-
137132
/* Logs messages to console with the [CodePush] prefix */
138133
function log(message) {
139134
console.log(`[CodePush] ${message}`)

CodePush.m

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ + (NSURL *)bundleURLForResource:(NSString *)resourceName
5050
NSString *packageFile = [CodePushPackage getCurrentPackageBundlePath:&error];
5151
NSURL *binaryJsBundleUrl = [[NSBundle mainBundle] URLForResource:resourceName withExtension:resourceExtension];
5252

53+
NSString *logMessageFormat = @"Loading JS bundle from %@";
54+
5355
if (error || !packageFile) {
56+
NSLog(logMessageFormat, binaryJsBundleUrl);
5457
return binaryJsBundleUrl;
5558
}
5659

@@ -61,8 +64,11 @@ + (NSURL *)bundleURLForResource:(NSString *)resourceName
6164

6265
if ([binaryDate compare:packageDate] == NSOrderedAscending) {
6366
// Return package file because it is newer than the app store binary's JS bundle
64-
return [[NSURL alloc] initFileURLWithPath:packageFile];
67+
NSURL *packageUrl = [[NSURL alloc] initFileURLWithPath:packageFile];
68+
NSLog(logMessageFormat, packageUrl);
69+
return packageUrl;
6570
} else {
71+
NSLog(logMessageFormat, binaryJsBundleUrl);
6672
return binaryJsBundleUrl;
6773
}
6874
}
@@ -159,6 +165,7 @@ - (void)initializeUpdateAfterRestart
159165
if (updateIsLoading) {
160166
// Pending update was initialized, but notifyApplicationReady was not called.
161167
// Therefore, deduce that it is a broken update and rollback.
168+
NSLog(@"Update did not finish loading the last time, rolling back to a previous version.");
162169
[self rollbackPackage];
163170
} else {
164171
// Mark that we tried to initialize the new update, so that if it crashes,
@@ -214,8 +221,7 @@ - (void)loadBundle
214221
// file (since Chrome wouldn't support it). Otherwise, update
215222
// the current bundle URL to point at the latest update
216223
if ([CodePush isUsingTestConfiguration] || ![_bridge.bundleURL.scheme hasPrefix:@"http"]) {
217-
NSURL *url = [CodePush bundleURL];
218-
_bridge.bundleURL = url;
224+
_bridge.bundleURL = [CodePush bundleURL];
219225
}
220226

221227
[_bridge reload];
@@ -386,17 +392,15 @@ - (void)savePendingUpdate:(NSString *)packageHash
386392
[self savePendingUpdate:updatePackage[PackageHashKey]
387393
isLoading:NO];
388394

389-
if (installMode == CodePushInstallModeOnNextResume) {
395+
if (installMode == CodePushInstallModeOnNextResume && !_hasResumeListener) {
390396
// Ensure we do not add the listener twice.
391-
if (!_hasResumeListener) {
392-
// Register for app resume notifications so that we
393-
// can check for pending updates which support "restart on resume"
394-
[[NSNotificationCenter defaultCenter] addObserver:self
395-
selector:@selector(loadBundle)
396-
name:UIApplicationWillEnterForegroundNotification
397-
object:[UIApplication sharedApplication]];
398-
_hasResumeListener = YES;
399-
}
397+
// Register for app resume notifications so that we
398+
// can check for pending updates which support "restart on resume"
399+
[[NSNotificationCenter defaultCenter] addObserver:self
400+
selector:@selector(loadBundle)
401+
name:UIApplicationWillEnterForegroundNotification
402+
object:[UIApplication sharedApplication]];
403+
_hasResumeListener = YES;
400404
}
401405
// Signal to JS that the update has been applied.
402406
resolve(nil);
@@ -453,8 +457,9 @@ - (void)savePendingUpdate:(NSString *)packageHash
453457

454458
/*
455459
* This method is the native side of the CodePush.downloadAndReplaceCurrentBundle()
456-
* method, which is only to be used during tests and no-ops if the test configuration
457-
* flag is not set.
460+
* method, which replaces the current bundle with the one downloaded from
461+
* removeBundleUrl. It is only to be used during tests and no-ops if the test
462+
* configuration flag is not set.
458463
*/
459464
RCT_EXPORT_METHOD(downloadAndReplaceCurrentBundle:(NSString *)remoteBundleUrl)
460465
{
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
export let serverPackage = {
2+
appVersion: "1.5.0",
3+
description: "Angry flappy birds",
4+
downloadUrl: "http://www.windowsazure.com/blobs/awperoiuqpweru",
5+
isAvailable: true,
6+
isMandatory: false,
7+
packageHash: "hash240",
8+
packageSize: 1024,
9+
updateAppVersion: false
10+
};
11+
12+
export let localPackage = {
13+
downloadURL: "http://www.windowsazure.com/blobs/awperoiuqpweru",
14+
description: "Angry flappy birds",
15+
appVersion: "1.5.0",
16+
label: "2.4.0",
17+
isMandatory: false,
18+
isAvailable: true,
19+
updateAppVersion: false,
20+
packageHash: "hash123",
21+
packageSize: 1024
22+
};
23+
24+
export let updateAppVersionPackage = {
25+
appVersion: "1.5.0",
26+
description: "",
27+
downloadUrl: "",
28+
isAvailable: false,
29+
isMandatory: false,
30+
packageHash: "",
31+
updateAppVersion: true
32+
};

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,8 @@ let PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCo
88
import assert from "assert";
99
import createMockAcquisitionSdk from "../../utils/mockAcquisitionSdk";
1010

11-
let serverPackage = {
12-
appVersion: "1.5.0",
13-
description: "Angry flappy birds",
14-
downloadUrl: "http://www.windowsazure.com/blobs/awperoiuqpweru",
15-
isAvailable: true,
16-
isMandatory: false,
17-
packageHash: "hash240",
18-
packageSize: 1024,
19-
updateAppVersion: false
20-
};
21-
22-
let localPackage = {};
11+
import { serverPackage } from "../resources/testPackages";
12+
const localPackage = {};
2313

2414
let FirstUpdateTest = createTestCaseComponent(
2515
"FirstUpdateTest",

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

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,7 @@ let PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCo
88
import assert from "assert";
99
import createMockAcquisitionSdk from "../../utils/mockAcquisitionSdk";
1010

11-
let serverPackage = {
12-
appVersion: "1.5.0",
13-
description: "Angry flappy birds",
14-
downloadUrl: "http://www.windowsazure.com/blobs/awperoiuqpweru",
15-
isAvailable: true,
16-
isMandatory: false,
17-
packageHash: "hash240",
18-
packageSize: 1024,
19-
updateAppVersion: false
20-
};
21-
22-
let localPackage = {
23-
downloadURL: "http://www.windowsazure.com/blobs/awperoiuqpweru",
24-
description: "Angry flappy birds",
25-
appVersion: "1.5.0",
26-
label: "2.4.0",
27-
isMandatory: false,
28-
isAvailable: true,
29-
updateAppVersion: false,
30-
packageHash: "hash123",
31-
packageSize: 1024
32-
};
11+
import { serverPackage, localPackage } from "../resources/testPackages";
3312

3413
let NewUpdateTest = createTestCaseComponent(
3514
"NewUpdateTest",

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,7 @@ let PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCo
88
import assert from "assert";
99
import createMockAcquisitionSdk from "../../utils/mockAcquisitionSdk";
1010

11-
let serverPackage = {
12-
appVersion: "1.5.0",
13-
description: "",
14-
downloadUrl: "",
15-
isAvailable: false,
16-
isMandatory: false,
17-
packageHash: "",
18-
updateAppVersion: true
19-
};
20-
11+
import { updateAppVersionPackage as serverPackage } from "../resources/testPackages";
2112
let localPackage = {};
2213

2314
let RemotePackageAppVersionNewerTest = createTestCaseComponent(

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,8 @@ let PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCo
88
import assert from "assert";
99
import createMockAcquisitionSdk from "../../utils/mockAcquisitionSdk";
1010

11-
let serverPackage = {
12-
appVersion: "1.5.0",
13-
description: "Angry flappy birds",
14-
downloadUrl: "http://www.windowsazure.com/blobs/awperoiuqpweru",
15-
isAvailable: true,
16-
isMandatory: false,
17-
packageHash: "hash240",
18-
packageSize: 1024,
19-
updateAppVersion: false
20-
};
21-
22-
let localPackage = serverPackage;
11+
import { serverPackage } from "../resources/testPackages";
12+
const localPackage = serverPackage;
2313

2414
let SamePackageTest = createTestCaseComponent(
2515
"SamePackageTest",

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,9 @@ let PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCo
88
import assert from "assert";
99
import createMockAcquisitionSdk from "../../utils/mockAcquisitionSdk";
1010

11-
let serverPackage = {
12-
appVersion: "1.5.0",
13-
description: "Angry flappy birds",
14-
downloadUrl: "http://www.windowsazure.com/blobs/awperoiuqpweru",
15-
isAvailable: true,
16-
isMandatory: false,
17-
packageHash: "hash240",
18-
packageSize: 1024,
19-
updateAppVersion: false
20-
};
11+
import { serverPackage } from "../resources/testPackages";
12+
const localPackage = {};
2113

22-
let localPackage = {};
2314
let deploymentKey = "myKey123";
2415

2516
let SwitchDeploymentKeyTest = createTestCaseComponent(

Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests/resources/TestPackages.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ packages.forEach((aPackage) => {
4444
}
4545
});
4646

47-
module.exports = packages;
47+
export default packages;

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
"use strict";
22

33
import React from "react-native";
4-
let { Platform } = require("react-native");
4+
import { Platform, AppRegistry, Text, View } from "react-native";
55
import CodePush from "react-native-code-push";
66
let NativeCodePush = React.NativeModules.CodePush;
77
let RCTTestModule = React.NativeModules.TestModule;
88

9-
let {
10-
AppRegistry,
11-
Text,
12-
View,
13-
} = React;
14-
159
let NotifyApplicationReadyTest = React.createClass({
1610
getInitialState() {
1711
return {};

0 commit comments

Comments
 (0)