Skip to content

Commit d43ed8e

Browse files
committed
fix: 高版本 win11 检测版本会很慢
1 parent e5c5441 commit d43ed8e

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

src/Lavcode.Uwp/App.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
4848

4949
#if DEBUG
5050
#else
51-
UpdateHelper.DownloadAndInstallAllUpdates();
51+
UpdateHelper.DownloadAndInstallAllUpdatesBackground();
5252
#endif
5353

5454
CreateFrame();

src/Lavcode.Uwp/Helpers/UpdateHelper.cs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using HTools;
2+
using System;
23
using System.Diagnostics;
34
using System.Threading.Tasks;
45
using Windows.Services.Store;
@@ -7,28 +8,35 @@ namespace Lavcode.Uwp.Helpers
78
{
89
public static class UpdateHelper
910
{
10-
public static async Task DownloadAndInstallAllUpdatesAsync()
11+
public static async Task<bool> DownloadAndInstallAllUpdatesAsync()
1112
{
12-
try
13+
var result = false;
14+
await TaskExtend.Run(async () =>
1315
{
14-
var context = StoreContext.GetDefault();
15-
var updates = await context.GetAppAndOptionalStorePackageUpdatesAsync();
16-
if (updates.Count > 0)
16+
try
1717
{
18-
var downloadResult = await context.RequestDownloadStorePackageUpdatesAsync(updates);
19-
if (downloadResult.OverallState == StorePackageUpdateState.Completed)
18+
var context = StoreContext.GetDefault();
19+
var updates = await context.GetAppAndOptionalStorePackageUpdatesAsync();
20+
if (updates.Count > 0)
2021
{
21-
await context.RequestDownloadAndInstallStorePackageUpdatesAsync(updates);
22+
var downloadResult = await context.RequestDownloadStorePackageUpdatesAsync(updates);
23+
if (downloadResult.OverallState == StorePackageUpdateState.Completed)
24+
{
25+
await context.RequestDownloadAndInstallStorePackageUpdatesAsync(updates);
26+
}
2227
}
28+
result = updates.Count > 0;
2329
}
24-
}
25-
catch (Exception ex)
26-
{
27-
Debug.WriteLine(ex);
28-
}
30+
catch (Exception ex)
31+
{
32+
Debug.WriteLine(ex);
33+
result = false;
34+
}
35+
});
36+
return result;
2937
}
3038

31-
public static async void DownloadAndInstallAllUpdates()
39+
public static async void DownloadAndInstallAllUpdatesBackground()
3240
{
3341
await DownloadAndInstallAllUpdatesAsync();
3442
}

0 commit comments

Comments
 (0)