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

Commit 9396824

Browse files
rozelegeof90
authored andcommitted
style(CodePush): Minor cosmetic changes throughout project (#549)
Includes the following changes: * UpdateState.Lastest -> UpdateState.Latest * Added *Async suffix to Task returning methods * Using DateTimeOffset in MinimumBackgroundListener * Disposing IDisposable streams in UpdateManager.DownloadPackage
1 parent 7aa0e29 commit 9396824

File tree

6 files changed

+88
-85
lines changed

6 files changed

+88
-85
lines changed

windows/CodePushConstants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal class CodePushConstants
2121
internal const string PendingUpdateKey = "CODE_PUSH_PENDING_UPDATE";
2222
internal const string PendingUpdateIsLoadingKey = "isLoading";
2323
internal const string PreviousPackageKey = "previousPackage";
24-
// This needs to be kept in sync with https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManager.java#L78
24+
// This needs to be kept in sync with https://github.com/ReactWindows/react-native-windows/blob/master/ReactWindows/ReactNative/DevSupport/DevSupportManager.cs#L22
2525
internal const string ReactDevBundleCacheFileName = "ReactNativeDevBundle.js";
2626
internal const string ReactNativeLogCategory = "ReactNative";
2727
internal const string RelativeBundlePathKey = "bundlePath";

windows/CodePushNativeModule.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public override IReadOnlyDictionary<string, object> Constants
4242
{ "codePushInstallModeOnNextRestart", InstallMode.OnNextRestart },
4343
{ "codePushUpdateStateRunning", UpdateState.Running },
4444
{ "codePushUpdateStatePending", UpdateState.Pending },
45-
{ "codePushUpdateStateLatest", UpdateState.Lastest },
45+
{ "codePushUpdateStateLatest", UpdateState.Latest },
4646
};
4747
}
4848
}
@@ -59,8 +59,8 @@ public void downloadUpdate(JObject updatePackage, bool notifyProgress, IPromise
5959
{
6060
try
6161
{
62-
updatePackage[CodePushConstants.BinaryModifiedTimeKey] = "" + await _codePush.GetBinaryResourcesModifiedTime();
63-
await _codePush.UpdateManager.DownloadPackage(
62+
updatePackage[CodePushConstants.BinaryModifiedTimeKey] = "" + await _codePush.GetBinaryResourcesModifiedTimeAsync();
63+
await _codePush.UpdateManager.DownloadPackageAsync(
6464
updatePackage,
6565
_codePush.AssetsBundleFileName,
6666
new Progress<HttpProgress>(
@@ -84,7 +84,7 @@ await _codePush.UpdateManager.DownloadPackage(
8484
)
8585
);
8686

87-
JObject newPackage = await _codePush.UpdateManager.GetPackage((string)updatePackage[CodePushConstants.PackageHashKey]);
87+
JObject newPackage = await _codePush.UpdateManager.GetPackageAsync((string)updatePackage[CodePushConstants.PackageHashKey]);
8888
promise.Resolve(newPackage);
8989
}
9090
catch (InvalidDataException e)
@@ -128,7 +128,7 @@ public void getUpdateMetadata(UpdateState updateState, IPromise promise)
128128
{
129129
Action getCurrentPackageAction = async () =>
130130
{
131-
JObject currentPackage = await _codePush.UpdateManager.GetCurrentPackage();
131+
JObject currentPackage = await _codePush.UpdateManager.GetCurrentPackageAsync();
132132
if (currentPackage == null)
133133
{
134134
promise.Resolve("");
@@ -153,7 +153,7 @@ public void getUpdateMetadata(UpdateState updateState, IPromise promise)
153153
{
154154
// The caller wants the running update, but the current
155155
// one is pending, so we need to grab the previous.
156-
promise.Resolve(await _codePush.UpdateManager.GetPreviousPackage());
156+
promise.Resolve(await _codePush.UpdateManager.GetPreviousPackageAsync());
157157
}
158158
else
159159
{
@@ -191,7 +191,7 @@ public void installUpdate(JObject updatePackage, InstallMode installMode, int mi
191191
{
192192
Action installUpdateAction = async () =>
193193
{
194-
await _codePush.UpdateManager.InstallPackage(updatePackage, SettingsManager.IsPendingUpdate(null));
194+
await _codePush.UpdateManager.InstallPackageAsync(updatePackage, SettingsManager.IsPendingUpdate(null));
195195
var pendingHash = (string)updatePackage[CodePushConstants.PackageHashKey];
196196
SettingsManager.SavePendingUpdate(pendingHash, /* isLoading */false);
197197
if (installMode == InstallMode.OnNextResume)
@@ -203,7 +203,7 @@ public void installUpdate(JObject updatePackage, InstallMode installMode, int mi
203203
{
204204
Context.RunOnNativeModulesQueueThread(async () =>
205205
{
206-
await LoadBundle();
206+
await LoadBundleAsync();
207207
});
208208
};
209209

@@ -236,7 +236,7 @@ public void isFirstRun(string packageHash, IPromise promise)
236236
bool isFirstRun = _codePush.DidUpdate
237237
&& packageHash != null
238238
&& packageHash.Length > 0
239-
&& packageHash.Equals(await _codePush.UpdateManager.GetCurrentPackageHash());
239+
&& packageHash.Equals(await _codePush.UpdateManager.GetCurrentPackageHashAsync());
240240
promise.Resolve(isFirstRun);
241241
};
242242

@@ -259,14 +259,14 @@ public void restartApp(bool onlyIfUpdateIsPending)
259259
// is current pending update, then reload the app.
260260
if (!onlyIfUpdateIsPending || SettingsManager.IsPendingUpdate(null))
261261
{
262-
await LoadBundle();
262+
await LoadBundleAsync();
263263
}
264264
};
265265

266266
Context.RunOnNativeModulesQueueThread(restartAppAction);
267267
}
268268

269-
internal async Task LoadBundle()
269+
internal async Task LoadBundleAsync()
270270
{
271271
// #1) Get the private ReactInstanceManager, which is what includes
272272
// the logic to reload the current React context.

windows/CodePushReactPackage.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ public async Task<string> GetJavaScriptBundleFileAsync(string assetsBundleFileNa
8585
{
8686
AssetsBundleFileName = assetsBundleFileName;
8787
string binaryJsBundleUrl = CodePushConstants.AssetsBundlePrefix + assetsBundleFileName;
88-
var binaryResourcesModifiedTime = await GetBinaryResourcesModifiedTime();
89-
var packageFile = await UpdateManager.GetCurrentPackageBundle(AssetsBundleFileName);
88+
var binaryResourcesModifiedTime = await GetBinaryResourcesModifiedTimeAsync();
89+
var packageFile = await UpdateManager.GetCurrentPackageBundleAsync(AssetsBundleFileName);
9090
if (packageFile == null)
9191
{
9292
// There has not been any downloaded updates.
@@ -95,7 +95,7 @@ public async Task<string> GetJavaScriptBundleFileAsync(string assetsBundleFileNa
9595
return binaryJsBundleUrl;
9696
}
9797

98-
var packageMetadata = await UpdateManager.GetCurrentPackage();
98+
var packageMetadata = await UpdateManager.GetCurrentPackageAsync();
9999
long? binaryModifiedDateDuringPackageInstall = null;
100100
var binaryModifiedDateDuringPackageInstallString = (string)packageMetadata[CodePushConstants.BinaryModifiedTimeKey];
101101
if (binaryModifiedDateDuringPackageInstallString != null)
@@ -119,7 +119,7 @@ public async Task<string> GetJavaScriptBundleFileAsync(string assetsBundleFileNa
119119
DidUpdate = false;
120120
if (!MainPage.UseDeveloperSupport || !AppVersion.Equals(packageAppVersion))
121121
{
122-
await ClearUpdates();
122+
await ClearUpdatesAsync();
123123
}
124124

125125
CodePushUtils.LogBundleUrl(binaryJsBundleUrl);
@@ -132,7 +132,7 @@ public async Task<string> GetJavaScriptBundleFileAsync(string assetsBundleFileNa
132132

133133
#region Internal methods
134134

135-
internal async Task<long> GetBinaryResourcesModifiedTime()
135+
internal async Task<long> GetBinaryResourcesModifiedTimeAsync()
136136
{
137137
var assetJSBundleFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(CodePushConstants.AssetsBundlePrefix + AssetsBundleFileName));
138138
var fileProperties = await assetJSBundleFile.GetBasicPropertiesAsync();
@@ -151,15 +151,15 @@ internal void InitializeUpdateAfterRestart()
151151
// Therefore, deduce that it is a broken update and rollback.
152152
CodePushUtils.Log("Update did not finish loading the last time, rolling back to a previous version.");
153153
NeedToReportRollback = true;
154-
RollbackPackage().Wait();
154+
RollbackPackageAsync().Wait();
155155
}
156156
else
157157
{
158158
DidUpdate = true;
159159
// Clear the React dev bundle cache so that new updates can be loaded.
160160
if (MainPage.UseDeveloperSupport)
161161
{
162-
ClearReactDevBundleCache().Wait();
162+
ClearReactDevBundleCacheAsync().Wait();
163163
}
164164
// Mark that we tried to initialize the new update, so that if it crashes,
165165
// we will know that we need to rollback when the app next starts.
@@ -168,9 +168,9 @@ internal void InitializeUpdateAfterRestart()
168168
}
169169
}
170170

171-
internal async Task ClearUpdates()
171+
internal async Task ClearUpdatesAsync()
172172
{
173-
await UpdateManager.ClearUpdates();
173+
await UpdateManager.ClearUpdatesAsync();
174174
SettingsManager.RemovePendingUpdate();
175175
SettingsManager.RemoveFailedUpdates();
176176
}
@@ -179,7 +179,7 @@ internal async Task ClearUpdates()
179179

180180
#region Private methods
181181

182-
private async Task ClearReactDevBundleCache()
182+
private async Task ClearReactDevBundleCacheAsync()
183183
{
184184
var devBundleCacheFile = (StorageFile) await ApplicationData.Current.LocalFolder.TryGetItemAsync(CodePushConstants.ReactDevBundleCacheFileName);
185185
if (devBundleCacheFile != null)
@@ -188,11 +188,11 @@ private async Task ClearReactDevBundleCache()
188188
}
189189
}
190190

191-
private async Task RollbackPackage()
191+
private async Task RollbackPackageAsync()
192192
{
193-
JObject failedPackage = await UpdateManager.GetCurrentPackage();
193+
JObject failedPackage = await UpdateManager.GetCurrentPackageAsync();
194194
SettingsManager.SaveFailedUpdate(failedPackage);
195-
await UpdateManager.RollbackPackage();
195+
await UpdateManager.RollbackPackageAsync();
196196
SettingsManager.RemovePendingUpdate();
197197
}
198198

windows/MinimumBackgroundListener.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace CodePush.ReactNative
55
{
66
internal class MinimumBackgroundListener : ILifecycleEventListener
77
{
8-
private DateTime? _lastSuspendDate;
8+
private DateTimeOffset? _lastSuspendDate;
99
private Action _resumeAction;
1010

1111
internal int MinimumBackgroundDuration { get; set; }
@@ -26,7 +26,7 @@ public void OnResume()
2626
{
2727
// Determine how long the app was in the background and ensure
2828
// that it meets the minimum duration amount of time.
29-
double durationInBackground = (new DateTime() - (DateTime)_lastSuspendDate).TotalSeconds;
29+
double durationInBackground = (DateTimeOffset.Now - _lastSuspendDate.Value).TotalSeconds;
3030
if (durationInBackground >= MinimumBackgroundDuration)
3131
{
3232
_resumeAction.Invoke();
@@ -38,7 +38,7 @@ public void OnSuspend()
3838
{
3939
// Save the current time so that when the app is later
4040
// resumed, we can detect how long it was in the background.
41-
_lastSuspendDate = new DateTime();
41+
_lastSuspendDate = DateTimeOffset.Now;
4242
}
4343
}
4444
}

0 commit comments

Comments
 (0)