mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +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
@@ -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