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

Commit 40b8c8e

Browse files
author
Geoffrey Goh
committed
CR feedback
1 parent 08283ef commit 40b8c8e

File tree

6 files changed

+36
-27
lines changed

6 files changed

+36
-27
lines changed

CodePush.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,9 @@ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProg
271271
log("User cancelled the update.");
272272
break;
273273
case CodePush.SyncStatus.UPDATE_INSTALLED:
274-
/*
275-
* If the install mode is IMMEDIATE, this will not get returned as the
276-
* app will be restarted to a new Javascript context.
277-
*/
278274
if (resolvedInstallMode == CodePush.InstallMode.ON_NEXT_RESTART) {
279275
log("Update is installed and will be run on the next app restart.");
280-
} else {
276+
} else if (resolvedInstallMode == CodePush.InstallMode.ON_NEXT_RESUME) {
281277
if (syncOptions.minimumBackgroundDuration > 0) {
282278
log(`Update is installed and will be run after the app has been in the background for at least ${syncOptions.minimumBackgroundDuration} seconds.`);
283279
} else {

windows/CodePush.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
<ItemGroup>
110110
<Compile Include="CodePushReactPackage.cs" />
111111
<Compile Include="CodePushConstants.cs" />
112-
<Compile Include="CodePushLifecycleEventListener.cs" />
112+
<Compile Include="MinBackgroundListener.cs" />
113113
<Compile Include="InstallMode.cs" />
114114
<Compile Include="CodePushNativeModule.cs" />
115115
<Compile Include="UpdateManager.cs" />

windows/CodePushNativeModule.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ namespace CodePush.ReactNative
1313
{
1414
internal class CodePushNativeModule : ReactContextNativeModuleBase
1515
{
16-
private CodePushLifecycleEventListener _codePushLifecycleEventListener = null;
17-
private ReactContext _reactContext;
1816
private CodePushReactPackage _codePush;
17+
private MinBackgroundListener _minBackgroundListener;
18+
private ReactContext _reactContext;
1919

2020
public CodePushNativeModule(ReactContext reactContext, CodePushReactPackage codePush) : base(reactContext)
2121
{
@@ -196,7 +196,7 @@ public void installUpdate(JObject updatePackage, int installMode, int minimumBac
196196
SettingsManager.SavePendingUpdate(pendingHash, /* isLoading */false);
197197
if (installMode == (int)InstallMode.OnNextResume)
198198
{
199-
if (_codePushLifecycleEventListener == null)
199+
if (_minBackgroundListener == null)
200200
{
201201
// Ensure we do not add the listener twice.
202202
Action loadBundleAction = () =>
@@ -207,12 +207,12 @@ public void installUpdate(JObject updatePackage, int installMode, int minimumBac
207207
});
208208
};
209209

210-
_codePushLifecycleEventListener = new CodePushLifecycleEventListener(loadBundleAction, minimumBackgroundDuration);
211-
_reactContext.AddLifecycleEventListener(_codePushLifecycleEventListener);
210+
_minBackgroundListener = new MinBackgroundListener(loadBundleAction, minimumBackgroundDuration);
211+
_reactContext.AddLifecycleEventListener(_minBackgroundListener);
212212
}
213213
else
214214
{
215-
_codePushLifecycleEventListener.MinimumBackgroundDuration = minimumBackgroundDuration;
215+
_minBackgroundListener.MinimumBackgroundDuration = minimumBackgroundDuration;
216216
}
217217
}
218218

windows/CodePushReactPackage.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,10 @@ public IReadOnlyList<Type> CreateJavaScriptModulesConfig()
5656

5757
public IReadOnlyList<INativeModule> CreateNativeModules(ReactContext reactContext)
5858
{
59-
_codePushNativeModule = new CodePushNativeModule(reactContext, this);
60-
var nativeModules = new List<INativeModule>
59+
return new List<INativeModule>
6160
{
62-
_codePushNativeModule
61+
new CodePushNativeModule(reactContext, this)
6362
};
64-
65-
return nativeModules;
6663
}
6764

6865
public IReadOnlyList<IViewManager> CreateViewManagers(ReactContext reactContext)

windows/CodePushLifecycleEventListener.cs renamed to windows/MinBackgroundListener.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33

44
namespace CodePush.ReactNative
55
{
6-
internal class CodePushLifecycleEventListener : ILifecycleEventListener
6+
internal class MinBackgroundListener : ILifecycleEventListener
77
{
88
private DateTime? _lastSuspendDate = null;
9-
private Action _loadBundleAction;
9+
private Action _resumeAction;
1010

1111
internal int MinimumBackgroundDuration { get; set; }
1212

13-
internal CodePushLifecycleEventListener(Action loadBundleAction, int minimumBackgroundDuration)
13+
internal MinBackgroundListener(Action resumeAction, int minBackgroundDuration)
1414
{
15-
_loadBundleAction = loadBundleAction;
16-
MinimumBackgroundDuration = minimumBackgroundDuration;
15+
_resumeAction = resumeAction;
16+
MinimumBackgroundDuration = minBackgroundDuration;
1717
}
1818

1919
public void OnDestroy()
@@ -29,7 +29,7 @@ public void OnResume()
2929
double durationInBackground = (new DateTime() - (DateTime)_lastSuspendDate).TotalSeconds;
3030
if (durationInBackground >= MinimumBackgroundDuration)
3131
{
32-
_loadBundleAction.Invoke();
32+
_resumeAction.Invoke();
3333
}
3434
}
3535
}

windows/UpdateManager.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,14 @@ internal async Task<StorageFile> GetCurrentPackageBundle(string bundleFileName)
123123

124124
internal async Task<string> GetCurrentPackageHash()
125125
{
126-
JObject currentPackageMetadata = await GetCurrentPackage();
126+
JObject info = await GetCurrentPackageInfo();
127+
string currentPackageShortHash = (string)info[CodePushConstants.CurrentPackageKey];
128+
if (currentPackageShortHash == null)
129+
{
130+
return null;
131+
}
132+
133+
JObject currentPackageMetadata = await GetPackage(currentPackageShortHash);
127134
return currentPackageMetadata == null ? null : (string)currentPackageMetadata[CodePushConstants.PackageHashKey];
128135
}
129136

@@ -170,16 +177,25 @@ internal async Task<JObject> GetPreviousPackage()
170177

171178
internal async Task<string> GetPreviousPackageHash()
172179
{
173-
JObject previousPackageMetadata = await GetPreviousPackage();
180+
JObject info = await GetCurrentPackageInfo();
181+
string previousPackageShortHash = (string)info[CodePushConstants.PreviousPackageKey];
182+
if (previousPackageShortHash == null)
183+
{
184+
return null;
185+
}
186+
187+
JObject previousPackageMetadata = await GetPackage(previousPackageShortHash);
174188
return previousPackageMetadata == null ? null : (string)previousPackageMetadata[CodePushConstants.PackageHashKey];
175189
}
176190

177-
internal async Task InstallPackage(JObject updatePackage, bool removePendingUpdate)
191+
internal async Task InstallPackage(JObject updatePackage, bool currentUpdateIsPending)
178192
{
179193
var packageHash = (string)updatePackage[CodePushConstants.PackageHashKey];
180194
JObject info = await GetCurrentPackageInfo();
181-
if (removePendingUpdate)
195+
if (currentUpdateIsPending)
182196
{
197+
// Don't back up current update to the "previous" position because
198+
// it is an unverified update which should not be rolled back to.
183199
StorageFolder currentPackageFolder = await GetCurrentPackageFolder();
184200
if (currentPackageFolder != null)
185201
{

0 commit comments

Comments
 (0)