Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 0225ca4

Browse files
committed
handle uncleared updates debug
1 parent 2141e72 commit 0225ca4

File tree

3 files changed

+55
-49
lines changed

3 files changed

+55
-49
lines changed

CodePush.js

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ async function checkForUpdate(deploymentKey = null) {
7070
* because we want to avoid having to install diff updates against the binary's
7171
* version, which we can't do yet on Android.
7272
*/
73-
if (!update || update.updateAppVersion || localPackage && (update.packageHash === localPackage.packageHash) || !localPackage && config.packageHash === update.packageHash) {
73+
if (
74+
!update ||
75+
update.updateAppVersion ||
76+
localPackage && (update.packageHash === localPackage.packageHash) ||
77+
(!localPackage || localPackage.isRunningBinaryVersion) && config.packageHash === update.packageHash
78+
) {
7479
if (update && update.updateAppVersion) {
7580
log("An update is available but it is targeting a newer binary version than you are currently running.");
7681
}
@@ -368,52 +373,42 @@ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProg
368373
}
369374
};
370375

371-
let CodePush;
372-
373-
// If the "NativeCodePush" variable isn't defined, then
374-
// the app didn't properly install the native module,
375-
// and therefore, it doesn't make sense initializing
376-
// the JS interface when it wouldn't work anyways.
377-
if (NativeCodePush) {
378-
CodePush = {
379-
AcquisitionSdk: Sdk,
380-
checkForUpdate,
381-
getConfiguration,
382-
getCurrentPackage,
383-
log,
384-
notifyApplicationReady,
385-
restartApp,
386-
setUpTestDependencies,
387-
sync,
388-
InstallMode: {
389-
IMMEDIATE: NativeCodePush.codePushInstallModeImmediate, // Restart the app immediately
390-
ON_NEXT_RESTART: NativeCodePush.codePushInstallModeOnNextRestart, // Don't artificially restart the app. Allow the update to be "picked up" on the next app restart
391-
ON_NEXT_RESUME: NativeCodePush.codePushInstallModeOnNextResume // Restart the app the next time it is resumed from the background
392-
},
393-
SyncStatus: {
394-
CHECKING_FOR_UPDATE: 0,
395-
AWAITING_USER_ACTION: 1,
396-
DOWNLOADING_PACKAGE: 2,
397-
INSTALLING_UPDATE: 3,
398-
UP_TO_DATE: 4, // The running app is up-to-date
399-
UPDATE_IGNORED: 5, // The app had an optional update and the end-user chose to ignore it
400-
UPDATE_INSTALLED: 6, // The app had an optional/mandatory update that was successfully downloaded and is about to be installed.
401-
SYNC_IN_PROGRESS: 7, // There is an ongoing "sync" operation in progress.
402-
UNKNOWN_ERROR: -1
403-
},
404-
DEFAULT_UPDATE_DIALOG: {
405-
appendReleaseDescription: false,
406-
descriptionPrefix: " Description: ",
407-
mandatoryContinueButtonLabel: "Continue",
408-
mandatoryUpdateMessage: "An update is available that must be installed.",
409-
optionalIgnoreButtonLabel: "Ignore",
410-
optionalInstallButtonLabel: "Install",
411-
optionalUpdateMessage: "An update is available. Would you like to install it?",
412-
title: "Update available"
413-
}
414-
}
415-
} else {
416-
log("The CodePush module doesn't appear to be properly installed. Please double-check that everything is setup correctly.");
417-
}
376+
const CodePush = {
377+
AcquisitionSdk: Sdk,
378+
checkForUpdate,
379+
getConfiguration,
380+
getCurrentPackage,
381+
log,
382+
notifyApplicationReady,
383+
restartApp,
384+
setUpTestDependencies,
385+
sync,
386+
InstallMode: {
387+
IMMEDIATE: NativeCodePush.codePushInstallModeImmediate, // Restart the app immediately
388+
ON_NEXT_RESTART: NativeCodePush.codePushInstallModeOnNextRestart, // Don't artificially restart the app. Allow the update to be "picked up" on the next app restart
389+
ON_NEXT_RESUME: NativeCodePush.codePushInstallModeOnNextResume // Restart the app the next time it is resumed from the background
390+
},
391+
SyncStatus: {
392+
CHECKING_FOR_UPDATE: 0,
393+
AWAITING_USER_ACTION: 1,
394+
DOWNLOADING_PACKAGE: 2,
395+
INSTALLING_UPDATE: 3,
396+
UP_TO_DATE: 4, // The running app is up-to-date
397+
UPDATE_IGNORED: 5, // The app had an optional update and the end-user chose to ignore it
398+
UPDATE_INSTALLED: 6, // The app had an optional/mandatory update that was successfully downloaded and is about to be installed.
399+
SYNC_IN_PROGRESS: 7, // There is an ongoing "sync" operation in progress.
400+
UNKNOWN_ERROR: -1
401+
},
402+
DEFAULT_UPDATE_DIALOG: {
403+
appendReleaseDescription: false,
404+
descriptionPrefix: " Description: ",
405+
mandatoryContinueButtonLabel: "Continue",
406+
mandatoryUpdateMessage: "An update is available that must be installed.",
407+
optionalIgnoreButtonLabel: "Ignore",
408+
optionalInstallButtonLabel: "Install",
409+
optionalUpdateMessage: "An update is available. Would you like to install it?",
410+
title: "Update available"
411+
}
412+
};
418413

419-
module.exports = CodePush;
414+
module.exports = CodePush;

android/app/src/main/java/com/microsoft/codepush/react/CodePush.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,10 @@ protected Void doInBackground(Object... params) {
423423
return null;
424424
}
425425

426+
if (isRunningBinaryVersion) {
427+
currentPackage.putBoolean("isRunningBinaryVersion", isRunningBinaryVersion);
428+
}
429+
426430
Boolean isPendingUpdate = false;
427431

428432
if (currentPackage.hasKey(codePushPackage.PACKAGE_HASH_KEY)) {

ios/CodePush/CodePush.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,13 @@ - (void)savePendingUpdate:(NSString *)packageHash
480480
return;
481481
}
482482

483+
if (isRunningBinaryVersion) {
484+
// This only matters in Debug builds. Since we do not clear "outdated" updates,
485+
// we need to indicate to the JS side that somehow we have a current update on
486+
// disk that is not actually running.
487+
[package setObject:@(isRunningBinaryVersion) forKey:@"isRunningBinaryVersion"];
488+
}
489+
483490
// Add the "isPending" virtual property to the package at this point, so that
484491
// the script-side doesn't need to immediately call back into native to populate it.
485492
BOOL isPendingUpdate = [self isPendingUpdate:[package objectForKey:PackageHashKey]];

0 commit comments

Comments
 (0)