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

Commit 631894c

Browse files
committed
Merge pull request #28 from Microsoft/failedApply
Implementing "failedApply" property on packages
2 parents c5de1ae + e0ac3a4 commit 631894c

File tree

4 files changed

+160
-141
lines changed

4 files changed

+160
-141
lines changed

CodePush.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#import "RCTBridgeModule.h"
22

3-
@interface CodePush : NSObject <RCTBridgeModule>
3+
@interface CodePush : NSObject<RCTBridgeModule>
44

5-
+ (NSString *) getDocumentsDirectory;
6-
7-
+ (NSURL *) getBundleUrl;
5+
+ (NSString *)getDocumentsDirectory;
6+
+ (NSURL *)getBundleUrl;
87

98
@end
109

@@ -48,4 +47,5 @@
4847
error:(NSError **)error;
4948

5049
+ (void)rollbackPackage;
50+
5151
@end

CodePush.ios.js

Lines changed: 57 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
'use strict';
22

33
var extend = require("extend");
4-
var NativeCodePush = require('react-native').NativeModules.CodePush;
4+
var NativeCodePush = require("react-native").NativeModules.CodePush;
55
var requestFetchAdapter = require("./request-fetch-adapter.js");
66
var Sdk = require("code-push/script/acquisition-sdk").AcquisitionManager;
77
var packageMixins = require("./package-mixins")(NativeCodePush);
8+
89
var { AlertIOS } = require("react-native");
910

1011
// This function is only used for tests. Replaces the default SDK, configuration and native bridge
@@ -50,45 +51,64 @@ var getSdk = (() => {
5051
}
5152
})();
5253

54+
function getCurrentPackage() {
55+
return new Promise((resolve, reject) => {
56+
var localPackage;
57+
NativeCodePush.getCurrentPackage()
58+
.then((currentPackage) => {
59+
localPackage = currentPackage;
60+
return NativeCodePush.isFailedUpdate(currentPackage.packageHash);
61+
})
62+
.then((failedUpdate) => {
63+
localPackage.failedApply = failedUpdate;
64+
resolve(localPackage);
65+
})
66+
.catch(reject)
67+
.done();
68+
});
69+
}
70+
5371
function checkForUpdate() {
5472
var config;
5573
var sdk;
74+
5675
return getConfiguration()
57-
.then((configResult) => {
58-
config = configResult;
59-
return getSdk();
60-
})
61-
.then((sdkResult) => {
62-
sdk = sdkResult;
63-
return getCurrentPackage();
64-
})
65-
.then((localPackage) => {
66-
var queryPackage = {appVersion: config.appVersion};
67-
if (localPackage && localPackage.appVersion === config.appVersion) {
68-
queryPackage = localPackage;
69-
}
70-
71-
return new Promise((resolve, reject) => {
72-
sdk.queryUpdateWithCurrentPackage(queryPackage, (err, update) => {
73-
if (err) return reject(err);
74-
if (update) {
75-
// There is an update available for a different native app version. In the current version of this plugin, we treat that as no update.
76-
if (update.updateAppVersion) resolve(false);
77-
else resolve(extend({}, update, packageMixins.remote));
78-
} else {
79-
resolve(update);
80-
}
81-
});
82-
});
83-
});
84-
}
85-
86-
function getCurrentPackage() {
87-
return NativeCodePush.getCurrentPackage();
88-
}
76+
.then((configResult) => {
77+
config = configResult;
78+
return getSdk();
79+
})
80+
.then((sdkResult) => {
81+
sdk = sdkResult;
82+
return getCurrentPackage();
83+
})
84+
.then((localPackage) => {
85+
var queryPackage = { appVersion: config.appVersion };
86+
if (localPackage && localPackage.appVersion === config.appVersion) {
87+
queryPackage = localPackage;
88+
}
8989

90-
function notifyApplicationReady() {
91-
return NativeCodePush.notifyApplicationReady();
90+
return new Promise((resolve, reject) => {
91+
sdk.queryUpdateWithCurrentPackage(queryPackage, (err, update) => {
92+
if (err) {
93+
reject(err);
94+
}
95+
96+
if (update) {
97+
update = extend(update, packageMixins.remote);
98+
99+
NativeCodePush.isFailedUpdate(update.packageHash)
100+
.then((isFailedHash) => {
101+
update.failedApply = isFailedHash;
102+
resolve(update);
103+
})
104+
.catch(reject)
105+
.done();
106+
} else {
107+
resolve(update);
108+
}
109+
})
110+
});
111+
});
92112
}
93113

94114
/**
@@ -174,10 +194,10 @@ function sync(options = {}) {
174194
};
175195

176196
var CodePush = {
177-
getConfiguration: getConfiguration,
178197
checkForUpdate: checkForUpdate,
198+
getConfiguration: getConfiguration,
179199
getCurrentPackage: getCurrentPackage,
180-
notifyApplicationReady: notifyApplicationReady,
200+
notifyApplicationReady: NativeCodePush.notifyApplicationReady,
181201
setUpTestDependencies: setUpTestDependencies,
182202
sync: sync,
183203
SyncStatus: {

0 commit comments

Comments
 (0)