Profiles - Added workshop installing

This commit is contained in:
Robert committed 2023-08-26 20:47:48 +02:00
1 parent 4143cc2de8
commit 671c587df6
21 files changed
+401 -73

No files matched your search

@@ -86,29 +86,36 @@
<StackPanel>
<TextBlock Theme="{StaticResource SubtitleTextBlockStyle}">Latest release</TextBlock>
<Border Classes="card-separator" />
<Button CornerRadius="8"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch">
<Button CornerRadius="8"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
Command="{CompiledBinding DownloadLatestRelease}">
<Grid ColumnDefinitions="Auto,*">
<!-- Icon -->
<Border Grid.Column="0"
CornerRadius="8"
CornerRadius="4"
Background="{StaticResource SystemAccentColor}"
VerticalAlignment="Center"
Margin="0 6"
Width="45"
Height="45"
Width="50"
Height="50"
ClipToBounds="True">
<avalonia:MaterialIcon Kind="Download"></avalonia:MaterialIcon>
</Border>
<!-- Body -->
<StackPanel Grid.Column="1" Margin="10 6">
<StackPanel Grid.Column="1" Margin="10 0" VerticalAlignment="Center">
<TextBlock Text="{CompiledBinding Entry.LatestRelease.Version, FallbackValue=Version}"></TextBlock>
<TextBlock Classes="subtitle">
<avalonia:MaterialIcon Kind="BoxOutline" />
<Run Text="{CompiledBinding Entry.LatestRelease.DownloadSize, Converter={StaticResource BytesToStringConverter}, Mode=OneWay}"></Run>
</TextBlock>
<TextBlock Classes="subtitle"
ToolTip.Tip="{CompiledBinding Entry.LatestRelease.CreatedAt, Converter={StaticResource DateTimeConverter}}">
<avalonia:MaterialIcon Kind="Calendar" />
<Run>Created</Run>
<Run Text="{CompiledBinding Entry.LatestRelease.CreatedAt, Converter={StaticResource DateTimeConverter}, ConverterParameter='humanize'}"></Run>
</TextBlock>
</StackPanel>
</Grid>
</Button>
@@ -1,11 +1,18 @@
using System;
using System.Reactive;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
using Artemis.Core;
using Artemis.UI.Screens.Workshop.Parameters;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Routing;
using Artemis.UI.Shared.Services;
using Artemis.UI.Shared.Services.Builders;
using Artemis.UI.Shared.Utilities;
using Artemis.WebClient.Workshop;
using Artemis.WebClient.Workshop.DownloadHandlers;
using Artemis.WebClient.Workshop.DownloadHandlers.Implementations;
using ReactiveUI;
using StrawberryShake;
@@ -14,18 +21,24 @@ namespace Artemis.UI.Screens.Workshop.Profile;
public class ProfileDetailsViewModel : RoutableScreen<ActivatableViewModelBase, WorkshopDetailParameters>, IWorkshopViewModel
{
private readonly IWorkshopClient _client;
private readonly ProfileEntryDownloadHandler _downloadHandler;
private readonly INotificationService _notificationService;
private readonly ObservableAsPropertyHelper<DateTimeOffset?> _updatedAt;
private IGetEntryById_Entry? _entry;
public ProfileDetailsViewModel(IWorkshopClient client)
public ProfileDetailsViewModel(IWorkshopClient client, ProfileEntryDownloadHandler downloadHandler, INotificationService notificationService)
{
_client = client;
_downloadHandler = downloadHandler;
_notificationService = notificationService;
_updatedAt = this.WhenAnyValue(vm => vm.Entry).Select(e => e?.LatestRelease?.CreatedAt ?? e?.CreatedAt).ToProperty(this, vm => vm.UpdatedAt);
DownloadLatestRelease = ReactiveCommand.CreateFromTask(ExecuteDownloadLatestRelease);
}
public DateTimeOffset? UpdatedAt => _updatedAt.Value;
public ReactiveCommand<Unit, Unit> DownloadLatestRelease { get; }
public EntryType? EntryType => null;
public DateTimeOffset? UpdatedAt => _updatedAt.Value;
public IGetEntryById_Entry? Entry
{
@@ -43,7 +56,21 @@ public class ProfileDetailsViewModel : RoutableScreen<ActivatableViewModelBase,
IOperationResult<IGetEntryByIdResult> result = await _client.GetEntryById.ExecuteAsync(entryId, cancellationToken);
if (result.IsErrorResult())
return;
Entry = result.Data?.Entry;
}
private async Task ExecuteDownloadLatestRelease(CancellationToken cancellationToken)
{
if (Entry?.LatestRelease == null)
return;
EntryInstallResult<ProfileConfiguration> result = await _downloadHandler.InstallProfileAsync(Entry.LatestRelease.Id, new Progress<StreamProgress>(), cancellationToken);
if (result.IsSuccess)
_notificationService.CreateNotification().WithTitle("Profile installed").WithSeverity(NotificationSeverity.Success).Show();
else
_notificationService.CreateNotification().WithTitle("Failed to install profile").WithMessage(result.Message).WithSeverity(NotificationSeverity.Error).Show();
}
public EntryType? EntryType => null;
}