mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-05-21 09:45:48 +08:00
102 lines
2.3 KiB
C#
102 lines
2.3 KiB
C#
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using System;
|
|
using System.ComponentModel;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using BetterGenshinImpact.Model;
|
|
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(UpdateOption option)
|
|
{
|
|
DataContext = this;
|
|
InitializeComponent();
|
|
|
|
if (option.Trigger == UpdateTrigger.Manual)
|
|
{
|
|
IgnoreButton.Visibility = Visibility.Collapsed;
|
|
}
|
|
|
|
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,
|
|
}
|
|
} |