Skip to content

Commit

Permalink
Simplified & beautified Promise calls in checkForUpdate
Browse files Browse the repository at this point in the history
Signed-off-by: Clovis Durand <[email protected]>
  • Loading branch information
Clovel committed Jul 8, 2021
1 parent 602a65b commit 1cb8ff2
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/codePush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,16 @@ class CodePush implements CodePushCapacitorPlugin {
const queryUpdate = async () => {
try {
const acquisitionManager = await Sdk.getAcquisitionManager(deploymentKey);
LocalPackage.getCurrentOrDefaultPackage().then(async (localPackage: LocalPackage) => {
const localPackage = await LocalPackage.getCurrentOrDefaultPackage();
try {
const currentBinaryVersion = await NativeAppInfo.getApplicationVersion();
localPackage.appVersion = currentBinaryVersion;
} catch (e) {
/* Nothing to do */
/* TODO : Why ? */
}
CodePushUtil.logMessage("Checking for update.");
acquisitionManager.queryUpdateWithCurrentPackage(localPackage, callback);
}, (error: Error) => {
CodePushUtil.invokeErrorCallback(error, queryError);
});
} catch (e) {
CodePushUtil.invokeErrorCallback(e, queryError);
}
Expand All @@ -264,12 +263,16 @@ class CodePush implements CodePushCapacitorPlugin {
if (deploymentKey) {
queryUpdate();
} else {
NativeAppInfo.getDeploymentKey().then(defaultDeploymentKey => {
deploymentKey = defaultDeploymentKey;
queryUpdate();
}, deploymentKeyError => {
CodePushUtil.invokeErrorCallback(deploymentKeyError, queryError);
});
NativeAppInfo.getDeploymentKey()
.then(
(defaultDeploymentKey) => {
deploymentKey = defaultDeploymentKey;
queryUpdate();
},
(deploymentKeyError) => {
CodePushUtil.invokeErrorCallback(deploymentKeyError, queryError);
}
);
}
} catch (e) {
CodePushUtil.invokeErrorCallback(new Error("An error occurred while querying for updates." + CodePushUtil.getErrorMessage(e)), queryError);
Expand Down

0 comments on commit 1cb8ff2

Please sign in to comment.