diff --git a/CodePush.js b/CodePush.js index eee79d8..0ae086d 100644 --- a/CodePush.js +++ b/CodePush.js @@ -271,13 +271,9 @@ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProg log("User cancelled the update."); break; case CodePush.SyncStatus.UPDATE_INSTALLED: - /* - * If the install mode is IMMEDIATE, this will not get returned as the - * app will be restarted to a new Javascript context. - */ if (resolvedInstallMode == CodePush.InstallMode.ON_NEXT_RESTART) { log("Update is installed and will be run on the next app restart."); - } else { + } else if (resolvedInstallMode == CodePush.InstallMode.ON_NEXT_RESUME) { if (syncOptions.minimumBackgroundDuration > 0) { log(`Update is installed and will be run after the app has been in the background for at least ${syncOptions.minimumBackgroundDuration} seconds.`); } else { diff --git a/windows/CodePush.csproj b/windows/CodePush.csproj index ad3c48d..57b76f3 100644 --- a/windows/CodePush.csproj +++ b/windows/CodePush.csproj @@ -109,7 +109,7 @@ - + diff --git a/windows/CodePushNativeModule.cs b/windows/CodePushNativeModule.cs index bd0a4df..6b90a43 100644 --- a/windows/CodePushNativeModule.cs +++ b/windows/CodePushNativeModule.cs @@ -13,9 +13,9 @@ namespace CodePush.ReactNative { internal class CodePushNativeModule : ReactContextNativeModuleBase { - private CodePushLifecycleEventListener _codePushLifecycleEventListener = null; - private ReactContext _reactContext; private CodePushReactPackage _codePush; + private MinBackgroundListener _minBackgroundListener; + private ReactContext _reactContext; public CodePushNativeModule(ReactContext reactContext, CodePushReactPackage codePush) : base(reactContext) { @@ -196,7 +196,7 @@ namespace CodePush.ReactNative SettingsManager.SavePendingUpdate(pendingHash, /* isLoading */false); if (installMode == (int)InstallMode.OnNextResume) { - if (_codePushLifecycleEventListener == null) + if (_minBackgroundListener == null) { // Ensure we do not add the listener twice. Action loadBundleAction = () => @@ -207,12 +207,12 @@ namespace CodePush.ReactNative }); }; - _codePushLifecycleEventListener = new CodePushLifecycleEventListener(loadBundleAction, minimumBackgroundDuration); - _reactContext.AddLifecycleEventListener(_codePushLifecycleEventListener); + _minBackgroundListener = new MinBackgroundListener(loadBundleAction, minimumBackgroundDuration); + _reactContext.AddLifecycleEventListener(_minBackgroundListener); } else { - _codePushLifecycleEventListener.MinimumBackgroundDuration = minimumBackgroundDuration; + _minBackgroundListener.MinimumBackgroundDuration = minimumBackgroundDuration; } } diff --git a/windows/CodePushReactPackage.cs b/windows/CodePushReactPackage.cs index 9a7f321..1aa931b 100644 --- a/windows/CodePushReactPackage.cs +++ b/windows/CodePushReactPackage.cs @@ -56,13 +56,10 @@ namespace CodePush.ReactNative public IReadOnlyList CreateNativeModules(ReactContext reactContext) { - _codePushNativeModule = new CodePushNativeModule(reactContext, this); - var nativeModules = new List + return new List { - _codePushNativeModule + new CodePushNativeModule(reactContext, this) }; - - return nativeModules; } public IReadOnlyList CreateViewManagers(ReactContext reactContext) diff --git a/windows/CodePushLifecycleEventListener.cs b/windows/MinBackgroundListener.cs similarity index 72% rename from windows/CodePushLifecycleEventListener.cs rename to windows/MinBackgroundListener.cs index 5dc3552..cbc213d 100644 --- a/windows/CodePushLifecycleEventListener.cs +++ b/windows/MinBackgroundListener.cs @@ -3,17 +3,17 @@ using System; namespace CodePush.ReactNative { - internal class CodePushLifecycleEventListener : ILifecycleEventListener + internal class MinBackgroundListener : ILifecycleEventListener { private DateTime? _lastSuspendDate = null; - private Action _loadBundleAction; + private Action _resumeAction; internal int MinimumBackgroundDuration { get; set; } - internal CodePushLifecycleEventListener(Action loadBundleAction, int minimumBackgroundDuration) + internal MinBackgroundListener(Action resumeAction, int minBackgroundDuration) { - _loadBundleAction = loadBundleAction; - MinimumBackgroundDuration = minimumBackgroundDuration; + _resumeAction = resumeAction; + MinimumBackgroundDuration = minBackgroundDuration; } public void OnDestroy() @@ -29,7 +29,7 @@ namespace CodePush.ReactNative double durationInBackground = (new DateTime() - (DateTime)_lastSuspendDate).TotalSeconds; if (durationInBackground >= MinimumBackgroundDuration) { - _loadBundleAction.Invoke(); + _resumeAction.Invoke(); } } } diff --git a/windows/UpdateManager.cs b/windows/UpdateManager.cs index 313dba7..be6f202 100644 --- a/windows/UpdateManager.cs +++ b/windows/UpdateManager.cs @@ -123,7 +123,14 @@ namespace CodePush.ReactNative internal async Task GetCurrentPackageHash() { - JObject currentPackageMetadata = await GetCurrentPackage(); + JObject info = await GetCurrentPackageInfo(); + string currentPackageShortHash = (string)info[CodePushConstants.CurrentPackageKey]; + if (currentPackageShortHash == null) + { + return null; + } + + JObject currentPackageMetadata = await GetPackage(currentPackageShortHash); return currentPackageMetadata == null ? null : (string)currentPackageMetadata[CodePushConstants.PackageHashKey]; } @@ -170,16 +177,25 @@ namespace CodePush.ReactNative internal async Task GetPreviousPackageHash() { - JObject previousPackageMetadata = await GetPreviousPackage(); + JObject info = await GetCurrentPackageInfo(); + string previousPackageShortHash = (string)info[CodePushConstants.PreviousPackageKey]; + if (previousPackageShortHash == null) + { + return null; + } + + JObject previousPackageMetadata = await GetPackage(previousPackageShortHash); return previousPackageMetadata == null ? null : (string)previousPackageMetadata[CodePushConstants.PackageHashKey]; } - internal async Task InstallPackage(JObject updatePackage, bool removePendingUpdate) + internal async Task InstallPackage(JObject updatePackage, bool currentUpdateIsPending) { var packageHash = (string)updatePackage[CodePushConstants.PackageHashKey]; JObject info = await GetCurrentPackageInfo(); - if (removePendingUpdate) + if (currentUpdateIsPending) { + // Don't back up current update to the "previous" position because + // it is an unverified update which should not be rolled back to. StorageFolder currentPackageFolder = await GetCurrentPackageFolder(); if (currentPackageFolder != null) {