From 25dcb16964779a07be97800ab4311ddab30b8538 Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Mon, 1 Feb 2021 19:36:29 +0100 Subject: [PATCH 1/2] Plugins - Check main entry DLL casing to avoid weird namespace issues Editor - Removed limit on zooming with mouseswheel, closes #528 --- src/Artemis.Core/Services/PluginManagementService.cs | 5 ++++- src/Artemis.UI/Screens/Shared/PanZoomViewModel.cs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Artemis.Core/Services/PluginManagementService.cs b/src/Artemis.Core/Services/PluginManagementService.cs index c15122d1d..30e085d6e 100644 --- a/src/Artemis.Core/Services/PluginManagementService.cs +++ b/src/Artemis.Core/Services/PluginManagementService.cs @@ -270,7 +270,10 @@ namespace Artemis.Core.Services string? mainFile = plugin.ResolveRelativePath(plugin.Info.Main); if (!File.Exists(mainFile)) throw new ArtemisPluginException(plugin, "Couldn't find the plugins main entry at " + mainFile); - + FileInfo[] fileInfos = directory.GetFiles(); + if (!fileInfos.Any(f => string.Equals(f.Name, plugin.Info.Main, StringComparison.InvariantCulture))) + throw new ArtemisPluginException(plugin, "Plugin main entry casing mismatch at " + plugin.Info.Main); + // Load the plugin, all types implementing Plugin and register them with DI plugin.PluginLoader = PluginLoader.CreateFromAssemblyFile(mainFile!, configure => { diff --git a/src/Artemis.UI/Screens/Shared/PanZoomViewModel.cs b/src/Artemis.UI/Screens/Shared/PanZoomViewModel.cs index 45638755c..e751e5e51 100644 --- a/src/Artemis.UI/Screens/Shared/PanZoomViewModel.cs +++ b/src/Artemis.UI/Screens/Shared/PanZoomViewModel.cs @@ -94,7 +94,7 @@ namespace Artemis.UI.Screens.Shared Zoom *= 0.9; // Limit to a min of 0.1 and a max of 2.5 (10% - 250% in the view) - Zoom = Math.Max(0.1, Math.Min(2.5, Zoom)); + Zoom = Math.Max(0.1, Zoom); // Update the PanX/Y to enable zooming relative to cursor if (LimitToZero) From bd6c93b292c391132fd8dcc127809ee7b4ec4266 Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Mon, 1 Feb 2021 19:54:28 +0100 Subject: [PATCH 2/2] Devices - Added option to disable devices --- src/Artemis.Core/Models/Profile/Layer.cs | 2 +- .../Models/Surface/ArtemisDevice.cs | 16 ++++- .../Models/Surface/ArtemisSurface.cs | 2 +- src/Artemis.Core/Services/RgbService.cs | 4 +- .../Entities/Surface/DeviceEntity.cs | 1 + .../Visualization/ProfileViewModel.cs | 2 +- .../Settings/Tabs/About/AboutTabView.xaml | 58 +++++++++++-------- .../Tabs/Devices/DeviceSettingsTabView.xaml | 9 ++- .../Devices/DeviceSettingsTabViewModel.cs | 26 ++++++++- .../Tabs/Devices/DeviceSettingsView.xaml | 12 ++-- .../Tabs/Devices/DeviceSettingsViewModel.cs | 33 ++++++++--- .../Tabs/Modules/ModuleOrderTabView.xaml | 1 + .../SurfaceEditor/SurfaceEditorViewModel.cs | 2 +- .../Visualization/SurfaceDeviceViewModel.cs | 2 +- 14 files changed, 118 insertions(+), 52 deletions(-) diff --git a/src/Artemis.Core/Models/Profile/Layer.cs b/src/Artemis.Core/Models/Profile/Layer.cs index 7cec76f9a..4485405d5 100644 --- a/src/Artemis.Core/Models/Profile/Layer.cs +++ b/src/Artemis.Core/Models/Profile/Layer.cs @@ -570,7 +570,7 @@ namespace Artemis.Core List leds = new(); // Get the surface LEDs for this layer - List availableLeds = surface.Devices.SelectMany(d => d.Leds).ToList(); + List availableLeds = surface.Devices.Where(d => d.IsEnabled).SelectMany(d => d.Leds).ToList(); foreach (LedEntity ledEntity in LayerEntity.Leds) { ArtemisLed? match = availableLeds.FirstOrDefault(a => a.Device.RgbDevice.GetDeviceIdentifier() == ledEntity.DeviceIdentifier && diff --git a/src/Artemis.Core/Models/Surface/ArtemisDevice.cs b/src/Artemis.Core/Models/Surface/ArtemisDevice.cs index 732b5c08b..107287d53 100644 --- a/src/Artemis.Core/Models/Surface/ArtemisDevice.cs +++ b/src/Artemis.Core/Models/Surface/ArtemisDevice.cs @@ -30,7 +30,8 @@ namespace Artemis.Core RedScale = 1; GreenScale = 1; BlueScale = 1; - + IsEnabled = true; + deviceProvider.DeviceLayoutPaths.TryGetValue(rgbDevice, out string? layoutPath); LayoutPath = layoutPath; @@ -213,6 +214,19 @@ namespace Artemis.Core } } + /// + /// Gets or sets a boolean indicating whether this devices is enabled or not + /// + public bool IsEnabled + { + get => DeviceEntity.IsEnabled; + set + { + DeviceEntity.IsEnabled = value; + OnPropertyChanged(nameof(IsEnabled)); + } + } + /// /// Gets the path to where the layout of the device was (attempted to be) loaded from /// diff --git a/src/Artemis.Core/Models/Surface/ArtemisSurface.cs b/src/Artemis.Core/Models/Surface/ArtemisSurface.cs index 58af700eb..c94f26543 100644 --- a/src/Artemis.Core/Models/Surface/ArtemisSurface.cs +++ b/src/Artemis.Core/Models/Surface/ArtemisSurface.cs @@ -98,7 +98,7 @@ namespace Artemis.Core internal void UpdateLedMap() { LedMap = new ReadOnlyDictionary( - _devices.SelectMany(d => d.Leds.Select(al => new KeyValuePair(al.RgbLed, al))).ToDictionary(kvp => kvp.Key, kvp => kvp.Value) + _devices.Where(d => d.IsEnabled).SelectMany(d => d.Leds.Select(al => new KeyValuePair(al.RgbLed, al))).ToDictionary(kvp => kvp.Key, kvp => kvp.Value) ); } diff --git a/src/Artemis.Core/Services/RgbService.cs b/src/Artemis.Core/Services/RgbService.cs index d2e1cfa3d..6d7492100 100644 --- a/src/Artemis.Core/Services/RgbService.cs +++ b/src/Artemis.Core/Services/RgbService.cs @@ -117,7 +117,7 @@ namespace Artemis.Core.Services { // Apply the application wide brush and decorator BitmapBrush = new BitmapBrush(new Scale(_renderScaleSetting.Value), _sampleSizeSetting); - _surfaceLedGroup = new ListLedGroup(Surface.Leds) {Brush = BitmapBrush}; + _surfaceLedGroup = new ListLedGroup(artemisSurface.LedMap.Select(l => l.Key)) {Brush = BitmapBrush}; return; } @@ -129,7 +129,7 @@ namespace Artemis.Core.Services // Apply the application wide brush and decorator BitmapBrush.Scale = new Scale(_renderScaleSetting.Value); BitmapBrush.Surface = artemisSurface; - _surfaceLedGroup = new ListLedGroup(Surface.Leds) {Brush = BitmapBrush}; + _surfaceLedGroup = new ListLedGroup(artemisSurface.LedMap.Select(l => l.Key)) {Brush = BitmapBrush}; } } diff --git a/src/Artemis.Storage/Entities/Surface/DeviceEntity.cs b/src/Artemis.Storage/Entities/Surface/DeviceEntity.cs index b4a5f7665..b952fc74c 100644 --- a/src/Artemis.Storage/Entities/Surface/DeviceEntity.cs +++ b/src/Artemis.Storage/Entities/Surface/DeviceEntity.cs @@ -18,6 +18,7 @@ namespace Artemis.Storage.Entities.Surface public double RedScale { get; set; } public double GreenScale { get; set; } public double BlueScale { get; set; } + public bool IsEnabled { get; set; } public List InputIdentifiers { get; set; } } diff --git a/src/Artemis.UI/Screens/ProfileEditor/Visualization/ProfileViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/Visualization/ProfileViewModel.cs index 6684c3bfe..e559a30fc 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Visualization/ProfileViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/Visualization/ProfileViewModel.cs @@ -207,7 +207,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization private void ApplySurfaceConfiguration(ArtemisSurface surface) { Devices.Clear(); - Devices.AddRange(surface.Devices.OrderBy(d => d.ZIndex)); + Devices.AddRange(surface.Devices.Where(d => d.IsEnabled).OrderBy(d => d.ZIndex)); } private void UpdateLedsDimStatus() diff --git a/src/Artemis.UI/Screens/Settings/Tabs/About/AboutTabView.xaml b/src/Artemis.UI/Screens/Settings/Tabs/About/AboutTabView.xaml index ccb64a250..f7a3f14c2 100644 --- a/src/Artemis.UI/Screens/Settings/Tabs/About/AboutTabView.xaml +++ b/src/Artemis.UI/Screens/Settings/Tabs/About/AboutTabView.xaml @@ -5,43 +5,51 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Artemis.UI.Screens.Settings.Tabs.About" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" + xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance local:AboutTabViewModel}"> - - Artemis 2 - + + + + Artemis 2 + + - - Lead developer - - - Spoinky (Robert Beekman) + + + + Lead developer + + + + - Spoinky (Robert Beekman) - - Main contributors + + + + Main contributors + + + + - DarthAffe + - DrMeteor (Diogo Trindade) - - DarthAffe - - - DrMeteor (Diogo Trindade) - - - - Special thanks - - - All the people on Discord provinding feedback and testing - - - Aureshion - Default device images + + + + Special thanks + + + + - All the people on Discord providing feedback and testing + - Aureshion - Default device images diff --git a/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsTabView.xaml b/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsTabView.xaml index 8e4986573..d1efa8012 100644 --- a/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsTabView.xaml +++ b/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsTabView.xaml @@ -10,7 +10,14 @@ d:DataContext="{d:DesignInstance local:DeviceSettingsTabViewModel}"> - Below you view and manage the devices that were detected by Artemis + + Device management + + Below you view and manage the devices that were detected by Artemis. + Disabling a device will cause it to stop updating. Some SDKs will even go back to using manufacturer lighting (Artemis restart may be required). + + + diff --git a/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsTabViewModel.cs b/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsTabViewModel.cs index 080f86424..31ba945e7 100644 --- a/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsTabViewModel.cs +++ b/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsTabViewModel.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading.Tasks; using Artemis.Core.Services; using Artemis.UI.Ninject.Factories; +using Artemis.UI.Shared.Services; using Stylet; namespace Artemis.UI.Screens.Settings.Tabs.Devices @@ -11,19 +12,22 @@ namespace Artemis.UI.Screens.Settings.Tabs.Devices { private readonly ISettingsVmFactory _settingsVmFactory; private readonly ISurfaceService _surfaceService; + private readonly IDialogService _dialogService; + private bool _confirmedDisable; - public DeviceSettingsTabViewModel(ISurfaceService surfaceService, ISettingsVmFactory settingsVmFactory) + public DeviceSettingsTabViewModel(ISurfaceService surfaceService, IDialogService dialogService, ISettingsVmFactory settingsVmFactory) { DisplayName = "DEVICES"; _surfaceService = surfaceService; + _dialogService = dialogService; _settingsVmFactory = settingsVmFactory; } - + protected override void OnActivate() { // Take it off the UI thread to avoid freezing on tab change - Task.Run(async () => + Task.Run(async () => { Items.Clear(); await Task.Delay(200); @@ -35,5 +39,21 @@ namespace Artemis.UI.Screens.Settings.Tabs.Devices base.OnActivate(); } + + public async Task ShowDeviceDisableDialog() + { + if (_confirmedDisable) + return true; + + bool confirmed = await _dialogService.ShowConfirmDialog( + "Disabling device", + "Disabling a device will cause it to stop updating. " + + "\r\nSome SDKs will even go back to using manufacturer lighting (Artemis restart may be required)." + ); + if (confirmed) + _confirmedDisable = true; + + return confirmed; + } } } \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsView.xaml b/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsView.xaml index d452a4fd0..8b4be68fa 100644 --- a/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsView.xaml +++ b/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsView.xaml @@ -29,7 +29,7 @@ - + - + diff --git a/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsViewModel.cs b/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsViewModel.cs index 42f2121e1..4ae2e45e2 100644 --- a/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsViewModel.cs +++ b/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsViewModel.cs @@ -14,14 +14,13 @@ using Stylet; namespace Artemis.UI.Screens.Settings.Tabs.Devices { - public class DeviceSettingsViewModel : PropertyChangedBase + public class DeviceSettingsViewModel : Screen { private readonly IDeviceDebugVmFactory _deviceDebugVmFactory; private readonly ISurfaceService _surfaceService; private readonly IDeviceService _deviceService; private readonly IDialogService _dialogService; private readonly IWindowManager _windowManager; - private bool _isDeviceEnabled; public DeviceSettingsViewModel(ArtemisDevice device, IDeviceService deviceService, @@ -40,9 +39,6 @@ namespace Artemis.UI.Screens.Settings.Tabs.Devices Type = Device.RgbDevice.DeviceInfo.DeviceType.ToString().Humanize(); Name = Device.RgbDevice.DeviceInfo.Model; Manufacturer = Device.RgbDevice.DeviceInfo.Manufacturer; - - // TODO: Implement this bad boy - IsDeviceEnabled = true; } public ArtemisDevice Device { get; } @@ -56,8 +52,27 @@ namespace Artemis.UI.Screens.Settings.Tabs.Devices public bool IsDeviceEnabled { - get => _isDeviceEnabled; - set => SetAndNotify(ref _isDeviceEnabled, value); + get => Device.IsEnabled; + set + { + Task.Run(() => UpdateIsDeviceEnabled(value)); + + } + } + + private async Task UpdateIsDeviceEnabled(bool value) + { + if (!value) + value = !await ((DeviceSettingsTabViewModel)Parent).ShowDeviceDisableDialog(); + + Device.IsEnabled = value; + NotifyOfPropertyChange(nameof(IsDeviceEnabled)); + SaveDevice(); + } + + private void SaveDevice() + { + _surfaceService.UpdateSurfaceConfiguration(_surfaceService.ActiveSurface, true); } public void IdentifyDevice() @@ -85,10 +100,10 @@ namespace Artemis.UI.Screens.Settings.Tabs.Devices public async Task DetectInput() { object madeChanges = await _dialogService.ShowDialog( - new Dictionary { { "device", Device } } + new Dictionary {{"device", Device}} ); - if ((bool)madeChanges) + if ((bool) madeChanges) _surfaceService.UpdateSurfaceConfiguration(_surfaceService.ActiveSurface, true); } diff --git a/src/Artemis.UI/Screens/Settings/Tabs/Modules/ModuleOrderTabView.xaml b/src/Artemis.UI/Screens/Settings/Tabs/Modules/ModuleOrderTabView.xaml index e14198f9d..9e015f13f 100644 --- a/src/Artemis.UI/Screens/Settings/Tabs/Modules/ModuleOrderTabView.xaml +++ b/src/Artemis.UI/Screens/Settings/Tabs/Modules/ModuleOrderTabView.xaml @@ -19,6 +19,7 @@ + Module priority Drag and drop the modules below to change their rendering priority. - Like in the profile editor, the modules at the top render over modules at the bottom diff --git a/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorViewModel.cs b/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorViewModel.cs index b0b89984a..aa285c954 100644 --- a/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorViewModel.cs +++ b/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorViewModel.cs @@ -176,7 +176,7 @@ namespace Artemis.UI.Screens.SurfaceEditor List deviceViewModels = new(); // Add missing/update existing - foreach (ArtemisDevice surfaceDeviceConfiguration in SelectedSurface.Devices.OrderBy(d => d.ZIndex).ToList()) + foreach (ArtemisDevice surfaceDeviceConfiguration in SelectedSurface.Devices.Where(d => d.IsEnabled).OrderBy(d => d.ZIndex).ToList()) { // Create VMs for missing devices SurfaceDeviceViewModel viewModel = existing.FirstOrDefault(vm => vm.Device.RgbDevice == surfaceDeviceConfiguration.RgbDevice); diff --git a/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceDeviceViewModel.cs b/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceDeviceViewModel.cs index 96050c532..9447d7ac6 100644 --- a/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceDeviceViewModel.cs +++ b/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceDeviceViewModel.cs @@ -116,7 +116,7 @@ namespace Artemis.UI.Screens.SurfaceEditor.Visualization .Select(l => SKRect.Create(l.Rectangle.Left + x, l.Rectangle.Top + y, l.Rectangle.Width, l.Rectangle.Height)) .ToList(); List others = Device.Surface.Devices - .Where(d => d != Device) + .Where(d => d != Device && d.IsEnabled) .SelectMany(d => d.Leds) .Select(l => SKRect.Create(l.Rectangle.Left + (float) l.Device.X, l.Rectangle.Top + (float) l.Device.Y, l.Rectangle.Width, l.Rectangle.Height)) .ToList();