mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Workshop Library - Added library pages
UI - Tweaked design to more closely match WinUI 3 gallery examples
This commit is contained in:
1 parent
e545d2f3da
commit
9c6d7329a6
25 files changed
+519
-288
No files matched your search
@@ -35,5 +35,8 @@
|
||||
<GraphQL Update="Queries\GetCategories.graphql">
|
||||
<Generator>MSBuild:GenerateGraphQLCode</Generator>
|
||||
</GraphQL>
|
||||
<GraphQL Update="Queries\GetSubmittedEntries.graphql">
|
||||
<Generator>MSBuild:GenerateGraphQLCode</Generator>
|
||||
</GraphQL>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,10 @@
|
||||
query GetSubmittedEntries($filter: EntryFilterInput) {
|
||||
submittedEntries(where: $filter order: {createdAt: DESC}) {
|
||||
id
|
||||
name
|
||||
summary
|
||||
entryType
|
||||
downloads
|
||||
createdAt
|
||||
}
|
||||
}
|
||||
@@ -1,30 +1,19 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Headers;
|
||||
using Artemis.UI.Shared.Routing;
|
||||
using Artemis.UI.Shared.Services.MainWindow;
|
||||
using Artemis.UI.Shared.Utilities;
|
||||
using Artemis.WebClient.Workshop.UploadHandlers;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Threading;
|
||||
|
||||
namespace Artemis.WebClient.Workshop.Services;
|
||||
|
||||
public class WorkshopService : IWorkshopService
|
||||
{
|
||||
private readonly Dictionary<Guid, Stream> _entryIconCache = new();
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly IRouter _router;
|
||||
private readonly SemaphoreSlim _iconCacheLock = new(1);
|
||||
|
||||
public WorkshopService(IHttpClientFactory httpClientFactory, IMainWindowService mainWindowService, IRouter router)
|
||||
public WorkshopService(IHttpClientFactory httpClientFactory, IRouter router)
|
||||
{
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_router = router;
|
||||
mainWindowService.MainWindowClosed += (_, _) => Dispatcher.UIThread.InvokeAsync(async () =>
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
ClearCache();
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<ImageUploadResult> SetEntryIcon(Guid entryId, Progress<StreamProgress> progress, Stream icon, CancellationToken cancellationToken)
|
||||
@@ -48,52 +37,41 @@ public class WorkshopService : IWorkshopService
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IWorkshopService.WorkshopStatus> GetWorkshopStatus()
|
||||
public async Task<IWorkshopService.WorkshopStatus> GetWorkshopStatus(CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Don't use the workshop client which adds auth headers
|
||||
HttpClient client = _httpClientFactory.CreateClient();
|
||||
HttpResponseMessage response = await client.SendAsync(new HttpRequestMessage(HttpMethod.Head, WorkshopConstants.WORKSHOP_URL + "/status"));
|
||||
HttpResponseMessage response = await client.SendAsync(new HttpRequestMessage(HttpMethod.Head, WorkshopConstants.WORKSHOP_URL + "/status"), cancellationToken);
|
||||
return new IWorkshopService.WorkshopStatus(response.IsSuccessStatusCode, response.StatusCode.ToString());
|
||||
}
|
||||
catch (OperationCanceledException e)
|
||||
{
|
||||
return new IWorkshopService.WorkshopStatus(false, e.Message);
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
return new IWorkshopService.WorkshopStatus(false, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> ValidateWorkshopStatus()
|
||||
public async Task<bool> ValidateWorkshopStatus(CancellationToken cancellationToken)
|
||||
{
|
||||
IWorkshopService.WorkshopStatus status = await GetWorkshopStatus();
|
||||
IWorkshopService.WorkshopStatus status = await GetWorkshopStatus(cancellationToken);
|
||||
if (!status.IsReachable)
|
||||
await _router.Navigate($"workshop/offline/{status.Message}");
|
||||
return status.IsReachable;
|
||||
}
|
||||
|
||||
private void ClearCache()
|
||||
{
|
||||
try
|
||||
{
|
||||
List<Stream> values = _entryIconCache.Values.ToList();
|
||||
_entryIconCache.Clear();
|
||||
foreach (Stream bitmap in values)
|
||||
bitmap.Dispose();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface IWorkshopService
|
||||
{
|
||||
Task<ImageUploadResult> SetEntryIcon(Guid entryId, Progress<StreamProgress> progress, Stream icon, CancellationToken cancellationToken);
|
||||
Task<WorkshopStatus> GetWorkshopStatus();
|
||||
Task<bool> ValidateWorkshopStatus();
|
||||
Task<WorkshopStatus> GetWorkshopStatus(CancellationToken cancellationToken);
|
||||
Task<bool> ValidateWorkshopStatus(CancellationToken cancellationToken);
|
||||
|
||||
public record WorkshopStatus(bool IsReachable, string Message);
|
||||
}
|
||||
@@ -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
|
||||
@@ -41,6 +41,7 @@ type Entry {
|
||||
id: UUID!
|
||||
images: [Image!]!
|
||||
latestRelease: Release
|
||||
latestReleaseId: UUID
|
||||
name: String!
|
||||
releases: [Release!]!
|
||||
summary: String!
|
||||
@@ -62,6 +63,7 @@ type Query {
|
||||
entries(order: [EntrySortInput!], skip: Int, take: Int, where: EntryFilterInput): EntriesCollectionSegment
|
||||
entry(id: UUID!): Entry
|
||||
searchEntries(input: String!, order: [EntrySortInput!], type: EntryType, where: EntryFilterInput): [Entry!]!
|
||||
submittedEntries(order: [EntrySortInput!], where: EntryFilterInput): [Entry!]!
|
||||
}
|
||||
|
||||
type Release {
|
||||
@@ -156,6 +158,8 @@ input EntryFilterInput {
|
||||
iconId: UuidOperationFilterInput
|
||||
id: UuidOperationFilterInput
|
||||
images: ListFilterInputTypeOfImageFilterInput
|
||||
latestRelease: ReleaseFilterInput
|
||||
latestReleaseId: UuidOperationFilterInput
|
||||
name: StringOperationFilterInput
|
||||
or: [EntryFilterInput!]
|
||||
releases: ListFilterInputTypeOfReleaseFilterInput
|
||||
@@ -173,6 +177,8 @@ input EntrySortInput {
|
||||
icon: ImageSortInput
|
||||
iconId: SortEnumType
|
||||
id: SortEnumType
|
||||
latestRelease: ReleaseSortInput
|
||||
latestReleaseId: SortEnumType
|
||||
name: SortEnumType
|
||||
summary: SortEnumType
|
||||
}
|
||||
@@ -267,6 +273,17 @@ input ReleaseFilterInput {
|
||||
version: StringOperationFilterInput
|
||||
}
|
||||
|
||||
input ReleaseSortInput {
|
||||
createdAt: SortEnumType
|
||||
downloadSize: SortEnumType
|
||||
downloads: SortEnumType
|
||||
entry: EntrySortInput
|
||||
entryId: SortEnumType
|
||||
id: SortEnumType
|
||||
md5Hash: SortEnumType
|
||||
version: SortEnumType
|
||||
}
|
||||
|
||||
input StringOperationFilterInput {
|
||||
and: [StringOperationFilterInput!]
|
||||
contains: String
|
||||
|
||||
Reference in new issue
Block a user