perf: 优化检查更新逻辑

This commit is contained in:
uye
2025-05-20 16:24:08 +08:00
parent c92502aed1
commit 81a98638b0
10 changed files with 93 additions and 70 deletions

View File

@@ -20,6 +20,7 @@ using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows;
using MaaWpfGui.Constants;
using MaaWpfGui.Extensions;
using MaaWpfGui.Helper;
@@ -426,6 +427,12 @@ public class VersionUpdateSettingsUserControlModel : PropertyChangedBase
/// ReSharper disable once UnusedMember.Global
public async Task ManualUpdate()
{
if (SettingsViewModel.VersionUpdateSettings.UpdateSource == "MirrorChyan" && string.IsNullOrEmpty(SettingsViewModel.VersionUpdateSettings.MirrorChyanCdk))
{
ToastNotification.ShowDirect(LocalizationHelper.GetString("MirrorChyanSelectedButNoCdk"));
return;
}
var ret = await Instances.VersionUpdateViewModel.CheckAndDownloadVersionUpdate();
var toastMessage = ret switch
@@ -457,21 +464,20 @@ public class VersionUpdateSettingsUserControlModel : PropertyChangedBase
// ReSharper disable once UnusedMember.Global
public async Task ManualUpdateResource()
{
if (SettingsViewModel.VersionUpdateSettings.UpdateSource == "MirrorChyan" && string.IsNullOrEmpty(SettingsViewModel.VersionUpdateSettings.MirrorChyanCdk))
{
ToastNotification.ShowDirect(LocalizationHelper.GetString("MirrorChyanSelectedButNoCdk"));
return;
}
IsCheckingForUpdates = true;
var (ret, uri, releaseNote) = await ResourceUpdater.CheckFromMirrorChyanAsync();
var toastMessage = ret switch
{
VersionUpdateViewModel.CheckUpdateRetT.NoNeedToUpdate => string.Empty,
VersionUpdateViewModel.CheckUpdateRetT.NoNeedToUpdateDebugVersion => LocalizationHelper.GetString("NoNeedToUpdateDebugVersion"),
VersionUpdateViewModel.CheckUpdateRetT.AlreadyLatest => LocalizationHelper.GetString("AlreadyLatest"),
VersionUpdateViewModel.CheckUpdateRetT.UnknownError => LocalizationHelper.GetString("NewVersionDetectFailedTitle"),
VersionUpdateViewModel.CheckUpdateRetT.NetworkError => LocalizationHelper.GetString("CheckNetworking"),
VersionUpdateViewModel.CheckUpdateRetT.FailedToGetInfo => LocalizationHelper.GetString("GetReleaseNoteFailed"),
VersionUpdateViewModel.CheckUpdateRetT.OK => string.Empty,
VersionUpdateViewModel.CheckUpdateRetT.NewVersionIsBeingBuilt => LocalizationHelper.GetString("NewVersionIsBeingBuilt"),
VersionUpdateViewModel.CheckUpdateRetT.OnlyGameResourceUpdated => LocalizationHelper.GetString("GameResourceUpdated"),
VersionUpdateViewModel.CheckUpdateRetT.NoMirrorChyanCdk => LocalizationHelper.GetString("MirrorChyanSoftwareUpdateTip"),
_ => string.Empty,
};
@@ -482,7 +488,7 @@ public class VersionUpdateSettingsUserControlModel : PropertyChangedBase
if (ret == VersionUpdateViewModel.CheckUpdateRetT.AlreadyLatest)
{
SettingsViewModel.VersionUpdateSettings.IsCheckingForUpdates = false;
IsCheckingForUpdates = false;
return;
}