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

Commit 46cdaf8

Browse files
committed
Merge pull request #61 from Microsoft/config_updates
Misc. product updates/improvements
2 parents 380df40 + 9e8c676 commit 46cdaf8

File tree

5 files changed

+258
-198
lines changed

5 files changed

+258
-198
lines changed

CodePush.h

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,26 @@
22

33
@interface CodePush : NSObject<RCTBridgeModule>
44

5-
+ (NSURL *)getBundleUrl;
6-
+ (NSString *)getDocumentsDirectory;
7-
8-
@end
9-
10-
@interface CodePushConfig : NSObject
5+
+ (NSURL *)bundleURL;
116

12-
+ (void)setDeploymentKey:(NSString *)deploymentKey;
13-
+ (NSString *)getDeploymentKey;
7+
+ (NSURL *)bundleURLForResourceName:(NSString *)resourceName;
148

15-
+ (void)setServerUrl:(NSString *)setServerUrl;
16-
+ (NSString *)getServerUrl;
9+
+ (NSURL *)bundleURLForResourceName:(NSString *)resourceName
10+
withExtension:(NSString *)resourceExtension;
1711

18-
+ (void)setAppVersion:(NSString *)appVersion;
19-
+ (NSString *)getAppVersion;
12+
+ (NSString *)getDocumentsDirectory;
2013

21-
+ (void)setBuildVersion:(NSString *)buildVersion;
22-
+ (NSString *)getBuildVersion;
14+
@end
2315

24-
+ (void)setRootComponent:(NSString *)rootComponent;
16+
@interface CodePushConfig : NSObject
2517

26-
+ (NSString *)getRootComponent;
18+
@property (readonly) NSString *appVersion;
19+
@property (readonly) NSString *buildVersion;
20+
@property (readonly) NSDictionary *configuration;
21+
@property (copy) NSString *deploymentKey;
22+
@property (copy) NSString *serverURL;
2723

28-
+ (NSDictionary *)getConfiguration;
24+
+ (instancetype)current;
2925

3026
@end
3127

CodePush.ios.js

Lines changed: 73 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,70 @@
11
'use strict';
22

3+
var { AlertIOS } = require("react-native");
34
var NativeCodePush = require("react-native").NativeModules.CodePush;
5+
var packageMixins = require("./package-mixins")(NativeCodePush);
46
var requestFetchAdapter = require("./request-fetch-adapter.js");
57
var Sdk = require("code-push/script/acquisition-sdk").AcquisitionManager;
6-
var packageMixins = require("./package-mixins")(NativeCodePush);
78

