current/latest badges

This commit is contained in:
Asval 2024-09-29 01:52:41 +02:00
parent fdf3deed76
commit ddee7c1479
6 changed files with 91 additions and 4 deletions

View File

@ -5,6 +5,7 @@ using CUE4Parse.UE4.Versions;
using FModel.Creator;
using FModel.Extensions;
using FModel.Framework;
using FModel.Settings;
using SkiaSharp;
using J = Newtonsoft.Json.JsonPropertyAttribute;
@ -15,12 +16,20 @@ public class GitHubRelease
[J("assets")] public GitHubAsset[] Assets { get; private set; }
}
public class GitHubAsset
public class GitHubAsset : ViewModel
{
[J("name")] public string Name { get; private set; }
[J("size")] public int Size { get; private set; }
[J("download_count")] public int DownloadCount { get; private set; }
[J("browser_download_url")] public string BrowserDownloadUrl { get; private set; }
[J("created_at")] public DateTime CreatedAt { get; private set; }
private bool _isLatest;
public bool IsLatest
{
get => _isLatest;
set => SetProperty(ref _isLatest, value);
}
}
public class GitHubCommit : ViewModel
@ -40,6 +49,8 @@ public class GitHubCommit : ViewModel
}
}
public bool IsCurrent => Sha == UserSettings.Default.CommitHash;
public string ShortSha => Sha[..7];
public bool IsDownloadable => Asset != null;
}

View File

@ -45,6 +45,8 @@ public class UpdateViewModel : ViewModel
#else
var qa = await _apiEndpointView.FModelApi.GetGitHubReleaseAsync("qa");
#endif
qa.Assets.OrderByDescending(x => x.CreatedAt).First().IsLatest = true;
foreach (var asset in qa.Assets)
{
var commitSha = asset.Name.SubstringBeforeLast(".zip");

View File

@ -65,7 +65,7 @@
</Grid>
</Grid>
<controls:CommitDownloaderControl Grid.Column="1" CommitAsset="{Binding Asset}">
<controls:CommitDownloaderControl Grid.Column="1" CommitAsset="{Binding Asset}" IsCurrent="{Binding IsCurrent}">
<controls:CommitDownloaderControl.Style>
<Style TargetType="controls:CommitDownloaderControl">
<Setter Property="Visibility" Value="Collapsed" />

View File

@ -15,9 +15,49 @@
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="15" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="15" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center">
<Border Grid.Column="0"
BorderThickness="1"
CornerRadius="2.5"
Padding="5,2"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<TextBlock FontSize="9" Foreground="{Binding BorderBrush, RelativeSource={RelativeSource AncestorType=Border}}">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding IsCurrent}" Value="True">
<Setter Property="Text" Value="Current" />
</DataTrigger>
<DataTrigger Binding="{Binding CommitAsset.IsLatest, RelativeSource={RelativeSource AncestorType=UserControl}}" Value="True">
<Setter Property="Text" Value="Latest" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
<Border.Style>
<Style TargetType="Border">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsCurrent}" Value="True">
<Setter Property="Visibility" Value="Visible" />
<Setter Property="BorderBrush" Value="#3f92b9" />
</DataTrigger>
<DataTrigger Binding="{Binding CommitAsset.IsLatest, RelativeSource={RelativeSource AncestorType=UserControl}}" Value="True">
<Setter Property="Visibility" Value="Visible" />
<Setter Property="BorderBrush" Value="#3fb950" />
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
</Border>
<Grid Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="5" />
@ -36,9 +76,10 @@
</StackPanel>
</Grid>
<Button Grid.Column="2" Style="{DynamicResource {x:Static adonisUi:Styles.ToolbarButton}}" ToolTip="Download"
<Button Grid.Column="4" Style="{DynamicResource {x:Static adonisUi:Styles.ToolbarButton}}" ToolTip="Download"
Height="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType=Grid}}"
Width="{Binding ActualHeight, RelativeSource={RelativeSource Self}}"
IsEnabled="{Binding IsCurrent, Converter={x:Static converters:InvertBooleanConverter.Instance}}"
Click="OnDownload">
<Viewbox Width="16" Height="16" VerticalAlignment="Center" HorizontalAlignment="Center">
<Canvas Width="16" Height="16">

View File

@ -21,6 +21,15 @@ public partial class CommitDownloaderControl : UserControl
set { SetValue(CommitAssetProperty, value); }
}
public static readonly DependencyProperty IsCurrentProperty =
DependencyProperty.Register("IsCurrent", typeof(bool), typeof(CommitDownloaderControl), new PropertyMetadata(null));
public bool IsCurrent
{
get { return (bool)GetValue(IsCurrentProperty); }
set { SetValue(IsCurrentProperty, value); }
}
private void OnDownload(object sender, RoutedEventArgs e)
{
AutoUpdater.DownloadUpdate(new UpdateInfoEventArgs { DownloadURL = CommitAsset.BrowserDownloadUrl });

View File

@ -0,0 +1,24 @@
using System;
using System.Globalization;
using System.Windows.Data;
namespace FModel.Views.Resources.Converters;
public class InvertBooleanConverter : IValueConverter
{
public static readonly InvertBooleanConverter Instance = new();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool boolean)
{
return !boolean;
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}