Skip to content

Commit

Permalink
Updated CodePush.syncInternal's management of SyncStatus
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 1cb8ff2 commit ada29b7
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/codePush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { RemotePackage } from "./remotePackage";
import { Sdk } from "./sdk";
import { SyncOptions, UpdateDialogOptions } from "./syncOptions";
import { SyncStatus } from "./syncStatus";
import { Dialog } from "@capacitor/dialog";
import { ConfirmResult, Dialog } from "@capacitor/dialog";

interface CodePushCapacitorPlugin {

Expand Down Expand Up @@ -423,18 +423,20 @@ class CodePush implements CodePushCapacitorPlugin {
const onUpdate = async (remotePackage: RemotePackage) => {
const updateShouldBeIgnored = remotePackage && (remotePackage.failedInstall && syncOptions.ignoreFailedUpdates);
if (updateShouldBeIgnored) {
if (updateShouldBeIgnored) {
CodePushUtil.logMessage("An update is available, but it is being ignored due to have been previously rolled back.");
}

syncCallback && syncCallback(null, SyncStatus.UP_TO_DATE);
syncCallback && syncCallback(null, SyncStatus.UPDATE_IGNORED);
} else {
const dlgOpts: UpdateDialogOptions = <UpdateDialogOptions>syncOptions.updateDialog;
if (dlgOpts) {
CodePushUtil.logMessage("Awaiting user action.");
syncCallback && syncCallback(null, SyncStatus.AWAITING_USER_ACTION);
}
if (remotePackage.isMandatory && syncOptions.updateDialog) {

if (remotePackage === null) {
/* Then the app is up to date */
syncCallback && syncCallback(null, SyncStatus.UP_TO_DATE);
} else if (remotePackage.isMandatory && syncOptions.updateDialog) {
/* Alert user */
const message = dlgOpts.appendReleaseDescription ?
dlgOpts.mandatoryUpdateMessage + dlgOpts.descriptionPrefix + remotePackage.description
Expand All @@ -451,14 +453,14 @@ class CodePush implements CodePushCapacitorPlugin {
dlgOpts.optionalUpdateMessage + dlgOpts.descriptionPrefix + remotePackage.description
: dlgOpts.optionalUpdateMessage;

const confirmResult = await Dialog.confirm({
const confirmResult: ConfirmResult = await Dialog.confirm({
message,
title: dlgOpts.updateTitle,
okButtonTitle: dlgOpts.optionalInstallButtonLabel,
cancelButtonTitle: dlgOpts.optionalIgnoreButtonLabel
});

if (confirmResult.value) {
if (confirmResult.value === true) {
/* Install */
downloadAndInstallUpdate(remotePackage);
} else {
Expand Down

0 comments on commit ada29b7

Please sign in to comment.