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

Commit 2c1bb66

Browse files
committed
Updating config options
1 parent 380df40 commit 2c1bb66

File tree

4 files changed

+191
-165
lines changed

4 files changed

+191
-165
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: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,51 @@ function setUpTestDependencies(providedTestSdk, providedTestConfig, testNativeBr
1616
var testConfig;
1717
var testSdk;
1818

19+
function checkForUpdate() {
20+
var config;
21+
var sdk;
22+
23+
return getConfiguration()
24+
.then((configResult) => {
25+
config = configResult;
26+
return getSdk();
27+
})
28+
.then((sdkResult) => {
29+
sdk = sdkResult;
30+
return getCurrentPackage();
31+
})
32+
.then((localPackage) => {
33+
var queryPackage = { appVersion: config.appVersion };
34+
if (localPackage && localPackage.appVersion === config.appVersion) {
35+
queryPackage = localPackage;
36+
}
37+
38+
return new Promise((resolve, reject) => {
39+
sdk.queryUpdateWithCurrentPackage(queryPackage, (err, update) => {
40+
if (err) {
41+
return reject(err);
42+
}
43+
44+
// Ignore updates that require a newer app version,
45+
// since the end-user couldn't reliably install it
46+
if (!update || update.updateAppVersion) {
47+
return resolve(null);
48+
}
49+
50+
update = Object.assign(update, packageMixins.remote);
51+
52+
NativeCodePush.isFailedUpdate(update.packageHash)
53+
.then((isFailedHash) => {
54+
update.failedInstall = isFailedHash;
55+
resolve(update);
56+
})
57+
.catch(reject)
58+
.done();
59+
})
60+
});
61+
});
62+
}
63+
1964
var getConfiguration = (() => {
2065
var config;
2166
return function getConfiguration() {
@@ -71,56 +116,15 @@ function getCurrentPackage() {
71116
});
72117
}
73118

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-
}
92-
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-
}
104-
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-
});
117-
}
118-
119119
/* Logs messages to console with the [CodePush] prefix */
120120
function log(message) {
121121
console.log(`[CodePush] ${message}`)
122122
}
123123

124+
function restartApp(rollbackTimeout = 0) {
125+
NativeCodePush.restartApp(rollbackTimeout);
126+
}
127+
124128
/**
125129
* The sync method provides a simple, one-line experience for
126130
* incorporating the check, download and application of an update.
@@ -214,7 +218,7 @@ function sync(options = {}, syncStatusChangeCallback, downloadProgressCallback)
214218
if (typeof syncOptions.updateDialog !== "object") {
215219
syncOptions.updateDialog = CodePush.DEFAULT_UPDATE_DIALOG;
216220
} else {
217-
syncOptions.updateDialog = Object.assign({}, CodePush.DEFAULT_UPDATE_DIALOG, syncOptions.updateDialog);
221+
syncOptions.updateDialog = Object.assign(CodePush.DEFAULT_UPDATE_DIALOG, syncOptions.updateDialog);
218222
}
219223

220224
var message = null;
@@ -258,6 +262,7 @@ function sync(options = {}, syncStatusChangeCallback, downloadProgressCallback)
258262
}
259263
})
260264
.catch((error) => {
265+
console.log(error);
261266
syncStatusChangeCallback(CodePush.SyncStatus.UNKNOWN_ERROR);
262267
reject(error);
263268
})
@@ -271,6 +276,8 @@ var CodePush = {
271276
getCurrentPackage: getCurrentPackage,
272277
log: log,
273278
notifyApplicationReady: NativeCodePush.notifyApplicationReady,
279+
restartApp: restartApp,
280+
setDeploymentKey: NativeCodePush.setDeploymentKey,
274281
setUpTestDependencies: setUpTestDependencies,
275282
sync: sync,
276283
InstallMode: {

0 commit comments

Comments
 (0)