mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 11:26:27 +00:00
Devices - Implemented switching between layout providers
This commit is contained in:
1 parent
e8590abd61
commit
dad6a56238
25 files changed
+178
-80
No files matched your search
@@ -1,11 +1,18 @@
|
||||
using RGB.NET.Layout;
|
||||
using Artemis.Core.Services;
|
||||
using RGB.NET.Layout;
|
||||
|
||||
namespace Artemis.Core.Providers;
|
||||
|
||||
public class CustomPathLayoutProvider : ILayoutProvider
|
||||
{
|
||||
public static string LayoutType = "CustomPath";
|
||||
|
||||
private readonly IDeviceService _deviceService;
|
||||
|
||||
public CustomPathLayoutProvider(IDeviceService deviceService)
|
||||
{
|
||||
_deviceService = deviceService;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ArtemisLayout? GetDeviceLayout(ArtemisDevice device)
|
||||
{
|
||||
@@ -19,10 +26,23 @@ public class CustomPathLayoutProvider : ILayoutProvider
|
||||
{
|
||||
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="path">The path to the custom layout.</param>
|
||||
public void ConfigureDevice(ArtemisDevice device, string? path)
|
||||
{
|
||||
device.LayoutSelection.Type = LayoutType;
|
||||
device.LayoutSelection.Parameter = path;
|
||||
_deviceService.SaveDevice(device);
|
||||
_deviceService.LoadDeviceLayout(device);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,16 @@
|
||||
namespace Artemis.Core.Providers;
|
||||
using Artemis.Core.Services;
|
||||
|
||||
namespace Artemis.Core.Providers;
|
||||
|
||||
public class DefaultLayoutProvider : ILayoutProvider
|
||||
{
|
||||
public static string LayoutType = "Default";
|
||||
private readonly IDeviceService _deviceService;
|
||||
|
||||
public DefaultLayoutProvider(IDeviceService deviceService)
|
||||
{
|
||||
_deviceService = deviceService;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ArtemisLayout? GetDeviceLayout(ArtemisDevice device)
|
||||
@@ -28,4 +36,16 @@ public class DefaultLayoutProvider : ILayoutProvider
|
||||
{
|
||||
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>
|
||||
public void ConfigureDevice(ArtemisDevice device)
|
||||
{
|
||||
device.LayoutSelection.Type = LayoutType;
|
||||
device.LayoutSelection.Parameter = null;
|
||||
_deviceService.SaveDevice(device);
|
||||
_deviceService.LoadDeviceLayout(device);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,17 @@
|
||||
namespace Artemis.Core.Providers;
|
||||
using Artemis.Core.Services;
|
||||
|
||||
namespace Artemis.Core.Providers;
|
||||
|
||||
public class NoneLayoutProvider : ILayoutProvider
|
||||
{
|
||||
private readonly IDeviceService _deviceService;
|
||||
public static string LayoutType = "None";
|
||||
|
||||
public NoneLayoutProvider(IDeviceService deviceService)
|
||||
{
|
||||
_deviceService = deviceService;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ArtemisLayout? GetDeviceLayout(ArtemisDevice device)
|
||||
{
|
||||
@@ -21,4 +29,16 @@ public class NoneLayoutProvider : ILayoutProvider
|
||||
{
|
||||
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>
|
||||
public void ConfigureDevice(ArtemisDevice device)
|
||||
{
|
||||
device.LayoutSelection.Type = LayoutType;
|
||||
device.LayoutSelection.Parameter = null;
|
||||
_deviceService.SaveDevice(device);
|
||||
_deviceService.LoadDeviceLayout(device);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ using Artemis.Core.Providers;
|
||||
using Artemis.Core.Services.Models;
|
||||
using Artemis.Storage.Entities.Surface;
|
||||
using Artemis.Storage.Repositories.Interfaces;
|
||||
using DryIoc;
|
||||
using RGB.NET.Core;
|
||||
using Serilog;
|
||||
|
||||
@@ -19,7 +20,7 @@ internal class DeviceService : IDeviceService
|
||||
private readonly IPluginManagementService _pluginManagementService;
|
||||
private readonly IDeviceRepository _deviceRepository;
|
||||
private readonly Lazy<IRenderService> _renderService;
|
||||
private readonly Func<IEnumerable<ILayoutProvider>> _getLayoutProviders;
|
||||
private readonly LazyEnumerable<ILayoutProvider> _layoutProviders;
|
||||
private readonly List<ArtemisDevice> _enabledDevices = new();
|
||||
private readonly List<ArtemisDevice> _devices = new();
|
||||
|
||||
@@ -27,13 +28,13 @@ internal class DeviceService : IDeviceService
|
||||
IPluginManagementService pluginManagementService,
|
||||
IDeviceRepository deviceRepository,
|
||||
Lazy<IRenderService> renderService,
|
||||
Func<IEnumerable<ILayoutProvider>> getLayoutProviders)
|
||||
LazyEnumerable<ILayoutProvider> layoutProviders)
|
||||
{
|
||||
_logger = logger;
|
||||
_pluginManagementService = pluginManagementService;
|
||||
_deviceRepository = deviceRepository;
|
||||
_renderService = renderService;
|
||||
_getLayoutProviders = getLayoutProviders;
|
||||
_layoutProviders = layoutProviders;
|
||||
|
||||
EnabledDevices = new ReadOnlyCollection<ArtemisDevice>(_enabledDevices);
|
||||
Devices = new ReadOnlyCollection<ArtemisDevice>(_devices);
|
||||
@@ -166,7 +167,7 @@ internal class DeviceService : IDeviceService
|
||||
/// <inheritdoc />
|
||||
public void LoadDeviceLayout(ArtemisDevice device)
|
||||
{
|
||||
ILayoutProvider? provider = _getLayoutProviders().FirstOrDefault(p => p.IsMatch(device));
|
||||
ILayoutProvider? provider = _layoutProviders.FirstOrDefault(p => p.IsMatch(device));
|
||||
if (provider == null)
|
||||
_logger.Warning("Could not find a layout provider for type {LayoutType} of device {Device}", device.LayoutSelection.Type, device);
|
||||
|
||||
@@ -176,11 +177,18 @@ internal class DeviceService : IDeviceService
|
||||
_logger.Warning("Got an invalid layout {Layout} from {LayoutProvider}", layout, provider!.GetType().FullName);
|
||||
layout = null;
|
||||
}
|
||||
|
||||
if (layout == null)
|
||||
device.ApplyLayout(null, false, false);
|
||||
else
|
||||
provider!.ApplyLayout(device, layout);
|
||||
|
||||
try
|
||||
{
|
||||
if (layout == null)
|
||||
device.ApplyLayout(null, false, false);
|
||||
else
|
||||
provider?.ApplyLayout(device, layout);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Error(e, "Failed to apply device layout");
|
||||
}
|
||||
|
||||
UpdateLeds();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user