|
1 | 1 | 'use strict';
|
2 | 2 |
|
| 3 | +var { AlertIOS } = require("react-native"); |
3 | 4 | var NativeCodePush = require("react-native").NativeModules.CodePush;
|
| 5 | +var packageMixins = require("./package-mixins")(NativeCodePush); |
4 | 6 | var requestFetchAdapter = require("./request-fetch-adapter.js");
|
5 | 7 | var Sdk = require("code-push/script/acquisition-sdk").AcquisitionManager;
|
6 |
| -var packageMixins = require("./package-mixins")(NativeCodePush); |
7 |
| - |
8 |
| -var { AlertIOS } = require("react-native"); |
9 |
| - |
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; |
15 |
| -} |
16 |
| -var testConfig; |
17 |
| -var testSdk; |
18 | 8 |
|
19 | 9 | function checkForUpdate() {
|
20 | 10 | var config;
|
@@ -61,10 +51,12 @@ function checkForUpdate() {
|
61 | 51 | });
|
62 | 52 | }
|
63 | 53 |
|
| 54 | +var isConfigValid = true; |
| 55 | + |
64 | 56 | var getConfiguration = (() => {
|
65 | 57 | var config;
|
66 | 58 | return function getConfiguration() {
|
67 |
| - if (config) { |
| 59 | + if (config && isConfigValid) { |
68 | 60 | return Promise.resolve(config);
|
69 | 61 | } else if (testConfig) {
|
70 | 62 | return Promise.resolve(testConfig);
|
@@ -125,6 +117,26 @@ function restartApp(rollbackTimeout = 0) {
|
125 | 117 | NativeCodePush.restartApp(rollbackTimeout);
|
126 | 118 | }
|
127 | 119 |
|
| 120 | +function setDeploymentKey(deploymentKey) { |
| 121 | + return NativeCodePush.setDeploymentKey(deploymentKey) |
| 122 | + .then(() => { |
| 123 | + // Mark the local copy of the config data |
| 124 | + // as invalid since we just modified it |
| 125 | + // on the native end. |
| 126 | + isConfigValid = false; |
| 127 | + }); |
| 128 | +} |
| 129 | + |
| 130 | +var testConfig; |
| 131 | +var testSdk; |
| 132 | + |
| 133 | +// This function is only used for tests. Replaces the default SDK, configuration and native bridge |
| 134 | +function setUpTestDependencies(providedTestSdk, providedTestConfig, testNativeBridge) { |
| 135 | + if (providedTestSdk) testSdk = providedTestSdk; |
| 136 | + if (providedTestConfig) testConfig = providedTestConfig; |
| 137 | + if (testNativeBridge) NativeCodePush = testNativeBridge; |
| 138 | +} |
| 139 | + |
128 | 140 | /**
|
129 | 141 | * The sync method provides a simple, one-line experience for
|
130 | 142 | * incorporating the check, download and application of an update.
|
@@ -276,7 +288,7 @@ var CodePush = {
|
276 | 288 | log: log,
|
277 | 289 | notifyApplicationReady: NativeCodePush.notifyApplicationReady,
|
278 | 290 | restartApp: restartApp,
|
279 |
| - setDeploymentKey: NativeCodePush.setDeploymentKey, |
| 291 | + setDeploymentKey: setDeploymentKey, |
280 | 292 | setUpTestDependencies: setUpTestDependencies,
|
281 | 293 | sync: sync,
|
282 | 294 | InstallMode: {
|
|
0 commit comments