1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00
Artemis/src/Artemis.WebClient.Workshop/Providers/WorkshopLayoutProvider.cs
Robert 648b7765ef Core - Added API for retrieving current suspended device providers
Core - Added events for plugin removal, entry installlation/uninstallation
Workshop - Remove the related workshop entry when manually removing a plugin or profile
Workshop - Prevent installing profiles with missing plugins and show a dialog with which plugins are missing
2024-06-30 09:42:41 +02:00

60 lines
2.0 KiB
C#

using Artemis.Core;
using Artemis.Core.Providers;
using Artemis.WebClient.Workshop.Models;
using Artemis.WebClient.Workshop.Services;
namespace Artemis.WebClient.Workshop.Providers;
public class WorkshopLayoutProvider : ILayoutProvider
{
public static string LayoutType = "Workshop";
private readonly IWorkshopService _workshopService;
public WorkshopLayoutProvider(IWorkshopService workshopService)
{
_workshopService = workshopService;
}
/// <inheritdoc />
public ArtemisLayout? GetDeviceLayout(ArtemisDevice device)
{
if (!long.TryParse(device.LayoutSelection.Parameter, out long entryId))
return null;
InstalledEntry? layoutEntry = _workshopService.GetInstalledEntry(entryId);
if (layoutEntry == null)
return null;
string layoutPath = Path.Combine(layoutEntry.GetReleaseDirectory().FullName, "layout.xml");
if (!File.Exists(layoutPath))
return null;
return new ArtemisLayout(layoutPath);
}
/// <inheritdoc />
public void ApplyLayout(ArtemisDevice device, ArtemisLayout layout)
{
device.ApplyLayout(layout, device.DeviceProvider.CreateMissingLedsSupported, device.DeviceProvider.RemoveExcessiveLedsSupported);
}
/// <inheritdoc />
public bool IsMatch(ArtemisDevice device)
{
return device.LayoutSelection.Type == LayoutType;
}
/// <summary>
/// Configures the provided device to use this layout provider.
/// </summary>
/// <param name="device">The device to apply the provider to.</param>
/// <param name="entry">The workshop entry to use as a layout.</param>
public void ConfigureDevice(ArtemisDevice device, InstalledEntry? entry)
{
if (entry != null && entry.EntryType != EntryType.Layout)
throw new InvalidOperationException($"Cannot use a workshop entry of type {entry.EntryType} as a layout");
device.LayoutSelection.Type = LayoutType;
device.LayoutSelection.Parameter = entry?.EntryId.ToString();
}
}