mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-06-10 07:10:36 +08:00
CR feedback
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -109,7 +109,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="CodePushReactPackage.cs" />
|
||||
<Compile Include="CodePushConstants.cs" />
|
||||
<Compile Include="CodePushLifecycleEventListener.cs" />
|
||||
<Compile Include="MinBackgroundListener.cs" />
|
||||
<Compile Include="InstallMode.cs" />
|
||||
<Compile Include="CodePushNativeModule.cs" />
|
||||
<Compile Include="UpdateManager.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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,13 +56,10 @@ namespace CodePush.ReactNative
|
||||
|
||||
public IReadOnlyList<INativeModule> CreateNativeModules(ReactContext reactContext)
|
||||
{
|
||||
_codePushNativeModule = new CodePushNativeModule(reactContext, this);
|
||||
var nativeModules = new List<INativeModule>
|
||||
return new List<INativeModule>
|
||||
{
|
||||
_codePushNativeModule
|
||||
new CodePushNativeModule(reactContext, this)
|
||||
};
|
||||
|
||||
return nativeModules;
|
||||
}
|
||||
|
||||
public IReadOnlyList<IViewManager> CreateViewManagers(ReactContext reactContext)
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -123,7 +123,14 @@ namespace CodePush.ReactNative
|
||||
|
||||
internal async Task<string> 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<string> 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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user