From 0225ca49a7de1da031c037f92ec54238f13947fb Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Mon, 29 Feb 2016 14:42:49 -0800 Subject: [PATCH] handle uncleared updates debug --- CodePush.js | 93 +++++++++---------- .../microsoft/codepush/react/CodePush.java | 4 + ios/CodePush/CodePush.m | 7 ++ 3 files changed, 55 insertions(+), 49 deletions(-) diff --git a/CodePush.js b/CodePush.js index 7834f08..e108516 100644 --- a/CodePush.js +++ b/CodePush.js @@ -70,7 +70,12 @@ async function checkForUpdate(deploymentKey = null) { * because we want to avoid having to install diff updates against the binary's * version, which we can't do yet on Android. */ - if (!update || update.updateAppVersion || localPackage && (update.packageHash === localPackage.packageHash) || !localPackage && config.packageHash === update.packageHash) { + if ( + !update || + update.updateAppVersion || + localPackage && (update.packageHash === localPackage.packageHash) || + (!localPackage || localPackage.isRunningBinaryVersion) && config.packageHash === update.packageHash + ) { if (update && update.updateAppVersion) { log("An update is available but it is targeting a newer binary version than you are currently running."); } @@ -368,52 +373,42 @@ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProg } }; -let CodePush; +const CodePush = { + AcquisitionSdk: Sdk, + checkForUpdate, + getConfiguration, + getCurrentPackage, + log, + notifyApplicationReady, + restartApp, + setUpTestDependencies, + sync, + InstallMode: { + IMMEDIATE: NativeCodePush.codePushInstallModeImmediate, // Restart the app immediately + ON_NEXT_RESTART: NativeCodePush.codePushInstallModeOnNextRestart, // Don't artificially restart the app. Allow the update to be "picked up" on the next app restart + ON_NEXT_RESUME: NativeCodePush.codePushInstallModeOnNextResume // Restart the app the next time it is resumed from the background + }, + SyncStatus: { + CHECKING_FOR_UPDATE: 0, + AWAITING_USER_ACTION: 1, + DOWNLOADING_PACKAGE: 2, + INSTALLING_UPDATE: 3, + UP_TO_DATE: 4, // The running app is up-to-date + UPDATE_IGNORED: 5, // The app had an optional update and the end-user chose to ignore it + UPDATE_INSTALLED: 6, // The app had an optional/mandatory update that was successfully downloaded and is about to be installed. + SYNC_IN_PROGRESS: 7, // There is an ongoing "sync" operation in progress. + UNKNOWN_ERROR: -1 + }, + DEFAULT_UPDATE_DIALOG: { + appendReleaseDescription: false, + descriptionPrefix: " Description: ", + mandatoryContinueButtonLabel: "Continue", + mandatoryUpdateMessage: "An update is available that must be installed.", + optionalIgnoreButtonLabel: "Ignore", + optionalInstallButtonLabel: "Install", + optionalUpdateMessage: "An update is available. Would you like to install it?", + title: "Update available" + } +}; -// If the "NativeCodePush" variable isn't defined, then -// the app didn't properly install the native module, -// and therefore, it doesn't make sense initializing -// the JS interface when it wouldn't work anyways. -if (NativeCodePush) { - CodePush = { - AcquisitionSdk: Sdk, - checkForUpdate, - getConfiguration, - getCurrentPackage, - log, - notifyApplicationReady, - restartApp, - setUpTestDependencies, - sync, - InstallMode: { - IMMEDIATE: NativeCodePush.codePushInstallModeImmediate, // Restart the app immediately - ON_NEXT_RESTART: NativeCodePush.codePushInstallModeOnNextRestart, // Don't artificially restart the app. Allow the update to be "picked up" on the next app restart - ON_NEXT_RESUME: NativeCodePush.codePushInstallModeOnNextResume // Restart the app the next time it is resumed from the background - }, - SyncStatus: { - CHECKING_FOR_UPDATE: 0, - AWAITING_USER_ACTION: 1, - DOWNLOADING_PACKAGE: 2, - INSTALLING_UPDATE: 3, - UP_TO_DATE: 4, // The running app is up-to-date - UPDATE_IGNORED: 5, // The app had an optional update and the end-user chose to ignore it - UPDATE_INSTALLED: 6, // The app had an optional/mandatory update that was successfully downloaded and is about to be installed. - SYNC_IN_PROGRESS: 7, // There is an ongoing "sync" operation in progress. - UNKNOWN_ERROR: -1 - }, - DEFAULT_UPDATE_DIALOG: { - appendReleaseDescription: false, - descriptionPrefix: " Description: ", - mandatoryContinueButtonLabel: "Continue", - mandatoryUpdateMessage: "An update is available that must be installed.", - optionalIgnoreButtonLabel: "Ignore", - optionalInstallButtonLabel: "Install", - optionalUpdateMessage: "An update is available. Would you like to install it?", - title: "Update available" - } - } -} else { - log("The CodePush module doesn't appear to be properly installed. Please double-check that everything is setup correctly."); -} - -module.exports = CodePush; +module.exports = CodePush; \ No newline at end of file diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java index da51b84..89f972a 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java @@ -423,6 +423,10 @@ public class CodePush { return null; } + if (isRunningBinaryVersion) { + currentPackage.putBoolean("isRunningBinaryVersion", isRunningBinaryVersion); + } + Boolean isPendingUpdate = false; if (currentPackage.hasKey(codePushPackage.PACKAGE_HASH_KEY)) { diff --git a/ios/CodePush/CodePush.m b/ios/CodePush/CodePush.m index 0ccbc64..f48e0ff 100644 --- a/ios/CodePush/CodePush.m +++ b/ios/CodePush/CodePush.m @@ -480,6 +480,13 @@ RCT_EXPORT_METHOD(getCurrentPackage:(RCTPromiseResolveBlock)resolve return; } + if (isRunningBinaryVersion) { + // This only matters in Debug builds. Since we do not clear "outdated" updates, + // we need to indicate to the JS side that somehow we have a current update on + // disk that is not actually running. + [package setObject:@(isRunningBinaryVersion) forKey:@"isRunningBinaryVersion"]; + } + // Add the "isPending" virtual property to the package at this point, so that // the script-side doesn't need to immediately call back into native to populate it. BOOL isPendingUpdate = [self isPendingUpdate:[package objectForKey:PackageHashKey]];