8-
var { AlertIOS } = require("react-native");
9+
function checkForUpdate() {
10+
var config;
11+
var sdk;
12+
13+
return getConfiguration()
14+
.then((configResult) => {
15+
config = configResult;
16+
return getSdk();
17+
})
18+
.then((sdkResult) => {
19+
sdk = sdkResult;
20+
return getCurrentPackage();
21+
})
22+
.then((localPackage) => {
23+
var queryPackage = { appVersion: config.appVersion };
24+
if (localPackage && localPackage.appVersion === config.appVersion) {
25+
queryPackage = localPackage;
26+
}
927

10-
// This function is only used for tests. Replaces the default SDK, configuration and native bridge
11-
function setUpTestDependencies(providedTestSdk, providedTestConfig, testNativeBridge){
12-
if (providedTestSdk) testSdk = providedTestSdk;
13-
if (providedTestConfig) testConfig = providedTestConfig;
14-
if (testNativeBridge) NativeCodePush = testNativeBridge;
28+
return new Promise((resolve, reject) => {
29+
sdk.queryUpdateWithCurrentPackage(queryPackage, (err, update) => {
30+
if (err) {
31+
return reject(err);
32+
}
33+
34+
// Ignore updates that require a newer app version,
35+
// since the end-user couldn't reliably install it
36+
if (!update || update.updateAppVersion) {
37+
return resolve(null);
38+
}
39+
40+
update = Object.assign(update, packageMixins.remote);
41+
42+
NativeCodePush.isFailedUpdate(update.packageHash)
43+
.then((isFailedHash) => {
44+
update.failedInstall = isFailedHash;
45+
resolve(update);
46+
})
47+
.catch(reject)
48+
.done();
49+
})
50+
});
51+
});
1552
}
16-
var testConfig;
17-
var testSdk;
53+
54+
var isConfigValid = true;
1855

1956
var getConfiguration = (() => {
2057
var config;
2158
return function getConfiguration() {
22-
if (config) {
59+
if (config && isConfigValid) {
2360
return Promise.resolve(config);
2461
} else if (testConfig) {
2562
return Promise.resolve(testConfig);
2663
} else {
2764
return NativeCodePush.getConfiguration()
2865
.then((configuration) => {
2966
if (!config) config = configuration;
67+
isConfigValid = true;
3068
return config;
3169
});
3270
}
@@ -71,54 +109,33 @@ function getCurrentPackage() {
71109
});
72110
}
73111

74-
function checkForUpdate() {
75-
var config;
76-
var sdk;
77-
78-
return getConfiguration()
79-
.then((configResult) => {
80-
config = configResult;
81-
return getSdk();
82-
})
83-
.then((sdkResult) => {
84-
sdk = sdkResult;
85-
return getCurrentPackage();
86-
})
87-
.then((localPackage) => {
88-
var queryPackage = { appVersion: config.appVersion };
89-
if (localPackage && localPackage.appVersion === config.appVersion) {
90-
queryPackage = localPackage;
91-
}
112+
/* Logs messages to console with the [CodePush] prefix */
113+
function log(message) {
114+
console.log(`[CodePush] ${message}`)
115+
}
92116

93-
return new Promise((resolve, reject) => {
94-
sdk.queryUpdateWithCurrentPackage(queryPackage, (err, update) => {
95-
if (err) {
96-
return reject(err);
97-
}
98-
99-
// Ignore updates that require a newer app version,
100-
// since the end-user couldn't reliably install it
101-
if (!update || update.updateAppVersion) {
102-
return resolve(null);
103-
}
117+
function restartApp(rollbackTimeout = 0) {
118+
NativeCodePush.restartApp(rollbackTimeout);
119+
}
104120

105-
update = Object.assign(update, packageMixins.remote);
106-
107-
NativeCodePush.isFailedUpdate(update.packageHash)
108-
.then((isFailedHash) => {
109-
update.failedInstall = isFailedHash;
110-
resolve(update);
111-
})
112-
.catch(reject)
113-
.done();
114-
})
115-
});
116-
});
121+
function setDeploymentKey(deploymentKey) {
122+
return NativeCodePush.setDeploymentKey(deploymentKey)
123+
.then(() => {
124+
// Mark the local copy of the config data
125+
// as invalid since we just modified it
126+
// on the native end.
127+
isConfigValid = false;
128+
});
117129
}
118130

119-
/* Logs messages to console with the [CodePush] prefix */
120-
function log(message) {
121-
console.log(`[CodePush] ${message}`)
131+
var testConfig;
132+
var testSdk;
133+
134+
// This function is only used for tests. Replaces the default SDK, configuration and native bridge
135+
function setUpTestDependencies(providedTestSdk, providedTestConfig, testNativeBridge) {
136+
if (providedTestSdk) testSdk = providedTestSdk;
137+
if (providedTestConfig) testConfig = providedTestConfig;
138+
if (testNativeBridge) NativeCodePush = testNativeBridge;
122139
}
123140

124141
/**
@@ -271,6 +288,8 @@ var CodePush = {
271288
getCurrentPackage: getCurrentPackage,
272289
log: log,
273290
notifyApplicationReady: NativeCodePush.notifyApplicationReady,
291+
restartApp: restartApp,
292+
setDeploymentKey: setDeploymentKey,
274293
setUpTestDependencies: setUpTestDependencies,
275294
sync: sync,
276295
InstallMode: {

0 commit comments

Comments
 (0)