Files
downkyicore/DownKyi/ViewModels/Dialogs/NewVersionAvailableDialogViewModel.cs
to_mo_to 58d66986c8 feat: 加入启动自动更新检测 (#317)
* feat: 加入启动自动更新检测

* 修改

* 还原功能外的更改
2025-06-20 23:00:12 +08:00

82 lines
2.5 KiB
C#

using System.Collections.ObjectModel;
using Avalonia.Controls.Documents;
using DownKyi.Utils;
using Prism.Commands;
using Prism.Services.Dialogs;
using SqlSugar;
using System.Linq;
using DownKyi.Core.Settings;
using DownKyi.Models;
namespace DownKyi.ViewModels.Dialogs
{
public class NewVersionAvailableDialogViewModel : BaseDialogViewModel
{
public const string Tag = "NewVersionAvailable";
private DelegateCommand? _allowCommand;
private DelegateCommand? _skipCurrentVersionCommand;
public DelegateCommand SkipCurrentVersionCommand => _skipCurrentVersionCommand ??= new DelegateCommand(ExecuteSkipCurrentVersionCommand);
public DelegateCommand AllowCommand => _allowCommand ??= new DelegateCommand(ExecuteAllowCommand);
private void ExecuteAllowCommand()
{
const ButtonResult result = ButtonResult.OK;
PlatformHelper.Open($"https://github.com/{App.RepoOwner}/{App.RepoName}/releases/tag/{TagName}");
RaiseRequestClose(new DialogResult(result));
}
private void ExecuteSkipCurrentVersionCommand()
{
SettingsManager.GetInstance().SetSkipVersionOnLaunch(NewVersion);
RaiseRequestClose(new DialogResult());
}
private string _tagName;
public string TagName
{
get => _tagName;
set => SetProperty(ref _tagName, value);
}
private string _markdownText;
public string MarkdownText
{
get => _markdownText;
set => SetProperty(ref _markdownText, value);
}
private bool _enableSkipVersionOnLaunch = false;
private string _newVersion;
private string NewVersion
{
get => _newVersion;
set => SetProperty(ref _newVersion, value);
}
public bool EnableSkipVersionOnLaunch
{
get => _enableSkipVersionOnLaunch;
set => SetProperty(ref _enableSkipVersionOnLaunch, value);
}
public override void OnDialogOpened(IDialogParameters parameters)
{
var release = parameters.GetValue<GitHubRelease>("release");
EnableSkipVersionOnLaunch = parameters.GetValue<bool>("enableSkipVersion");
MarkdownText = release.Body;
TagName = release.TagName;
NewVersion = release.TagName.TrimStart('v');
}
}
}