Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #90 from Microsoft/fix-deployment-key-override
Browse files Browse the repository at this point in the history
Fix deployment key override
  • Loading branch information
geof90 committed Mar 31, 2016
2 parents 1667076 + d5dba80 commit 633fc83
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
17 changes: 11 additions & 6 deletions bin/www/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var Sdk = (function () {
function Sdk() {
}
Sdk.getAcquisitionManager = function (callback, userDeploymentKey, contentType) {
var resolveManager = function (defaultInstance) {
var resolveManager = function () {
if (userDeploymentKey || contentType) {
var customConfiguration = {
deploymentKey: (userDeploymentKey ? userDeploymentKey : Sdk.DefaultConfiguration.deploymentKey),
Expand All @@ -28,18 +28,21 @@ var Sdk = (function () {
var customAcquisitionManager = new AcquisitionManager(requester, customConfiguration);
callback(null, customAcquisitionManager);
}
else {
else if (Sdk.DefaultConfiguration.deploymentKey) {
callback(null, Sdk.DefaultAcquisitionManager);
}
else {
callback(new Error("No deployment key provided, please provide a default one in your config.xml or specify one in the call to checkForUpdate() or sync()."), null);
}
};
if (Sdk.DefaultAcquisitionManager) {
resolveManager(Sdk.DefaultAcquisitionManager);
resolveManager();
}
else {
NativeAppInfo.getServerURL(function (serverError, serverURL) {
NativeAppInfo.getDeploymentKey(function (depolymentKeyError, deploymentKey) {
NativeAppInfo.getApplicationVersion(function (appVersionError, appVersion) {
if (!serverURL || !deploymentKey || !appVersion) {
if (!serverURL || !appVersion) {
callback(new Error("Could not get the CodePush configuration. Please check your config.xml file."), null);
}
else {
Expand All @@ -50,8 +53,10 @@ var Sdk = (function () {
appVersion: appVersion,
clientUniqueId: device.uuid
};
Sdk.DefaultAcquisitionManager = new AcquisitionManager(new HttpRequester(), Sdk.DefaultConfiguration);
resolveManager(Sdk.DefaultAcquisitionManager);
if (deploymentKey) {
Sdk.DefaultAcquisitionManager = new AcquisitionManager(new HttpRequester(), Sdk.DefaultConfiguration);
}
resolveManager();
}
});
});
Expand Down
24 changes: 15 additions & 9 deletions www/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class Sdk {

private static DefaultAcquisitionManager: AcquisitionManager;
private static DefaultConfiguration: Configuration;

/**
* Reads the CodePush configuration and creates an AcquisitionManager instance using it.
*/
public static getAcquisitionManager(callback: Callback<AcquisitionManager>, userDeploymentKey?: string, contentType?: string): void {

var resolveManager = (defaultInstance: AcquisitionManager): void => {
var resolveManager = (): void => {
if (userDeploymentKey || contentType) {
var customConfiguration: Configuration = {
deploymentKey: (userDeploymentKey ? userDeploymentKey : Sdk.DefaultConfiguration.deploymentKey),
Expand All @@ -32,18 +32,20 @@ class Sdk {
var requester = new HttpRequester(contentType);
var customAcquisitionManager: AcquisitionManager = new AcquisitionManager(requester, customConfiguration);
callback(null, customAcquisitionManager);
} else {
} else if (Sdk.DefaultConfiguration.deploymentKey) {
callback(null, Sdk.DefaultAcquisitionManager);
} else {
callback(new Error("No deployment key provided, please provide a default one in your config.xml or specify one in the call to checkForUpdate() or sync()."), null);
}
};

if (Sdk.DefaultAcquisitionManager) {
resolveManager(Sdk.DefaultAcquisitionManager);
resolveManager();
} else {
NativeAppInfo.getServerURL((serverError: Error, serverURL: string) => {
NativeAppInfo.getDeploymentKey((depolymentKeyError: Error, deploymentKey: string) => {
NativeAppInfo.getApplicationVersion((appVersionError: Error, appVersion: string) => {
if (!serverURL || !deploymentKey || !appVersion) {
if (!serverURL || !appVersion) {
callback(new Error("Could not get the CodePush configuration. Please check your config.xml file."), null);
} else {
Sdk.DefaultConfiguration = {
Expand All @@ -53,8 +55,12 @@ class Sdk {
appVersion: appVersion,
clientUniqueId: device.uuid
};
Sdk.DefaultAcquisitionManager = new AcquisitionManager(new HttpRequester(), Sdk.DefaultConfiguration);
resolveManager(Sdk.DefaultAcquisitionManager);

if (deploymentKey) {
Sdk.DefaultAcquisitionManager = new AcquisitionManager(new HttpRequester(), Sdk.DefaultConfiguration);
}

resolveManager();
}
});
});
Expand All @@ -79,7 +85,7 @@ class Sdk {
callback && callback(new Error("An error occured while reporting the deployment status. " + e), null);
}
}

/**
* Reports the download status to the CodePush server.
*/
Expand All @@ -99,4 +105,4 @@ class Sdk {
}
}

export = Sdk;
export = Sdk;

0 comments on commit 633fc83

Please sign in to comment.