Add About dialog

This commit is contained in:
MBucari 2023-04-02 11:29:28 -06:00
parent 4a65d6bbd3
commit 8d73f5cc7e
14 changed files with 466 additions and 16 deletions

View file

@ -2,12 +2,65 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="550" d:DesignHeight="450"
MinWidth="550" MinHeight="450"
Width="650" Height="500"
mc:Ignorable="d" d:DesignWidth="450" d:DesignHeight="600"
MinWidth="450" MinHeight="550"
Width="450" Height="600"
x:Class="LibationAvalonia.Dialogs.AboutDialog"
xmlns:controls="clr-namespace:LibationAvalonia.Controls"
Title="About Libation"
Icon="/Assets/libation.ico">
Welcome to Avalonia!
<Grid Margin="10" ColumnDefinitions="Auto,*" RowDefinitions="Auto,Auto,Auto,Auto,*">
<TextBlock Grid.ColumnSpan="2" FontSize="18" FontWeight="Bold" Text="{Binding Version}" />
<controls:LinkLabel Grid.Column="1" FontSize="16" VerticalAlignment="Center" HorizontalAlignment="Right" Text="Release Notes" Tapped="ViewReleaseNotes_Tapped"/>
<Button Grid.Row="1" Grid.ColumnSpan="2" HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" Margin="0,20,0,0" IsEnabled="{Binding CanCheckForUpgrade}" Content="{Binding UpgradeButtonText}" Click="CheckForUpgrade_Click" />
<Canvas Grid.Row="2" Grid.ColumnSpan="2" Margin="0,30" Width="345" Height="280">
<Path Stretch="None" Fill="{DynamicResource IconFill}" Data="{DynamicResource LibationCheersIcon}">
<Path.RenderTransform>
<TransformGroup>
<RotateTransform Angle="12" />
<ScaleTransform ScaleX="0.5" ScaleY="0.5" />
<TranslateTransform X="-150" Y="-120" />
</TransformGroup>
</Path.RenderTransform>
</Path>
<Path Stretch="None" Fill="{DynamicResource IconFill}" Data="{DynamicResource LibationCheersIcon}">
<Path.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="-1" ScaleY="1" />
<RotateTransform Angle="-12" />
<ScaleTransform ScaleX="0.5" ScaleY="0.5" />
<TranslateTransform X="78" Y="-120" />
</TransformGroup>
</Path.RenderTransform>
</Path>
</Canvas>
<TextBlock Grid.Row="3" VerticalAlignment="Center" FontSize="16" FontWeight="Bold" Text="Loaded Assemblies"/>
<Button Grid.Row="3" Grid.Column="1" HorizontalAlignment="Right" Padding="10,0" Content="Copy to Clopboard" Command="{Binding CopyAssembliesAsync}"/>
<ListBox Grid.Row="4" Grid.ColumnSpan="2" Margin="0,10,0,0" ItemsSource="{Binding Assemblies}">
<ListBox.Styles>
<Style Selector="ListBoxItem" >
<Setter Property="Padding" Value="0" />
<Style Selector="^ > Grid > TextBlock" >
<Setter Property="FontSize" Value="11" />
</Style>
</Style>
</ListBox.Styles>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid ColumnDefinitions="*,Auto">
<TextBlock Text="{Binding Name}" />
<TextBlock Grid.Column="1" Text="{Binding Version}" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Window>

View file

@ -1,12 +1,78 @@
using Avalonia.Collections;
using Avalonia.Controls;
using LibationAvalonia.ViewModels;
using LibationFileManager;
using LibationUiBase;
using ReactiveUI;
using System;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
namespace LibationAvalonia.Dialogs
{
public partial class AboutDialog : DialogWindow
{
public AboutDialog()
private readonly AboutVM _viewModel;
public AboutDialog() : base(saveAndRestorePosition:false)
{
if (Design.IsDesignMode)
_ = Configuration.Instance.LibationFiles;
InitializeComponent();
DataContext = _viewModel = new AboutVM();
}
private async void CheckForUpgrade_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
{
var mainWindow = Owner as Views.MainWindow;
var upgrader = new Upgrader();
upgrader.DownloadProgress += async (_, e) => await Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() => mainWindow.ViewModel.DownloadProgress = e.ProgressPercentage);
upgrader.DownloadCompleted += async (_, _) => await Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() => mainWindow.ViewModel.DownloadProgress = null);
_viewModel.CanCheckForUpgrade = false;
Version latestVersion = null;
await upgrader.CheckForUpgradeAsync(OnUpgradeAvailable);
_viewModel.CanCheckForUpgrade = latestVersion is null;
_viewModel.UpgradeButtonText = latestVersion is null ? "Libation is up to date. Check Again." : $"Version {latestVersion:3} is available";
async Task OnUpgradeAvailable(UpgradeEventArgs e)
{
var notificationResult = await new UpgradeNotificationDialog(e.UpgradeProperties, e.CapUpgrade).ShowDialogAsync(this);
e.Ignore = notificationResult == DialogResult.Ignore;
e.InstallUpgrade = notificationResult == DialogResult.OK;
latestVersion = e.UpgradeProperties.LatestRelease;
}
}
private void ViewReleaseNotes_Tapped(object sender, Avalonia.Input.TappedEventArgs e)
{
Dinah.Core.Go.To.Url($"{AppScaffolding.LibationScaffolding.RepositoryUrl}/releases/tag/v{AppScaffolding.LibationScaffolding.BuildVersion.ToString(3)}");
}
}
public class AboutVM : ViewModelBase
{
public string Version { get; }
public AvaloniaList<AssemblyName> Assemblies { get; } = new();
public bool CanCheckForUpgrade { get => canCheckForUpgrade; set => this.RaiseAndSetIfChanged(ref canCheckForUpgrade, value); }
public string UpgradeButtonText { get => upgradeButtonText; set => this.RaiseAndSetIfChanged(ref upgradeButtonText, value); }
private bool canCheckForUpgrade = true;
private string upgradeButtonText = "Check for Upgrade";
public AboutVM()
{
Version = $"Libation {AppScaffolding.LibationScaffolding.Variety} v{AppScaffolding.LibationScaffolding.BuildVersion}";
Assemblies.AddRange(AppDomain.CurrentDomain.GetAssemblies().Select(a => new AssemblyName(a.FullName)).Where(a => a.Version.Major + a.Version.Minor + a.Version.Build + a.Version.Revision > 0).OrderBy(a => a.Name));
}
public async Task CopyAssembliesAsync() => await App.Current.Clipboard.SetTextAsync(string.Join(Environment.NewLine, Assemblies.Select(a => $"{a.Name}\t{a.Version}")));
}
}