Files
better-genshin-impact/BetterGenshinImpact/View/Windows/CheckUpdateWindow.xaml.cs
2025-01-13 01:17:11 +08:00

96 lines
2.1 KiB
C#

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.ComponentModel;
using System.Threading.Tasks;
using Wpf.Ui.Controls;
namespace BetterGenshinImpact.View.Windows;
[ObservableObject]
public partial class CheckUpdateWindow : FluentWindow
{
public Func<object, CheckUpdateWindowButton, Task>? UserInteraction = null!;
[ObservableProperty]
private bool showUpdateStatus = false;
[ObservableProperty]
private string updateStatusMessage = string.Empty;
public CheckUpdateWindow()
{
DataContext = this;
InitializeComponent();
Closing += OnClosing;
}
protected void OnClosing(object? sender, CancelEventArgs e)
{
if (ShowUpdateStatus)
{
e.Cancel = true;
}
}
public void NavigateToHtml(string html)
{
WebpagePanel?.NavigateToHtml(html);
}
[RelayCommand]
private async Task BackgroundUpdateAsync()
{
if (UserInteraction != null)
{
await UserInteraction.Invoke(this, CheckUpdateWindowButton.BackgroundUpdate);
}
}
[RelayCommand]
private async Task OtherUpdateAsync()
{
if (UserInteraction != null)
{
await UserInteraction.Invoke(this, CheckUpdateWindowButton.OtherUpdate);
}
}
[RelayCommand]
private async Task UpdateAsync()
{
if (UserInteraction != null)
{
await UserInteraction.Invoke(this, CheckUpdateWindowButton.Update);
}
}
[RelayCommand]
private async Task IgnoreAsync()
{
if (UserInteraction != null)
{
await UserInteraction.Invoke(this, CheckUpdateWindowButton.Ignore);
}
}
[RelayCommand]
private async Task CancelAsync()
{
if (UserInteraction != null)
{
await UserInteraction.Invoke(this, CheckUpdateWindowButton.Cancel);
}
}
public enum CheckUpdateWindowButton
{
BackgroundUpdate,
OtherUpdate,
Update,
Ignore,
Cancel,
}
}