From 0225ca49a7de1da031c037f92ec54238f13947fb Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Mon, 29 Feb 2016 14:42:49 -0800 Subject: [PATCH 1/6] 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]]; From e1717dd5399f8acca8556eb23ac2b036be44bbaf Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Mon, 29 Feb 2016 14:45:17 -0800 Subject: [PATCH 2/6] revert --- CodePush.js | 84 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 37 deletions(-) diff --git a/CodePush.js b/CodePush.js index e108516..fa38850 100644 --- a/CodePush.js +++ b/CodePush.js @@ -373,42 +373,52 @@ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProg } }; -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" - } -}; +let CodePush; + +// 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; \ No newline at end of file From 9c416cddbcb021a415b0b67589ca5e88c68e1974 Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Mon, 29 Feb 2016 14:45:58 -0800 Subject: [PATCH 3/6] end of file newline --- CodePush.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CodePush.js b/CodePush.js index fa38850..74bdd7c 100644 --- a/CodePush.js +++ b/CodePush.js @@ -421,4 +421,4 @@ if (NativeCodePush) { log("The CodePush module doesn't appear to be properly installed. Please double-check that everything is setup correctly."); } -module.exports = CodePush; \ No newline at end of file +module.exports = CodePush; From 7c5347039ba8d13bc561b0bdd17220d0b6dfcea5 Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Mon, 29 Feb 2016 15:00:28 -0800 Subject: [PATCH 4/6] Update CodePush.js --- CodePush.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/CodePush.js b/CodePush.js index 74bdd7c..41000b4 100644 --- a/CodePush.js +++ b/CodePush.js @@ -70,12 +70,10 @@ 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 || localPackage.isRunningBinaryVersion) && 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."); } From c0d99ab936ae61247c8196b1ae7ded359880db52 Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Mon, 29 Feb 2016 15:08:19 -0800 Subject: [PATCH 5/6] change var name --- CodePush.js | 9 +++------ .../main/java/com/microsoft/codepush/react/CodePush.java | 2 +- ios/CodePush/CodePush.m | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/CodePush.js b/CodePush.js index 74bdd7c..70efd24 100644 --- a/CodePush.js +++ b/CodePush.js @@ -70,12 +70,9 @@ 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 || localPackage.isRunningBinaryVersion) && config.packageHash === update.packageHash - ) { + if (!update || update.updateAppVersion || + localPackage && (update.packageHash === localPackage.packageHash) || + (!localPackage || localPackage._isDebugOnly) && 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."); } 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 89f972a..67314ef 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 @@ -424,7 +424,7 @@ public class CodePush { } if (isRunningBinaryVersion) { - currentPackage.putBoolean("isRunningBinaryVersion", isRunningBinaryVersion); + currentPackage.putBoolean("_isDebugOnly", isRunningBinaryVersion); } Boolean isPendingUpdate = false; diff --git a/ios/CodePush/CodePush.m b/ios/CodePush/CodePush.m index f48e0ff..7dc52ed 100644 --- a/ios/CodePush/CodePush.m +++ b/ios/CodePush/CodePush.m @@ -484,7 +484,7 @@ RCT_EXPORT_METHOD(getCurrentPackage:(RCTPromiseResolveBlock)resolve // 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"]; + [package setObject:@(isRunningBinaryVersion) forKey:@"_isDebugOnly"]; } // Add the "isPending" virtual property to the package at this point, so that From 7dd1b47b134c3fbc943f30f3605f573dace6008e Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Mon, 29 Feb 2016 15:12:56 -0800 Subject: [PATCH 6/6] set to true directly --- .../src/main/java/com/microsoft/codepush/react/CodePush.java | 2 +- ios/CodePush/CodePush.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 67314ef..446e2bc 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 @@ -424,7 +424,7 @@ public class CodePush { } if (isRunningBinaryVersion) { - currentPackage.putBoolean("_isDebugOnly", isRunningBinaryVersion); + currentPackage.putBoolean("_isDebugOnly", true); } Boolean isPendingUpdate = false; diff --git a/ios/CodePush/CodePush.m b/ios/CodePush/CodePush.m index 7dc52ed..b0647b4 100644 --- a/ios/CodePush/CodePush.m +++ b/ios/CodePush/CodePush.m @@ -484,7 +484,7 @@ RCT_EXPORT_METHOD(getCurrentPackage:(RCTPromiseResolveBlock)resolve // 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:@"_isDebugOnly"]; + [package setObject:@(YES) forKey:@"_isDebugOnly"]; } // Add the "isPending" virtual property to the package at this point, so that