forked from microsoft/react-native-code-push
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package-mixins.js
48 lines (43 loc) · 1.58 KB
/
package-mixins.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var extend = require("extend");
var { NativeAppEventEmitter } = require("react-native");
module.exports = (NativeCodePush) => {
var remote = {
abortDownload: function abortDownload() {
return NativeCodePush.abortDownload(this);
},
download: function download(progressHandler) {
if (!this.downloadUrl) {
return Promise.reject(new Error("Cannot download an update without a download url"));
}
var downloadProgressSubscription;
if (progressHandler) {
// Use event subscription to obtain download progress.
downloadProgressSubscription = NativeAppEventEmitter.addListener(
"CodePushDownloadProgress",
progressHandler
);
}
// Use the downloaded package info. Native code will save the package info
// so that the client knows what the current package version is.
return NativeCodePush.downloadUpdate(this)
.then((downloadedPackage) => {
downloadProgressSubscription && downloadProgressSubscription.remove();
return extend({}, downloadedPackage, local);
})
.catch((error) => {
downloadProgressSubscription && downloadProgressSubscription.remove();
// Rethrow the error for subsequent handlers down the promise chain.
throw error;
});
}
};
var local = {
apply: function apply(rollbackTimeout = 0, restartMode = NativeCodePush.codePushRestartModeImmediate) {
return NativeCodePush.applyUpdate(this, rollbackTimeout, restartMode);
}
};
return {
remote: remote,
local: local
};
};