97 lines
2.9 KiB
C#
97 lines
2.9 KiB
C#
using System;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Markup.Xaml;
|
|
using StreamPlayer.Desktop.Models;
|
|
|
|
namespace StreamPlayer.Desktop.Views;
|
|
|
|
public enum UpdateDialogAction
|
|
{
|
|
Skip,
|
|
Download,
|
|
ViewRelease,
|
|
Exit
|
|
}
|
|
|
|
public partial class UpdateDialog : Window
|
|
{
|
|
private readonly UpdateInfo _info;
|
|
private readonly bool _mandatory;
|
|
|
|
private TextBlock? _titleText;
|
|
private TextBlock? _infoText;
|
|
private TextBlock? _notesText;
|
|
private Button? _viewReleaseButton;
|
|
private Button? _dismissButton;
|
|
|
|
public UpdateDialog() : this(
|
|
new UpdateInfo(AppVersion.VersionCode, AppVersion.VersionName, string.Empty, string.Empty, string.Empty, 0, 0, string.Empty, AppVersion.VersionCode, false),
|
|
false)
|
|
{
|
|
}
|
|
|
|
public UpdateDialog(UpdateInfo info, bool mandatory)
|
|
{
|
|
_info = info;
|
|
_mandatory = mandatory;
|
|
InitializeComponent();
|
|
ConfigureView();
|
|
}
|
|
|
|
private void ConfigureView()
|
|
{
|
|
if (_titleText != null)
|
|
{
|
|
_titleText.Text = _mandatory ? "Actualización obligatoria" : "Actualización disponible";
|
|
}
|
|
if (_infoText != null)
|
|
{
|
|
_infoText.Text =
|
|
$"Versión instalada: {AppVersion.VersionName} ({AppVersion.VersionCode}){Environment.NewLine}" +
|
|
$"Última versión: {_info.VersionName} ({_info.VersionCode}){Environment.NewLine}" +
|
|
$"Tamaño estimado: {_info.FormatSize()} Descargas: {_info.DownloadCount}";
|
|
}
|
|
|
|
if (_notesText != null)
|
|
{
|
|
_notesText.Text = string.IsNullOrWhiteSpace(_info.ReleaseNotes)
|
|
? "La release no incluye notas."
|
|
: _info.ReleaseNotes;
|
|
}
|
|
|
|
if (_viewReleaseButton != null && string.IsNullOrWhiteSpace(_info.ReleasePageUrl))
|
|
{
|
|
_viewReleaseButton.IsVisible = false;
|
|
}
|
|
if (_mandatory && _dismissButton != null)
|
|
{
|
|
_dismissButton.Content = "Salir";
|
|
}
|
|
}
|
|
|
|
private void OnDownloadClicked(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
|
{
|
|
Close(UpdateDialogAction.Download);
|
|
}
|
|
|
|
private void OnViewReleaseClicked(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
|
{
|
|
Close(UpdateDialogAction.ViewRelease);
|
|
}
|
|
|
|
private void OnDismissClicked(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
|
{
|
|
Close(_mandatory ? UpdateDialogAction.Exit : UpdateDialogAction.Skip);
|
|
}
|
|
|
|
private void InitializeComponent()
|
|
{
|
|
AvaloniaXamlLoader.Load(this);
|
|
_titleText = this.FindControl<TextBlock>("TitleText");
|
|
_infoText = this.FindControl<TextBlock>("InfoText");
|
|
_notesText = this.FindControl<TextBlock>("NotesText");
|
|
_viewReleaseButton = this.FindControl<Button>("ViewReleaseButton");
|
|
_dismissButton = this.FindControl<Button>("DismissButton");
|
|
}
|
|
}
|