diff --git a/src/Artemis.Core/Providers/CustomPathLayoutProvider.cs b/src/Artemis.Core/Providers/CustomPathLayoutProvider.cs
index 5b5e96e2c..61f47119a 100644
--- a/src/Artemis.Core/Providers/CustomPathLayoutProvider.cs
+++ b/src/Artemis.Core/Providers/CustomPathLayoutProvider.cs
@@ -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;
+ }
+
///
public ArtemisLayout? GetDeviceLayout(ArtemisDevice device)
{
@@ -19,10 +26,23 @@ public class CustomPathLayoutProvider : ILayoutProvider
{
device.ApplyLayout(layout, device.DeviceProvider.CreateMissingLedsSupported, device.DeviceProvider.RemoveExcessiveLedsSupported);
}
-
+
///
public bool IsMatch(ArtemisDevice device)
{
return device.LayoutSelection.Type == LayoutType;
}
+
+ ///
+ /// Configures the provided device to use this layout provider.
+ ///
+ /// The device to apply the provider to.
+ /// The path to the custom layout.
+ public void ConfigureDevice(ArtemisDevice device, string? path)
+ {
+ device.LayoutSelection.Type = LayoutType;
+ device.LayoutSelection.Parameter = path;
+ _deviceService.SaveDevice(device);
+ _deviceService.LoadDeviceLayout(device);
+ }
}
\ No newline at end of file
diff --git a/src/Artemis.Core/Providers/DefaultLayoutProvider.cs b/src/Artemis.Core/Providers/DefaultLayoutProvider.cs
index 2360ab11b..3ab899bed 100644
--- a/src/Artemis.Core/Providers/DefaultLayoutProvider.cs
+++ b/src/Artemis.Core/Providers/DefaultLayoutProvider.cs
@@ -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;
+ }
///
public ArtemisLayout? GetDeviceLayout(ArtemisDevice device)
@@ -28,4 +36,16 @@ public class DefaultLayoutProvider : ILayoutProvider
{
return device.LayoutSelection.Type == LayoutType;
}
+
+ ///
+ /// Configures the provided device to use this layout provider.
+ ///
+ /// The device to apply the provider to.
+ public void ConfigureDevice(ArtemisDevice device)
+ {
+ device.LayoutSelection.Type = LayoutType;
+ device.LayoutSelection.Parameter = null;
+ _deviceService.SaveDevice(device);
+ _deviceService.LoadDeviceLayout(device);
+ }
}
\ No newline at end of file
diff --git a/src/Artemis.Core/Providers/NoneLayoutProvider.cs b/src/Artemis.Core/Providers/NoneLayoutProvider.cs
index c764b0ddb..35de69ee6 100644
--- a/src/Artemis.Core/Providers/NoneLayoutProvider.cs
+++ b/src/Artemis.Core/Providers/NoneLayoutProvider.cs
@@ -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;
+ }
+
///
public ArtemisLayout? GetDeviceLayout(ArtemisDevice device)
{
@@ -21,4 +29,16 @@ public class NoneLayoutProvider : ILayoutProvider
{
return device.LayoutSelection.Type == LayoutType;
}
+
+ ///
+ /// Configures the provided device to use this layout provider.
+ ///
+ /// The device to apply the provider to.
+ public void ConfigureDevice(ArtemisDevice device)
+ {
+ device.LayoutSelection.Type = LayoutType;
+ device.LayoutSelection.Parameter = null;
+ _deviceService.SaveDevice(device);
+ _deviceService.LoadDeviceLayout(device);
+ }
}
\ No newline at end of file
diff --git a/src/Artemis.Core/Services/DeviceService.cs b/src/Artemis.Core/Services/DeviceService.cs
index ea3e09533..3a17d0bdc 100644
--- a/src/Artemis.Core/Services/DeviceService.cs
+++ b/src/Artemis.Core/Services/DeviceService.cs
@@ -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 _renderService;
- private readonly Func> _getLayoutProviders;
+ private readonly LazyEnumerable _layoutProviders;
private readonly List _enabledDevices = new();
private readonly List _devices = new();
@@ -27,13 +28,13 @@ internal class DeviceService : IDeviceService
IPluginManagementService pluginManagementService,
IDeviceRepository deviceRepository,
Lazy renderService,
- Func> getLayoutProviders)
+ LazyEnumerable layoutProviders)
{
_logger = logger;
_pluginManagementService = pluginManagementService;
_deviceRepository = deviceRepository;
_renderService = renderService;
- _getLayoutProviders = getLayoutProviders;
+ _layoutProviders = layoutProviders;
EnabledDevices = new ReadOnlyCollection(_enabledDevices);
Devices = new ReadOnlyCollection(_devices);
@@ -166,7 +167,7 @@ internal class DeviceService : IDeviceService
///
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();
}
diff --git a/src/Artemis.UI/Screens/Device/Tabs/Layout/DeviceLayoutTabView.axaml b/src/Artemis.UI/Screens/Device/Tabs/Layout/DeviceLayoutTabView.axaml
index b154411cf..9dccbfef4 100644
--- a/src/Artemis.UI/Screens/Device/Tabs/Layout/DeviceLayoutTabView.axaml
+++ b/src/Artemis.UI/Screens/Device/Tabs/Layout/DeviceLayoutTabView.axaml
@@ -4,8 +4,6 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
- xmlns:device="clr-namespace:Artemis.UI.Screens.Device"
- xmlns:providers="clr-namespace:Artemis.Core.Providers;assembly=Artemis.Core"
xmlns:layout="clr-namespace:Artemis.UI.Screens.Device.Layout"
xmlns:layoutProviders="clr-namespace:Artemis.UI.Screens.Device.Layout.LayoutProviders"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="800"
@@ -83,8 +81,8 @@
-
-
+
+
diff --git a/src/Artemis.UI/Screens/Device/Tabs/Layout/DeviceLayoutTabViewModel.cs b/src/Artemis.UI/Screens/Device/Tabs/Layout/DeviceLayoutTabViewModel.cs
index 4e3ef3455..8c100a9a6 100644
--- a/src/Artemis.UI/Screens/Device/Tabs/Layout/DeviceLayoutTabViewModel.cs
+++ b/src/Artemis.UI/Screens/Device/Tabs/Layout/DeviceLayoutTabViewModel.cs
@@ -11,6 +11,7 @@ using Artemis.UI.Shared;
using Artemis.UI.Shared.Services;
using Artemis.UI.Shared.Services.Builders;
using PropertyChanged.SourceGenerator;
+using ReactiveUI;
using RGB.NET.Layout;
namespace Artemis.UI.Screens.Device.Layout;
@@ -35,9 +36,16 @@ public partial class DeviceLayoutTabViewModel : ActivatableViewModelBase
foreach (ILayoutProviderViewModel layoutProviderViewModel in layoutProviders)
{
layoutProviderViewModel.Device = Device;
- if (layoutProviderViewModel.IsMatch(Device))
+ if (layoutProviderViewModel.Provider.IsMatch(Device))
SelectedLayoutProvider = layoutProviderViewModel;
}
+
+ // When changing device provider to one that isn't currently on the device, apply it to the device immediately
+ this.WhenAnyValue(vm => vm.SelectedLayoutProvider).Subscribe(l =>
+ {
+ if (l != null && !l.Provider.IsMatch(Device))
+ l.Apply();
+ });
}
public ArtemisDevice Device { get; }
@@ -77,13 +85,13 @@ public partial class DeviceLayoutTabViewModel : ActivatableViewModelBase
}
else
{
- List ledLayouts = Device.Leds.Select(x => new LedLayout()
+ List ledLayouts = Device.Leds.Select(x => new LedLayout
{
Id = x.RgbLed.Id.ToString(),
DescriptiveX = x.Rectangle.Left.ToString(),
DescriptiveY = x.Rectangle.Top.ToString(),
DescriptiveWidth = $"{x.Rectangle.Width}mm",
- DescriptiveHeight = $"{x.Rectangle.Height}mm",
+ DescriptiveHeight = $"{x.Rectangle.Height}mm"
}).ToList();
DeviceLayout emptyLayout = new()
@@ -94,7 +102,7 @@ public partial class DeviceLayoutTabViewModel : ActivatableViewModelBase
Model = Device.RgbDevice.DeviceInfo.Model,
Width = Device.Rectangle.Width,
Height = Device.Rectangle.Height,
- InternalLeds = ledLayouts,
+ InternalLeds = ledLayouts
};
XmlSerializer serializer = new(typeof(DeviceLayout));
diff --git a/src/Artemis.UI/Screens/Device/Tabs/Layout/DeviceLogicalLayoutDialogView.axaml b/src/Artemis.UI/Screens/Device/Tabs/Layout/DeviceLogicalLayoutDialogView.axaml
index 0626dc357..c32a2f462 100644
--- a/src/Artemis.UI/Screens/Device/Tabs/Layout/DeviceLogicalLayoutDialogView.axaml
+++ b/src/Artemis.UI/Screens/Device/Tabs/Layout/DeviceLogicalLayoutDialogView.axaml
@@ -2,7 +2,6 @@
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:device="clr-namespace:Artemis.UI.Screens.Device"
xmlns:globalization="clr-namespace:System.Globalization;assembly=System.Runtime"
xmlns:layout="clr-namespace:Artemis.UI.Screens.Device.Layout"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
@@ -28,8 +27,9 @@
-
-
+
+
+
diff --git a/src/Artemis.UI/Screens/Device/Tabs/Layout/DeviceLogicalLayoutDialogView.axaml.cs b/src/Artemis.UI/Screens/Device/Tabs/Layout/DeviceLogicalLayoutDialogView.axaml.cs
index c91a64662..977a59c9e 100644
--- a/src/Artemis.UI/Screens/Device/Tabs/Layout/DeviceLogicalLayoutDialogView.axaml.cs
+++ b/src/Artemis.UI/Screens/Device/Tabs/Layout/DeviceLogicalLayoutDialogView.axaml.cs
@@ -11,7 +11,7 @@ public partial class DeviceLogicalLayoutDialogView : ReactiveUserControl
-
+
diff --git a/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/CustomLayoutView.axaml.cs b/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/CustomLayoutView.axaml.cs
index 230302deb..cfc0af0d5 100644
--- a/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/CustomLayoutView.axaml.cs
+++ b/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/CustomLayoutView.axaml.cs
@@ -1,6 +1,4 @@
-using Avalonia;
using Avalonia.Controls;
-using Avalonia.Markup.Xaml;
namespace Artemis.UI.Screens.Device.Layout.LayoutProviders;
diff --git a/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/CustomLayoutViewModel.cs b/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/CustomLayoutViewModel.cs
index 4a22ff1f0..624fa376e 100644
--- a/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/CustomLayoutViewModel.cs
+++ b/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/CustomLayoutViewModel.cs
@@ -1,7 +1,6 @@
using System.Threading.Tasks;
using Artemis.Core;
using Artemis.Core.Providers;
-using Artemis.Core.Services;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Services;
using Artemis.UI.Shared.Services.Builders;
@@ -11,12 +10,10 @@ namespace Artemis.UI.Screens.Device.Layout.LayoutProviders;
public class CustomLayoutViewModel : ViewModelBase, ILayoutProviderViewModel
{
private readonly CustomPathLayoutProvider _layoutProvider;
- private readonly IDeviceService _deviceService;
- public CustomLayoutViewModel(IWindowService windowService, INotificationService notificationService, CustomPathLayoutProvider layoutProvider, IDeviceService deviceService)
+ public CustomLayoutViewModel(IWindowService windowService, INotificationService notificationService, CustomPathLayoutProvider layoutProvider)
{
_layoutProvider = layoutProvider;
- _deviceService = deviceService;
_windowService = windowService;
_notificationService = notificationService;
}
@@ -28,25 +25,21 @@ public class CustomLayoutViewModel : ViewModelBase, ILayoutProviderViewModel
public string Description => "Select a layout file from a folder on your computer";
///
- public bool IsMatch(ArtemisDevice device)
- {
- return _layoutProvider.IsMatch(device);
- }
+ public ILayoutProvider Provider => _layoutProvider;
public ArtemisDevice Device { get; set; } = null!;
-
+
private readonly IWindowService _windowService;
+
private readonly INotificationService _notificationService;
public void ClearCustomLayout()
{
- Device.LayoutSelection.Type = CustomPathLayoutProvider.LayoutType;
- Device.LayoutSelection.Parameter = null;
+ _layoutProvider.ConfigureDevice(Device, null);
+
_notificationService.CreateNotification()
.WithMessage("Cleared imported layout.")
.WithSeverity(NotificationSeverity.Informational);
-
- _deviceService.SaveDevice(Device);
}
public async Task BrowseCustomLayout()
@@ -58,14 +51,18 @@ public class CustomLayoutViewModel : ViewModelBase, ILayoutProviderViewModel
if (files?.Length > 0)
{
- Device.LayoutSelection.Type = CustomPathLayoutProvider.LayoutType;
- Device.LayoutSelection.Parameter = files[0];
+ _layoutProvider.ConfigureDevice(Device, files[0]);
+
_notificationService.CreateNotification()
.WithTitle("Imported layout")
.WithMessage($"File loaded from {files[0]}")
.WithSeverity(NotificationSeverity.Informational);
}
-
- _deviceService.SaveDevice(Device);
+ }
+
+ ///
+ public void Apply()
+ {
+ _layoutProvider.ConfigureDevice(Device, null);
}
}
\ No newline at end of file
diff --git a/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/DefaultLayoutView.axaml b/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/DefaultLayoutView.axaml
index 7c248e017..61bb856e4 100644
--- a/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/DefaultLayoutView.axaml
+++ b/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/DefaultLayoutView.axaml
@@ -4,7 +4,11 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Artemis.UI.Screens.Device.Layout.LayoutProviders.DefaultLayoutView">
-
- Loading the default layout from the plugin or User Layouts folder.
-
-
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/DefaultLayoutView.axaml.cs b/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/DefaultLayoutView.axaml.cs
index 4dcf9a258..dfa0d7f91 100644
--- a/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/DefaultLayoutView.axaml.cs
+++ b/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/DefaultLayoutView.axaml.cs
@@ -1,6 +1,4 @@
-using Avalonia;
using Avalonia.Controls;
-using Avalonia.Markup.Xaml;
namespace Artemis.UI.Screens.Device.Layout.LayoutProviders;
diff --git a/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/DefaultLayoutViewModel.cs b/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/DefaultLayoutViewModel.cs
index e49fbcf07..78d4b9b0f 100644
--- a/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/DefaultLayoutViewModel.cs
+++ b/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/DefaultLayoutViewModel.cs
@@ -13,8 +13,11 @@ public class DefaultLayoutViewModel : ViewModelBase, ILayoutProviderViewModel
_layoutProvider = layoutProvider;
}
+ ///
+ public ILayoutProvider Provider => _layoutProvider;
+
public ArtemisDevice Device { get; set; } = null!;
-
+
///
public string Name => "Default";
@@ -22,8 +25,8 @@ public class DefaultLayoutViewModel : ViewModelBase, ILayoutProviderViewModel
public string Description => "Attempts to load a layout from the default paths";
///
- public bool IsMatch(ArtemisDevice device)
+ public void Apply()
{
- return _layoutProvider.IsMatch(device);
+ _layoutProvider.ConfigureDevice(Device);
}
}
\ No newline at end of file
diff --git a/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/ILayoutProviderViewModel.cs b/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/ILayoutProviderViewModel.cs
index 7de990659..888583650 100644
--- a/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/ILayoutProviderViewModel.cs
+++ b/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/ILayoutProviderViewModel.cs
@@ -1,4 +1,5 @@
using Artemis.Core;
+using Artemis.Core.Providers;
namespace Artemis.UI.Screens.Device.Layout.LayoutProviders;
@@ -8,7 +9,9 @@ public interface ILayoutProviderViewModel
string Description { get; }
- bool IsMatch(ArtemisDevice device);
+ ILayoutProvider Provider { get; }
ArtemisDevice Device { get; set; }
+
+ void Apply();
}
\ No newline at end of file
diff --git a/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/NoneLayoutView.axaml b/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/NoneLayoutView.axaml
index 95b49ed07..1c5151846 100644
--- a/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/NoneLayoutView.axaml
+++ b/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/NoneLayoutView.axaml
@@ -4,7 +4,11 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Artemis.UI.Screens.Device.Layout.LayoutProviders.NoneLayoutView">
-
- Not loading any layout, leaving LEDs to be positioned by the device provider.
-
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/NoneLayoutView.axaml.cs b/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/NoneLayoutView.axaml.cs
index be8396558..bfce59c6f 100644
--- a/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/NoneLayoutView.axaml.cs
+++ b/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/NoneLayoutView.axaml.cs
@@ -1,6 +1,4 @@
-using Avalonia;
using Avalonia.Controls;
-using Avalonia.Markup.Xaml;
namespace Artemis.UI.Screens.Device.Layout.LayoutProviders;
diff --git a/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/NoneLayoutViewModel.cs b/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/NoneLayoutViewModel.cs
index 9b0090b05..466c13f31 100644
--- a/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/NoneLayoutViewModel.cs
+++ b/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/NoneLayoutViewModel.cs
@@ -13,8 +13,11 @@ public class NoneLayoutViewModel : ViewModelBase, ILayoutProviderViewModel
_layoutProvider = layoutProvider;
}
+ ///
+ public ILayoutProvider Provider => _layoutProvider;
+
public ArtemisDevice Device { get; set; } = null!;
-
+
///
public string Name => "None";
@@ -22,8 +25,8 @@ public class NoneLayoutViewModel : ViewModelBase, ILayoutProviderViewModel
public string Description => "Do not load any layout";
///
- public bool IsMatch(ArtemisDevice device)
+ public void Apply()
{
- return _layoutProvider.IsMatch(device);
+ _layoutProvider.ConfigureDevice(Device);
}
}
\ No newline at end of file
diff --git a/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/WorkshopLayoutView.axaml b/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/WorkshopLayoutView.axaml
index 78a976e98..50de1a677 100644
--- a/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/WorkshopLayoutView.axaml
+++ b/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/WorkshopLayoutView.axaml
@@ -4,8 +4,11 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Artemis.UI.Screens.Device.Layout.LayoutProviders.WorkshopLayoutView">
-
-
- Here you'll do workshop things
-
-
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/WorkshopLayoutView.axaml.cs b/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/WorkshopLayoutView.axaml.cs
index 98a51506d..fc27fb9aa 100644
--- a/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/WorkshopLayoutView.axaml.cs
+++ b/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/WorkshopLayoutView.axaml.cs
@@ -1,6 +1,4 @@
-using Avalonia;
using Avalonia.Controls;
-using Avalonia.Markup.Xaml;
namespace Artemis.UI.Screens.Device.Layout.LayoutProviders;
diff --git a/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/WorkshopLayoutViewModel.cs b/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/WorkshopLayoutViewModel.cs
index 07128d075..948f8fe29 100644
--- a/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/WorkshopLayoutViewModel.cs
+++ b/src/Artemis.UI/Screens/Device/Tabs/Layout/LayoutProviders/WorkshopLayoutViewModel.cs
@@ -1,4 +1,5 @@
using Artemis.Core;
+using Artemis.Core.Providers;
using Artemis.UI.Shared;
using Artemis.WebClient.Workshop.Providers;
@@ -13,6 +14,9 @@ public class WorkshopLayoutViewModel : ViewModelBase, ILayoutProviderViewModel
_layoutProvider = layoutProvider;
}
+ ///
+ public ILayoutProvider Provider => _layoutProvider;
+
public ArtemisDevice Device { get; set; } = null!;
///
@@ -22,8 +26,8 @@ public class WorkshopLayoutViewModel : ViewModelBase, ILayoutProviderViewModel
public string Description => "Load a layout from the workshop";
///
- public bool IsMatch(ArtemisDevice device)
+ public void Apply()
{
- return _layoutProvider.IsMatch(device);
+ _layoutProvider.ConfigureDevice(Device);
}
}
\ No newline at end of file
diff --git a/src/Artemis.WebClient.Workshop/Providers/WorkshopLayoutProvider.cs b/src/Artemis.WebClient.Workshop/Providers/WorkshopLayoutProvider.cs
index 4b6901b3f..6544ff437 100644
--- a/src/Artemis.WebClient.Workshop/Providers/WorkshopLayoutProvider.cs
+++ b/src/Artemis.WebClient.Workshop/Providers/WorkshopLayoutProvider.cs
@@ -1,5 +1,6 @@
using Artemis.Core;
using Artemis.Core.Providers;
+using Artemis.Core.Services;
using Artemis.WebClient.Workshop.Services;
namespace Artemis.WebClient.Workshop.Providers;
@@ -7,11 +8,13 @@ namespace Artemis.WebClient.Workshop.Providers;
public class WorkshopLayoutProvider : ILayoutProvider
{
public static string LayoutType = "Workshop";
-
+
+ private readonly IDeviceService _deviceService;
private readonly IWorkshopService _workshopService;
- public WorkshopLayoutProvider(IWorkshopService workshopService)
+ public WorkshopLayoutProvider(IDeviceService deviceService, IWorkshopService workshopService)
{
+ _deviceService = deviceService;
_workshopService = workshopService;
}
@@ -45,4 +48,16 @@ public class WorkshopLayoutProvider : ILayoutProvider
{
return entry.TryGetMetadata("DeviceId", out HashSet? deviceIds) && deviceIds.Contains(device.Identifier);
}
+
+ ///
+ /// Configures the provided device to use this layout provider.
+ ///
+ /// The device to apply the provider to.
+ public void ConfigureDevice(ArtemisDevice device)
+ {
+ device.LayoutSelection.Type = LayoutType;
+ device.LayoutSelection.Parameter = null;
+ _deviceService.SaveDevice(device);
+ _deviceService.LoadDeviceLayout(device);
+ }
}
\ No newline at end of file
diff --git a/src/Artemis.WebClient.Workshop/Services/InstalledEntry.cs b/src/Artemis.WebClient.Workshop/Services/InstalledEntry.cs
index e284595e8..1ac3069e2 100644
--- a/src/Artemis.WebClient.Workshop/Services/InstalledEntry.cs
+++ b/src/Artemis.WebClient.Workshop/Services/InstalledEntry.cs
@@ -49,7 +49,7 @@ public class InstalledEntry
ReleaseVersion = Entity.ReleaseVersion;
InstalledAt = Entity.InstalledAt;
- _metadata = new Dictionary(Entity.Metadata);
+ _metadata = Entity.Metadata != null ? new Dictionary(Entity.Metadata) : new Dictionary();
}
internal void Save()