|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 | 3 | var extend = require("extend");
|
4 |
| -var NativeCodePush = require('react-native').NativeModules.CodePush; |
| 4 | +var NativeCodePush = require("react-native").NativeModules.CodePush; |
5 | 5 | var requestFetchAdapter = require("./request-fetch-adapter.js");
|
6 | 6 | var Sdk = require("code-push/script/acquisition-sdk").AcquisitionManager;
|
7 | 7 | var packageMixins = require("./package-mixins")(NativeCodePush);
|
| 8 | + |
8 | 9 | var { AlertIOS } = require("react-native");
|
9 | 10 |
|
10 | 11 | // This function is only used for tests. Replaces the default SDK, configuration and native bridge
|
@@ -50,45 +51,64 @@ var getSdk = (() => {
|
50 | 51 | }
|
51 | 52 | })();
|
52 | 53 |
|
| 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 | + |
53 | 71 | function checkForUpdate() {
|
54 | 72 | var config;
|
55 | 73 | var sdk;
|
| 74 | + |
56 | 75 | 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 | + } |
89 | 89 |
|
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 | + }); |
92 | 112 | }
|
93 | 113 |
|
94 | 114 | /**
|
@@ -174,10 +194,10 @@ function sync(options = {}) {
|
174 | 194 | };
|
175 | 195 |
|
176 | 196 | var CodePush = {
|
177 |
| - getConfiguration: getConfiguration, |
178 | 197 | checkForUpdate: checkForUpdate,
|
| 198 | + getConfiguration: getConfiguration, |
179 | 199 | getCurrentPackage: getCurrentPackage,
|
180 |
| - notifyApplicationReady: notifyApplicationReady, |
| 200 | + notifyApplicationReady: NativeCodePush.notifyApplicationReady, |
181 | 201 | setUpTestDependencies: setUpTestDependencies,
|
182 | 202 | sync: sync,
|
183 | 203 | SyncStatus: {
|
|
0 commit comments