mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-12 13:28:33 +00:00
Workshop - Avoid crashes when auto-updating without internet
Workshop - Added vote based entry score system
This commit is contained in:
parent
7f5bb589af
commit
1e8c68bbeb
65
src/Artemis.UI/Screens/Workshop/Entries/EntryVoteView.axaml
Normal file
65
src/Artemis.UI/Screens/Workshop/Entries/EntryVoteView.axaml
Normal file
@ -0,0 +1,65 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
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"
|
||||
xmlns:entries="clr-namespace:Artemis.UI.Screens.Workshop.Entries"
|
||||
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Workshop.Entries.EntryVoteView"
|
||||
x:DataType="entries:EntryVoteViewModel">
|
||||
<UserControl.Styles>
|
||||
<Styles>
|
||||
<Style Selector="Button.vote-button avalonia|MaterialIcon">
|
||||
<Setter Property="Transitions">
|
||||
<Transitions>
|
||||
<BrushTransition Property="Foreground" Duration="0:0:0.2" Easing="CubicEaseOut" />
|
||||
</Transitions>
|
||||
</Setter>
|
||||
</Style>
|
||||
<Style Selector="Button.vote-button.upvote:pointerover avalonia|MaterialIcon">
|
||||
<Setter Property="Foreground" Value="#F57634"></Setter>
|
||||
</Style>
|
||||
<Style Selector="Button.vote-button.downvote:pointerover avalonia|MaterialIcon">
|
||||
<Setter Property="Foreground" Value="#7193FF"></Setter>
|
||||
</Style>
|
||||
|
||||
<Style Selector="TextBlock.upvoted">
|
||||
<Setter Property="Foreground" Value="#F57634"></Setter>
|
||||
</Style>
|
||||
<Style Selector="TextBlock.downvoted">
|
||||
<Setter Property="Foreground" Value="#7193FF"></Setter>
|
||||
</Style>
|
||||
</Styles>
|
||||
</UserControl.Styles>
|
||||
|
||||
<!-- Voting -->
|
||||
<StackPanel Spacing="4" VerticalAlignment="Center">
|
||||
<Button IsEnabled="{CompiledBinding IsLoggedIn^}"
|
||||
HorizontalAlignment="Stretch"
|
||||
Theme="{StaticResource TransparentButton}"
|
||||
Classes="vote-button upvote"
|
||||
Command="{CompiledBinding CastVote}"
|
||||
CommandParameter="{x:True}">
|
||||
<Panel>
|
||||
<avalonia:MaterialIcon Kind="ArrowUp" IsVisible="{CompiledBinding !Upvoted}" />
|
||||
<avalonia:MaterialIcon Kind="ArrowUpThick" IsVisible="{CompiledBinding Upvoted}" Foreground="#F57634" />
|
||||
</Panel>
|
||||
</Button>
|
||||
<TextBlock Text="{CompiledBinding Score, FallbackValue=0}"
|
||||
HorizontalAlignment="Stretch"
|
||||
TextAlignment="Center"
|
||||
Classes.upvoted="{CompiledBinding Upvoted}"
|
||||
Classes.downvoted="{CompiledBinding Downvoted}" />
|
||||
<Button IsEnabled="{CompiledBinding IsLoggedIn^}"
|
||||
HorizontalAlignment="Stretch"
|
||||
Theme="{StaticResource TransparentButton}"
|
||||
Classes="vote-button downvote"
|
||||
Command="{CompiledBinding CastVote}"
|
||||
CommandParameter="{x:False}">
|
||||
<Panel>
|
||||
<avalonia:MaterialIcon Kind="ArrowDown" IsVisible="{CompiledBinding !Downvoted}" />
|
||||
<avalonia:MaterialIcon Kind="ArrowDownThick" IsVisible="{CompiledBinding Downvoted}" Foreground="#7193FF" />
|
||||
</Panel>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@ -0,0 +1,14 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.Entries;
|
||||
|
||||
public partial class EntryVoteView : ReactiveUserControl<EntryVoteViewModel>
|
||||
{
|
||||
public EntryVoteView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Artemis.UI.Shared.Services.Builders;
|
||||
using Artemis.WebClient.Workshop;
|
||||
using Artemis.WebClient.Workshop.Services;
|
||||
using PropertyChanged.SourceGenerator;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.Entries;
|
||||
|
||||
public partial class EntryVoteViewModel : ActivatableViewModelBase
|
||||
{
|
||||
private readonly IEntrySummary _entry;
|
||||
private readonly INotificationService _notificationService;
|
||||
private readonly IVoteClient _voteClient;
|
||||
private bool _voting;
|
||||
|
||||
[Notify] private int _score;
|
||||
[Notify] private bool _upvoted;
|
||||
[Notify] private bool _downvoted;
|
||||
|
||||
public EntryVoteViewModel(IEntrySummary entry, IAuthenticationService authenticationService, INotificationService notificationService, IVoteClient voteClient)
|
||||
{
|
||||
_entry = entry;
|
||||
_notificationService = notificationService;
|
||||
_voteClient = voteClient;
|
||||
|
||||
IsLoggedIn = authenticationService.IsLoggedIn;
|
||||
Score = entry.UpvoteCount - entry.DownvoteCount;
|
||||
this.WhenActivated(d => IsLoggedIn.Subscribe(l => _ = GetVoteStatus(l)).DisposeWith(d));
|
||||
}
|
||||
|
||||
public IObservable<bool> IsLoggedIn { get; }
|
||||
|
||||
public async Task CastVote(bool upvote)
|
||||
{
|
||||
// Could use a ReactiveCommand to achieve the same thing but that disables the button
|
||||
// while executing which grays it out for a fraction of a second and looks bad
|
||||
if (_voting)
|
||||
return;
|
||||
|
||||
_voting = true;
|
||||
try
|
||||
{
|
||||
IVoteCount? result;
|
||||
// If the vote was removed, reset the upvote/downvote state
|
||||
if ((Upvoted && upvote) || (Downvoted && !upvote))
|
||||
{
|
||||
result = await _voteClient.ClearVote(_entry.Id);
|
||||
Upvoted = false;
|
||||
Downvoted = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await _voteClient.CastVote(_entry.Id, upvote);
|
||||
Upvoted = upvote;
|
||||
Downvoted = !upvote;
|
||||
}
|
||||
|
||||
if (result != null)
|
||||
Score = result.UpvoteCount - result.DownvoteCount;
|
||||
else
|
||||
_notificationService.CreateNotification().WithTitle("Failed to cast vote").WithMessage("Please try again later.").WithSeverity(NotificationSeverity.Error).Show();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_voting = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task GetVoteStatus(bool isLoggedIn)
|
||||
{
|
||||
if (!isLoggedIn)
|
||||
{
|
||||
Upvoted = false;
|
||||
Downvoted = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool? vote = await _voteClient.GetVote(_entry.Id);
|
||||
if (vote != null)
|
||||
{
|
||||
Upvoted = vote.Value;
|
||||
Downvoted = !vote.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -21,6 +21,7 @@
|
||||
<ComboBoxItem>Recently updated</ComboBoxItem>
|
||||
<ComboBoxItem>Recently added</ComboBoxItem>
|
||||
<ComboBoxItem>Download count</ComboBoxItem>
|
||||
<ComboBoxItem>Score</ComboBoxItem>
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
<TextBlock Grid.Column="3" VerticalAlignment="Center" Margin="5 0 0 0" MinWidth="75" TextAlignment="Right">
|
||||
|
||||
@ -21,9 +21,12 @@
|
||||
HorizontalContentAlignment="Stretch"
|
||||
Command="{CompiledBinding NavigateToEntry}"
|
||||
IsVisible="{CompiledBinding Entry, Converter={x:Static ObjectConverters.IsNotNull}}">
|
||||
<Grid ColumnDefinitions="Auto,*,Auto" RowDefinitions="*, Auto">
|
||||
<Grid ColumnDefinitions="Auto, Auto,*,Auto" RowDefinitions="*, Auto">
|
||||
<!-- Score -->
|
||||
<ContentControl Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" Width="40" Margin="0 0 10 0" Content="{CompiledBinding VoteViewModel}"/>
|
||||
|
||||
<!-- Icon -->
|
||||
<Border Grid.Column="0"
|
||||
<Border Grid.Column="1"
|
||||
Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
CornerRadius="6"
|
||||
@ -36,7 +39,7 @@
|
||||
</Border>
|
||||
|
||||
<!-- Body -->
|
||||
<Grid Grid.Column="1" Grid.Row="0" Grid.RowSpan="2" VerticalAlignment="Stretch" RowDefinitions="Auto,*,Auto">
|
||||
<Grid Grid.Column="2" Grid.Row="0" Grid.RowSpan="2" VerticalAlignment="Stretch" RowDefinitions="Auto,*,Auto">
|
||||
<StackPanel Grid.Row="0" Orientation="Horizontal">
|
||||
<TextBlock Margin="0 0 0 5" TextTrimming="CharacterEllipsis">
|
||||
<Run Classes="h5" Text="{CompiledBinding Entry.Name, FallbackValue=Title}" />
|
||||
@ -79,7 +82,7 @@
|
||||
</Grid>
|
||||
|
||||
<!-- Info -->
|
||||
<StackPanel Grid.Column="2" Grid.Row="0" Margin="0 0 4 0" HorizontalAlignment="Right">
|
||||
<StackPanel Grid.Column="3" Grid.Row="0" Margin="0 0 4 0" HorizontalAlignment="Right">
|
||||
<TextBlock TextAlignment="Right" Text="{CompiledBinding Entry.CreatedAt, FallbackValue=01-01-1337, Converter={StaticResource DateTimeConverter}}" />
|
||||
<TextBlock TextAlignment="Right">
|
||||
<avalonia:MaterialIcon Kind="Downloads" />
|
||||
@ -89,7 +92,7 @@
|
||||
</StackPanel>
|
||||
|
||||
<!-- Install state -->
|
||||
<StackPanel Grid.Column="2" Grid.Row="1" Margin="0 0 4 0" HorizontalAlignment="Right" VerticalAlignment="Bottom" IsVisible="{CompiledBinding IsInstalled}">
|
||||
<StackPanel Grid.Column="3" Grid.Row="1" Margin="0 0 4 0" HorizontalAlignment="Right" VerticalAlignment="Bottom" IsVisible="{CompiledBinding IsInstalled}">
|
||||
<TextBlock TextAlignment="Right" IsVisible="{CompiledBinding !UpdateAvailable}">
|
||||
<avalonia:MaterialIcon Kind="CheckCircle" Foreground="{DynamicResource SystemAccentColorLight1}" Width="20" Height="20" />
|
||||
<Run>installed</Run>
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.UI.Shared;
|
||||
@ -18,12 +17,12 @@ public partial class EntryListItemViewModel : ActivatableViewModelBase
|
||||
[Notify] private bool _isInstalled;
|
||||
[Notify] private bool _updateAvailable;
|
||||
|
||||
public EntryListItemViewModel(IEntrySummary entry, IRouter router, IWorkshopService workshopService)
|
||||
public EntryListItemViewModel(IEntrySummary entry, IRouter router, IWorkshopService workshopService, Func<IEntrySummary, EntryVoteViewModel> getEntryVoteViewModel)
|
||||
{
|
||||
_router = router;
|
||||
|
||||
Entry = entry;
|
||||
NavigateToEntry = ReactiveCommand.CreateFromTask(ExecuteNavigateToEntry);
|
||||
VoteViewModel = getEntryVoteViewModel(entry);
|
||||
|
||||
this.WhenActivated((CompositeDisposable _) =>
|
||||
{
|
||||
@ -34,9 +33,9 @@ public partial class EntryListItemViewModel : ActivatableViewModelBase
|
||||
}
|
||||
|
||||
public IEntrySummary Entry { get; }
|
||||
public ReactiveCommand<Unit, Unit> NavigateToEntry { get; }
|
||||
public EntryVoteViewModel VoteViewModel { get; }
|
||||
|
||||
private async Task ExecuteNavigateToEntry()
|
||||
public async Task NavigateToEntry()
|
||||
{
|
||||
switch (Entry.EntryType)
|
||||
{
|
||||
|
||||
@ -137,6 +137,9 @@ public partial class EntryListViewModel : RoutableScreen
|
||||
if (InputViewModel.SortBy == 2)
|
||||
return new[] {new EntrySortInput {Downloads = SortEnumType.Desc}};
|
||||
|
||||
// Sort by score
|
||||
if (InputViewModel.SortBy == 3)
|
||||
return new[] {new EntrySortInput {Score = SortEnumType.Desc}};
|
||||
|
||||
// Sort by latest release, then by created at
|
||||
return new[]
|
||||
|
||||
@ -11,7 +11,6 @@
|
||||
x:DataType="tabs:InstalledTabItemViewModel">
|
||||
<UserControl.Resources>
|
||||
<converters:EntryIconUriConverter x:Key="EntryIconUriConverter" />
|
||||
<converters:DateTimeConverter x:Key="DateTimeConverter" />
|
||||
</UserControl.Resources>
|
||||
<Button MinHeight="110"
|
||||
MaxHeight="140"
|
||||
@ -19,9 +18,12 @@
|
||||
HorizontalAlignment="Stretch"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
Command="{CompiledBinding ViewWorkshopPage}">
|
||||
<Grid ColumnDefinitions="Auto,*,Auto,Auto" RowDefinitions="*, Auto">
|
||||
<Grid ColumnDefinitions="Auto,Auto,*,Auto,Auto" RowDefinitions="*, Auto">
|
||||
<!-- Score -->
|
||||
<ContentControl Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" Width="40" Margin="0 0 10 0" Content="{CompiledBinding VoteViewModel}"/>
|
||||
|
||||
<!-- Icon -->
|
||||
<Border Grid.Column="0"
|
||||
<Border Grid.Column="1"
|
||||
Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
CornerRadius="6"
|
||||
@ -34,7 +36,7 @@
|
||||
</Border>
|
||||
|
||||
<!-- Body -->
|
||||
<Grid Grid.Column="1" Grid.Row="0" Grid.RowSpan="2" VerticalAlignment="Stretch" RowDefinitions="Auto,*,Auto">
|
||||
<Grid Grid.Column="2" Grid.Row="0" Grid.RowSpan="2" VerticalAlignment="Stretch" RowDefinitions="Auto,*,Auto">
|
||||
<StackPanel Grid.Row="0" Orientation="Horizontal">
|
||||
<TextBlock Margin="0 0 0 5" TextTrimming="CharacterEllipsis">
|
||||
<Run Classes="h5" Text="{CompiledBinding Entry.Name, FallbackValue=Title}" />
|
||||
@ -76,7 +78,7 @@
|
||||
</Grid>
|
||||
|
||||
<!-- Info -->
|
||||
<StackPanel Grid.Column="2" Grid.Row="0" Margin="0 0 4 0" HorizontalAlignment="Right">
|
||||
<StackPanel Grid.Column="3" Grid.Row="0" Margin="0 0 4 0" HorizontalAlignment="Right">
|
||||
<TextBlock TextAlignment="Right">
|
||||
<avalonia:MaterialIcon Kind="Harddisk" />
|
||||
<Run Text="{CompiledBinding Entry.ReleaseVersion}" />
|
||||
@ -84,7 +86,7 @@
|
||||
</StackPanel>
|
||||
|
||||
<!-- Install state -->
|
||||
<StackPanel Grid.Column="2" Grid.Row="1" Margin="0 0 4 0" HorizontalAlignment="Right" VerticalAlignment="Bottom">
|
||||
<StackPanel Grid.Column="3" Grid.Row="1" Margin="0 0 4 0" HorizontalAlignment="Right" VerticalAlignment="Bottom">
|
||||
<TextBlock TextAlignment="Right" IsVisible="{CompiledBinding UpdateAvailable}">
|
||||
<avalonia:MaterialIcon Kind="Update" Foreground="{DynamicResource SystemAccentColorLight1}" Width="20" Height="20" />
|
||||
<Run>update available</Run>
|
||||
@ -92,7 +94,7 @@
|
||||
</StackPanel>
|
||||
|
||||
<!-- Management -->
|
||||
<Border Grid.Column="3" Grid.Row="0" Grid.RowSpan="2" BorderBrush="{DynamicResource ButtonBorderBrush}" BorderThickness="1 0 0 0" Margin="10 0 0 0" Padding="10 0 0 0">
|
||||
<Border Grid.Column="4" Grid.Row="0" Grid.RowSpan="2" BorderBrush="{DynamicResource ButtonBorderBrush}" BorderThickness="1 0 0 0" Margin="10 0 0 0" Padding="10 0 0 0">
|
||||
<StackPanel VerticalAlignment="Center">
|
||||
<StackPanel Orientation="Horizontal" Spacing="5">
|
||||
<Button Command="{CompiledBinding ViewLocal}" HorizontalAlignment="Stretch" >Open</Button>
|
||||
|
||||
@ -10,6 +10,7 @@ using Artemis.Core.Services;
|
||||
using Artemis.UI.DryIoc.Factories;
|
||||
using Artemis.UI.Extensions;
|
||||
using Artemis.UI.Screens.Plugins;
|
||||
using Artemis.UI.Screens.Workshop.Entries;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Routing;
|
||||
@ -35,6 +36,7 @@ public partial class InstalledTabItemViewModel : ActivatableViewModelBase
|
||||
|
||||
[Notify] private bool _updateAvailable;
|
||||
[Notify] private bool _autoUpdate;
|
||||
[Notify] private EntryVoteViewModel _voteViewModel;
|
||||
|
||||
public InstalledTabItemViewModel(InstalledEntry entry,
|
||||
IWorkshopClient client,
|
||||
@ -43,7 +45,8 @@ public partial class InstalledTabItemViewModel : ActivatableViewModelBase
|
||||
IRouter router,
|
||||
IWindowService windowService,
|
||||
IPluginManagementService pluginManagementService,
|
||||
ISettingsVmFactory settingsVmFactory)
|
||||
ISettingsVmFactory settingsVmFactory,
|
||||
Func<IEntrySummary, EntryVoteViewModel> getEntryVoteViewModel)
|
||||
{
|
||||
_client = client;
|
||||
_workshopService = workshopService;
|
||||
@ -53,9 +56,9 @@ public partial class InstalledTabItemViewModel : ActivatableViewModelBase
|
||||
_pluginManagementService = pluginManagementService;
|
||||
_settingsVmFactory = settingsVmFactory;
|
||||
_autoUpdate = entry.AutoUpdate;
|
||||
|
||||
Entry = entry;
|
||||
|
||||
Entry = entry;
|
||||
|
||||
this.WhenActivatedAsync(async _ =>
|
||||
{
|
||||
// Grab the latest entry summary from the workshop
|
||||
@ -65,6 +68,7 @@ public partial class InstalledTabItemViewModel : ActivatableViewModelBase
|
||||
if (entrySummary.Data?.Entry != null)
|
||||
{
|
||||
Entry.ApplyEntrySummary(entrySummary.Data.Entry);
|
||||
VoteViewModel = getEntryVoteViewModel(entrySummary.Data.Entry);
|
||||
_workshopService.SaveInstalledEntry(Entry);
|
||||
}
|
||||
}
|
||||
@ -73,7 +77,7 @@ public partial class InstalledTabItemViewModel : ActivatableViewModelBase
|
||||
UpdateAvailable = Entry.ReleaseId != Entry.LatestReleaseId;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
this.WhenAnyValue(vm => vm.AutoUpdate).Skip(1).Subscribe(_ => AutoUpdateToggled());
|
||||
}
|
||||
|
||||
@ -122,10 +126,10 @@ public partial class InstalledTabItemViewModel : ActivatableViewModelBase
|
||||
private void AutoUpdateToggled()
|
||||
{
|
||||
_workshopService.SetAutoUpdate(Entry, AutoUpdate);
|
||||
|
||||
|
||||
if (!AutoUpdate)
|
||||
return;
|
||||
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await _workshopUpdateService.AutoUpdateEntry(Entry);
|
||||
|
||||
@ -22,7 +22,8 @@ public class WorkshopUpdateService : IWorkshopUpdateService
|
||||
private readonly Lazy<IUpdateNotificationProvider> _updateNotificationProvider;
|
||||
private readonly PluginSetting<bool> _showNotifications;
|
||||
|
||||
public WorkshopUpdateService(ILogger logger, IWorkshopClient client, IWorkshopService workshopService, ISettingsService settingsService, Lazy<IUpdateNotificationProvider> updateNotificationProvider)
|
||||
public WorkshopUpdateService(ILogger logger, IWorkshopClient client, IWorkshopService workshopService, ISettingsService settingsService,
|
||||
Lazy<IUpdateNotificationProvider> updateNotificationProvider)
|
||||
{
|
||||
_logger = logger;
|
||||
_client = client;
|
||||
@ -56,20 +57,19 @@ public class WorkshopUpdateService : IWorkshopUpdateService
|
||||
|
||||
public async Task<bool> AutoUpdateEntry(InstalledEntry installedEntry)
|
||||
{
|
||||
// Query the latest version
|
||||
IOperationResult<IGetEntryLatestReleaseByIdResult> latestReleaseResult = await _client.GetEntryLatestReleaseById.ExecuteAsync(installedEntry.Id);
|
||||
IEntrySummary? entry = latestReleaseResult.Data?.Entry?.LatestRelease?.Entry;
|
||||
if (entry == null)
|
||||
return false;
|
||||
if (latestReleaseResult.Data?.Entry?.LatestRelease is not IRelease latestRelease)
|
||||
return false;
|
||||
if (latestRelease.Id == installedEntry.ReleaseId)
|
||||
return false;
|
||||
|
||||
_logger.Information("Auto-updating entry {Entry} to version {Version}", entry, latestRelease.Version);
|
||||
|
||||
try
|
||||
{
|
||||
// Query the latest version
|
||||
IOperationResult<IGetEntryLatestReleaseByIdResult> latestReleaseResult = await _client.GetEntryLatestReleaseById.ExecuteAsync(installedEntry.Id);
|
||||
IEntrySummary? entry = latestReleaseResult.Data?.Entry?.LatestRelease?.Entry;
|
||||
if (entry == null)
|
||||
return false;
|
||||
if (latestReleaseResult.Data?.Entry?.LatestRelease is not IRelease latestRelease)
|
||||
return false;
|
||||
if (latestRelease.Id == installedEntry.ReleaseId)
|
||||
return false;
|
||||
|
||||
_logger.Information("Auto-updating entry {Entry} to version {Version}", entry, latestRelease.Version);
|
||||
EntryInstallResult updateResult = await _workshopService.InstallEntry(entry, latestRelease, new Progress<StreamProgress>(), CancellationToken.None);
|
||||
|
||||
// This happens during installation too but not on our reference of the entry
|
||||
@ -85,7 +85,7 @@ public class WorkshopUpdateService : IWorkshopUpdateService
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Warning(e, "Auto-update failed for entry {Entry}", entry);
|
||||
_logger.Warning(e, "Auto-update failed for entry {Entry}", installedEntry);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@ -53,6 +53,7 @@ public static class ContainerExtensions
|
||||
container.Register<IAuthenticationRepository, AuthenticationRepository>(Reuse.Singleton);
|
||||
container.Register<IAuthenticationService, AuthenticationService>(Reuse.Singleton);
|
||||
container.Register<IWorkshopService, WorkshopService>(Reuse.Singleton);
|
||||
container.Register<IVoteClient, VoteClient>(Reuse.Singleton);
|
||||
container.Register<ILayoutProvider, WorkshopLayoutProvider>(Reuse.Singleton);
|
||||
container.Register<IUserManagementService, UserManagementService>();
|
||||
|
||||
|
||||
16
src/Artemis.WebClient.Workshop/Mutations/CastVote.graphql
Normal file
16
src/Artemis.WebClient.Workshop/Mutations/CastVote.graphql
Normal file
@ -0,0 +1,16 @@
|
||||
mutation CastVote($input: CastVoteInput!) {
|
||||
castVote(input: $input) {
|
||||
...voteCount
|
||||
}
|
||||
}
|
||||
|
||||
mutation ClearVote($entryId: Long!) {
|
||||
clearVote(entryId: $entryId) {
|
||||
...voteCount
|
||||
}
|
||||
}
|
||||
|
||||
fragment voteCount on Entry {
|
||||
upvoteCount
|
||||
downvoteCount
|
||||
}
|
||||
@ -2,4 +2,4 @@ mutation AddEntry ($input: CreateEntryInput!) {
|
||||
addEntry(input: $input) {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -36,6 +36,8 @@ fragment entrySummary on Entry {
|
||||
summary
|
||||
entryType
|
||||
downloads
|
||||
upvoteCount
|
||||
downvoteCount
|
||||
createdAt
|
||||
latestReleaseId
|
||||
categories {
|
||||
@ -51,6 +53,8 @@ fragment entryDetails on Entry {
|
||||
summary
|
||||
entryType
|
||||
downloads
|
||||
upvoteCount
|
||||
downvoteCount
|
||||
createdAt
|
||||
description
|
||||
categories {
|
||||
|
||||
6
src/Artemis.WebClient.Workshop/Queries/GetVotes.graphql
Normal file
6
src/Artemis.WebClient.Workshop/Queries/GetVotes.graphql
Normal file
@ -0,0 +1,6 @@
|
||||
query GetVotes {
|
||||
votes {
|
||||
entryId
|
||||
upvote
|
||||
}
|
||||
}
|
||||
105
src/Artemis.WebClient.Workshop/Services/VoteClient.cs
Normal file
105
src/Artemis.WebClient.Workshop/Services/VoteClient.cs
Normal file
@ -0,0 +1,105 @@
|
||||
using StrawberryShake;
|
||||
|
||||
namespace Artemis.WebClient.Workshop.Services;
|
||||
|
||||
public class VoteClient : IVoteClient
|
||||
{
|
||||
private readonly Dictionary<long, bool> _cache = new();
|
||||
private readonly IWorkshopClient _client;
|
||||
private readonly SemaphoreSlim _lock = new(1, 1);
|
||||
private DateTime _cacheAge = DateTime.MinValue;
|
||||
|
||||
public VoteClient(IWorkshopClient client, IAuthenticationService authenticationService)
|
||||
{
|
||||
_client = client;
|
||||
authenticationService.IsLoggedIn.Subscribe(_ => _cacheAge = DateTime.MinValue);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<bool?> GetVote(long entryId)
|
||||
{
|
||||
await _lock.WaitAsync();
|
||||
|
||||
try
|
||||
{
|
||||
if (_cacheAge < DateTime.UtcNow.AddMinutes(-15))
|
||||
{
|
||||
_cache.Clear();
|
||||
IOperationResult<IGetVotesResult> result = await _client.GetVotes.ExecuteAsync();
|
||||
if (result.Data?.Votes != null)
|
||||
foreach (IGetVotes_Votes vote in result.Data.Votes)
|
||||
_cache.Add(vote.EntryId, vote.Upvote);
|
||||
_cacheAge = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
return _cache.TryGetValue(entryId, out bool upvote) ? upvote : null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_lock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<IVoteCount?> CastVote(long entryId, bool upvote)
|
||||
{
|
||||
await _lock.WaitAsync();
|
||||
|
||||
try
|
||||
{
|
||||
IOperationResult<ICastVoteResult> result = await _client.CastVote.ExecuteAsync(new CastVoteInput {EntryId = entryId, Upvote = upvote});
|
||||
if (result.IsSuccessResult() && result.Data?.CastVote != null)
|
||||
_cache[entryId] = upvote;
|
||||
|
||||
return result.Data?.CastVote;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_lock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<IVoteCount?> ClearVote(long entryId)
|
||||
{
|
||||
await _lock.WaitAsync();
|
||||
|
||||
try
|
||||
{
|
||||
IOperationResult<IClearVoteResult> result = await _client.ClearVote.ExecuteAsync(entryId);
|
||||
if (result.IsSuccessResult() && result.Data?.ClearVote != null)
|
||||
_cache.Remove(entryId);
|
||||
|
||||
return result.Data?.ClearVote;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_lock.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface IVoteClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the vote status for a specific entry.
|
||||
/// </summary>
|
||||
/// <param name="entryId">The ID of the entry</param>
|
||||
/// <returns>A Task containing the vote status.</returns>
|
||||
Task<bool?> GetVote(long entryId);
|
||||
|
||||
/// <summary>
|
||||
/// Casts a vote for a specific entry.
|
||||
/// </summary>
|
||||
/// <param name="entryId">The ID of the entry.</param>
|
||||
/// <param name="upvote">A boolean indicating whether the vote is an upvote.</param>
|
||||
/// <returns>A Task containing the cast vote.</returns>
|
||||
Task<IVoteCount?> CastVote(long entryId, bool upvote);
|
||||
|
||||
/// <summary>
|
||||
/// Clears a vote for a specific entry.
|
||||
/// </summary>
|
||||
/// <param name="entryId">The ID of the entry</param>
|
||||
/// <returns>A Task containing the vote status.</returns>
|
||||
Task<IVoteCount?> ClearVote(long entryId);
|
||||
}
|
||||
@ -2,10 +2,10 @@ namespace Artemis.WebClient.Workshop;
|
||||
|
||||
public static class WorkshopConstants
|
||||
{
|
||||
// public const string AUTHORITY_URL = "https://localhost:5001";
|
||||
// public const string WORKSHOP_URL = "https://localhost:7281";
|
||||
public const string AUTHORITY_URL = "https://identity.artemis-rgb.com";
|
||||
public const string WORKSHOP_URL = "https://workshop.artemis-rgb.com";
|
||||
public const string AUTHORITY_URL = "https://localhost:5001";
|
||||
public const string WORKSHOP_URL = "https://localhost:7281";
|
||||
// public const string AUTHORITY_URL = "https://identity.artemis-rgb.com";
|
||||
// public const string WORKSHOP_URL = "https://workshop.artemis-rgb.com";
|
||||
public const string IDENTITY_CLIENT_NAME = "IdentityApiClient";
|
||||
public const string WORKSHOP_CLIENT_NAME = "WorkshopApiClient";
|
||||
}
|
||||
@ -2,7 +2,7 @@ schema: schema.graphql
|
||||
extensions:
|
||||
endpoints:
|
||||
Default GraphQL Endpoint:
|
||||
url: https://workshop.artemis-rgb.com/graphql
|
||||
url: https://localhost:7281/graphql/
|
||||
headers:
|
||||
user-agent: JS GraphQL
|
||||
introspect: true
|
||||
|
||||
@ -56,11 +56,13 @@ type Entry {
|
||||
dependantReleases: [Release!]!
|
||||
description: String!
|
||||
downloads: Long!
|
||||
downvoteCount: Int!
|
||||
entryType: EntryType!
|
||||
icon: Image
|
||||
iconId: UUID
|
||||
id: Long!
|
||||
images: [Image!]!
|
||||
isDefault: Boolean!
|
||||
isOfficial: Boolean!
|
||||
latestRelease: Release
|
||||
latestReleaseId: Long
|
||||
@ -68,8 +70,10 @@ type Entry {
|
||||
name: String!
|
||||
pluginInfo: PluginInfo
|
||||
releases: [Release!]!
|
||||
score: Int!
|
||||
summary: String!
|
||||
tags: [Tag!]!
|
||||
upvoteCount: Int!
|
||||
}
|
||||
|
||||
type Image {
|
||||
@ -99,6 +103,8 @@ type LayoutInfo {
|
||||
type Mutation {
|
||||
addEntry(input: CreateEntryInput!): Entry
|
||||
addLayoutInfo(input: CreateLayoutInfoInput!): LayoutInfo
|
||||
castVote(input: CastVoteInput!): Entry
|
||||
clearVote(entryId: Long!): Entry
|
||||
removeEntry(id: Long!): Entry
|
||||
removeLayoutInfo(id: Long!): LayoutInfo!
|
||||
removeRelease(id: Long!): Release!
|
||||
@ -168,6 +174,7 @@ type Query {
|
||||
searchKeyboardLayout(deviceProvider: UUID!, logicalLayout: String, model: String!, physicalLayout: KeyboardLayoutType!, vendor: String!): LayoutInfo
|
||||
searchLayout(deviceProvider: UUID!, deviceType: RGBDeviceType!, model: String!, vendor: String!): LayoutInfo
|
||||
submittedEntries(order: [EntrySortInput!], where: EntryFilterInput): [Entry!]!
|
||||
votes(order: [VoteSortInput!], where: VoteFilterInput): [Vote!]!
|
||||
}
|
||||
|
||||
type Release {
|
||||
@ -188,6 +195,15 @@ type Tag {
|
||||
name: String!
|
||||
}
|
||||
|
||||
type Vote {
|
||||
entry: Entry!
|
||||
entryId: Long!
|
||||
id: Long!
|
||||
upvote: Boolean!
|
||||
userId: UUID!
|
||||
votedAt: DateTime!
|
||||
}
|
||||
|
||||
enum ApplyPolicy {
|
||||
AFTER_RESOLVER
|
||||
BEFORE_RESOLVER
|
||||
@ -250,6 +266,11 @@ input BooleanOperationFilterInput {
|
||||
neq: Boolean
|
||||
}
|
||||
|
||||
input CastVoteInput {
|
||||
entryId: Long!
|
||||
upvote: Boolean!
|
||||
}
|
||||
|
||||
input CategoryFilterInput {
|
||||
and: [CategoryFilterInput!]
|
||||
icon: StringOperationFilterInput
|
||||
@ -268,6 +289,7 @@ input CreateEntryInput {
|
||||
categories: [Long!]!
|
||||
description: String!
|
||||
entryType: EntryType!
|
||||
isDefault: Boolean!
|
||||
name: String!
|
||||
summary: String!
|
||||
tags: [String!]!
|
||||
@ -307,11 +329,13 @@ input EntryFilterInput {
|
||||
dependantReleases: ListFilterInputTypeOfReleaseFilterInput
|
||||
description: StringOperationFilterInput
|
||||
downloads: LongOperationFilterInput
|
||||
downvoteCount: IntOperationFilterInput
|
||||
entryType: EntryTypeOperationFilterInput
|
||||
icon: ImageFilterInput
|
||||
iconId: UuidOperationFilterInput
|
||||
id: LongOperationFilterInput
|
||||
images: ListFilterInputTypeOfImageFilterInput
|
||||
isDefault: BooleanOperationFilterInput
|
||||
isOfficial: BooleanOperationFilterInput
|
||||
latestRelease: ReleaseFilterInput
|
||||
latestReleaseId: LongOperationFilterInput
|
||||
@ -320,8 +344,10 @@ input EntryFilterInput {
|
||||
or: [EntryFilterInput!]
|
||||
pluginInfo: PluginInfoFilterInput
|
||||
releases: ListFilterInputTypeOfReleaseFilterInput
|
||||
score: IntOperationFilterInput
|
||||
summary: StringOperationFilterInput
|
||||
tags: ListFilterInputTypeOfTagFilterInput
|
||||
upvoteCount: IntOperationFilterInput
|
||||
}
|
||||
|
||||
input EntrySortInput {
|
||||
@ -330,16 +356,20 @@ input EntrySortInput {
|
||||
createdAt: SortEnumType
|
||||
description: SortEnumType
|
||||
downloads: SortEnumType
|
||||
downvoteCount: SortEnumType
|
||||
entryType: SortEnumType
|
||||
icon: ImageSortInput
|
||||
iconId: SortEnumType
|
||||
id: SortEnumType
|
||||
isDefault: SortEnumType
|
||||
isOfficial: SortEnumType
|
||||
latestRelease: ReleaseSortInput
|
||||
latestReleaseId: SortEnumType
|
||||
name: SortEnumType
|
||||
pluginInfo: PluginInfoSortInput
|
||||
score: SortEnumType
|
||||
summary: SortEnumType
|
||||
upvoteCount: SortEnumType
|
||||
}
|
||||
|
||||
input EntryTypeOperationFilterInput {
|
||||
@ -580,6 +610,7 @@ input UpdateEntryInput {
|
||||
categories: [Long!]!
|
||||
description: String!
|
||||
id: Long!
|
||||
isDefault: Boolean!
|
||||
name: String!
|
||||
summary: String!
|
||||
tags: [String!]!
|
||||
@ -604,3 +635,23 @@ input UuidOperationFilterInput {
|
||||
nlt: UUID
|
||||
nlte: UUID
|
||||
}
|
||||
|
||||
input VoteFilterInput {
|
||||
and: [VoteFilterInput!]
|
||||
entry: EntryFilterInput
|
||||
entryId: LongOperationFilterInput
|
||||
id: LongOperationFilterInput
|
||||
or: [VoteFilterInput!]
|
||||
upvote: BooleanOperationFilterInput
|
||||
userId: UuidOperationFilterInput
|
||||
votedAt: DateTimeOperationFilterInput
|
||||
}
|
||||
|
||||
input VoteSortInput {
|
||||
entry: EntrySortInput
|
||||
entryId: SortEnumType
|
||||
id: SortEnumType
|
||||
upvote: SortEnumType
|
||||
userId: SortEnumType
|
||||
votedAt: SortEnumType
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user