diff --git a/src/Artemis.Core/Models/Surface/ArtemisDevice.cs b/src/Artemis.Core/Models/Surface/ArtemisDevice.cs index 953fda3d2..285b31855 100644 --- a/src/Artemis.Core/Models/Surface/ArtemisDevice.cs +++ b/src/Artemis.Core/Models/Surface/ArtemisDevice.cs @@ -23,16 +23,17 @@ namespace Artemis.Core RgbDevice = rgbDevice; DeviceProvider = deviceProvider; Surface = surface; - DeviceEntity = new DeviceEntity(); - - InputIdentifiers = new List(); - - _leds = rgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly(); - Rotation = 0; Scale = 1; ZIndex = 1; + DeviceEntity = new DeviceEntity(); + deviceProvider.DeviceLayoutPaths.TryGetValue(rgbDevice, out string? layoutPath); + LayoutPath = layoutPath; + + InputIdentifiers = new List(); + + _leds = rgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly(); ApplyToEntity(); CalculateRenderProperties(); } @@ -44,6 +45,9 @@ namespace Artemis.Core Surface = surface; DeviceEntity = deviceEntity; + deviceProvider.DeviceLayoutPaths.TryGetValue(rgbDevice, out string? layoutPath); + LayoutPath = layoutPath; + InputIdentifiers = new List(); foreach (DeviceInputIdentifierEntity identifierEntity in DeviceEntity.InputIdentifiers) InputIdentifiers.Add(new ArtemisDeviceInputIdentifier(identifierEntity.InputProvider, identifierEntity.Identifier)); @@ -94,7 +98,7 @@ namespace Artemis.Core } /// - /// Gets a list of input identifiers associated with this device + /// Gets a list of input identifiers associated with this device /// public List InputIdentifiers { get; } @@ -163,6 +167,11 @@ namespace Artemis.Core } } + /// + /// Gets the path to where the layout of the device was (attempted to be) loaded from + /// + public string? LayoutPath { get; internal set; } + internal DeviceEntity DeviceEntity { get; } /// @@ -191,13 +200,11 @@ namespace Artemis.Core DeviceEntity.InputIdentifiers.Clear(); foreach (ArtemisDeviceInputIdentifier identifier in InputIdentifiers) - { DeviceEntity.InputIdentifiers.Add(new DeviceInputIdentifierEntity { InputProvider = identifier.InputProvider, Identifier = identifier.Identifier }); - } } internal void ApplyToRgbDevice() diff --git a/src/Artemis.Core/Plugins/DeviceProviders/DeviceProvider.cs b/src/Artemis.Core/Plugins/DeviceProviders/DeviceProvider.cs index bfc020c52..06b465cc6 100644 --- a/src/Artemis.Core/Plugins/DeviceProviders/DeviceProvider.cs +++ b/src/Artemis.Core/Plugins/DeviceProviders/DeviceProvider.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using Ninject; using RGB.NET.Core; @@ -33,6 +34,8 @@ namespace Artemis.Core.DeviceProviders [Inject] public ILogger? Logger { get; set; } + internal Dictionary DeviceLayoutPaths { get; set; } = new Dictionary(); + /// public override void Disable() { @@ -54,12 +57,16 @@ namespace Artemis.Core.DeviceProviders else if (e.RelativePath != null) e.FinalPath = Path.Combine(Plugin.Directory.FullName, e.RelativePath); - IRGBDeviceInfo deviceInfo = ((IRGBDevice) sender).DeviceInfo; + IRGBDevice device = (IRGBDevice) sender; + IRGBDeviceInfo deviceInfo = device.DeviceInfo; if (e.FileName != null && !File.Exists(e.FinalPath)) { Logger?.Information("Couldn't find a layout for device {deviceName}, model {deviceModel} at {filePath}", deviceInfo.DeviceName, deviceInfo.Model, e.FinalPath); } + + if (e.FileName != null) + DeviceLayoutPaths[device] = e.FinalPath; } } } diff --git a/src/Artemis.Core/Services/PluginManagementService.cs b/src/Artemis.Core/Services/PluginManagementService.cs index 6f3edc843..22ea1f25a 100644 --- a/src/Artemis.Core/Services/PluginManagementService.cs +++ b/src/Artemis.Core/Services/PluginManagementService.cs @@ -297,7 +297,8 @@ namespace Artemis.Core.Services throw new ArtemisPluginException( plugin, "Failed to initialize the plugin assembly", - new AggregateException(e.LoaderExceptions.Where(le => le != null).ToArray()) + // ReSharper disable once RedundantEnumerableCastCall - Casting from nullable to non-nullable here + new AggregateException(e.LoaderExceptions.Where(le => le != null).Cast().ToArray()) ); } diff --git a/src/Artemis.UI/InputProviders/NativeWindowInputProvider.cs b/src/Artemis.UI/InputProviders/NativeWindowInputProvider.cs index a0e8b4d39..56f822d6e 100644 --- a/src/Artemis.UI/InputProviders/NativeWindowInputProvider.cs +++ b/src/Artemis.UI/InputProviders/NativeWindowInputProvider.cs @@ -6,6 +6,7 @@ using Artemis.Core; using Artemis.Core.Services; using Linearstar.Windows.RawInput; using Linearstar.Windows.RawInput.Native; +using Serilog; using MouseButton = Artemis.Core.Services.MouseButton; namespace Artemis.UI.InputProviders @@ -14,12 +15,14 @@ namespace Artemis.UI.InputProviders { private const int WM_INPUT = 0x00FF; + private readonly ILogger _logger; private readonly IInputService _inputService; private DateTime _lastMouseUpdate; private SpongeWindow _sponge; - public NativeWindowInputProvider(IInputService inputService) + public NativeWindowInputProvider(ILogger logger, IInputService inputService) { + _logger = logger; _inputService = inputService; _sponge = new SpongeWindow(); @@ -68,7 +71,7 @@ namespace Artemis.UI.InputProviders { KeyboardKey key = (KeyboardKey) KeyInterop.KeyFromVirtualKey(keyboardData.Keyboard.VirutalKey); // Debug.WriteLine($"VK: {key} ({keyboardData.Keyboard.VirutalKey}), Flags: {keyboardData.Keyboard.Flags}, Scan code: {keyboardData.Keyboard.ScanCode}"); - + // Sometimes we get double hits and they resolve to None, ignore those if (key == KeyboardKey.None) return; @@ -85,7 +88,16 @@ namespace Artemis.UI.InputProviders ArtemisDevice device = null; if (identifier != null) - device = _inputService.GetDeviceByIdentifier(this, identifier, InputDeviceType.Keyboard); + { + try + { + device = _inputService.GetDeviceByIdentifier(this, identifier, InputDeviceType.Keyboard); + } + catch (Exception e) + { + _logger.Warning(e, "Failed to retrieve input device by its identifier"); + } + } // Duplicate keys with different positions can be identified by the LeftKey flag (even though its set of the key that's physically on the right) if (keyboardData.Keyboard.Flags == RawKeyboardFlags.LeftKey || keyboardData.Keyboard.Flags == (RawKeyboardFlags.LeftKey | RawKeyboardFlags.Up)) @@ -130,7 +142,16 @@ namespace Artemis.UI.InputProviders ArtemisDevice device = null; string identifier = data.Device?.DevicePath; if (identifier != null) - device = _inputService.GetDeviceByIdentifier(this, identifier, InputDeviceType.Mouse); + { + try + { + device = _inputService.GetDeviceByIdentifier(this, identifier, InputDeviceType.Keyboard); + } + catch (Exception e) + { + _logger.Warning(e, "Failed to retrieve input device by its identifier"); + } + } // Debug.WriteLine($"Buttons: {data.Mouse.Buttons}, Data: {data.Mouse.ButtonData}, Flags: {data.Mouse.Flags}, XY: {data.Mouse.LastX},{data.Mouse.LastY}"); diff --git a/src/Artemis.UI/Screens/Settings/Debug/DeviceDebugView.xaml b/src/Artemis.UI/Screens/Settings/Debug/DeviceDebugView.xaml index d6cd0a90e..6ab2f00bd 100644 --- a/src/Artemis.UI/Screens/Settings/Debug/DeviceDebugView.xaml +++ b/src/Artemis.UI/Screens/Settings/Debug/DeviceDebugView.xaml @@ -47,212 +47,244 @@ - - - - - - - - + + + + + + + + + In this window you can view detailed information of the device. Please note that having this window open can have a performance impact on your system. - + - + + + - - - - - - - - - - - - - - Device name - + + + + + + + + + + + + + + + + + Device name + - - - + + + - - - - - - - - - - Manufacturer - + + + + + + + + + Manufacturer + - - - + + + - - - - - - - - - - Lighting support - + + + + + + + + + Lighting support + - - - + + + - - - - - - - - - - Device type - + + + + + + + + + Device type + - - - + + + - - - - - - - - - - Device image - - - - - - - - - - - - - - - - - Size (1px = 1mm) - + + + + + + + + + Device image + + + + + + + + + + + + + + + + + Size (1px = 1mm) + - - - - - - - - - - - - - Location (1px = 1mm) - + + + + + + + + + + + + Location (1px = 1mm) + - - - + + + - - - - - - - - - - Rotation (degrees) - + + + + + + + + + Rotation (degrees) + - - - + + + - - - - - - - - - - Syncback supported - + + + + + + + + + Syncback supported + - - - - - - - + + + - - - - - - - - - - - + + + + + + + + + + Layout file path + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Artemis.UI/Services/RegistrationService.cs b/src/Artemis.UI/Services/RegistrationService.cs index b1f75b0ad..f64218a08 100644 --- a/src/Artemis.UI/Services/RegistrationService.cs +++ b/src/Artemis.UI/Services/RegistrationService.cs @@ -8,11 +8,13 @@ using Artemis.UI.Ninject; using Artemis.UI.PropertyInput; using Artemis.UI.Services.Interfaces; using Artemis.UI.Shared.Services; +using Serilog; namespace Artemis.UI.Services { public class RegistrationService : IRegistrationService { + private readonly ILogger _logger; private readonly IDataModelUIService _dataModelUIService; private readonly IProfileEditorService _profileEditorService; private readonly IPluginManagementService _pluginManagementService; @@ -22,12 +24,14 @@ namespace Artemis.UI.Services private bool _registeredBuiltInDataModelInputs; private bool _registeredBuiltInPropertyEditors; - public RegistrationService(IDataModelUIService dataModelUIService, - IProfileEditorService profileEditorService, + public RegistrationService(ILogger logger, + IDataModelUIService dataModelUIService, + IProfileEditorService profileEditorService, IPluginManagementService pluginManagementService, ISurfaceService surfaceService, IInputService inputService) { + _logger = logger; _dataModelUIService = dataModelUIService; _profileEditorService = profileEditorService; _pluginManagementService = pluginManagementService; @@ -85,7 +89,7 @@ namespace Artemis.UI.Services public void RegisterInputProvider() { - _inputService.AddInputProvider(new NativeWindowInputProvider(_inputService)); + _inputService.AddInputProvider(new NativeWindowInputProvider(_logger, _inputService)); } private void PluginServiceOnPluginEnabling(object sender, PluginEventArgs e) @@ -95,7 +99,7 @@ namespace Artemis.UI.Services private void LoadPluginModules() { - foreach (Plugin plugin in _pluginManagementService.GetAllPlugins().Where(p => p.IsEnabled)) + foreach (Plugin plugin in _pluginManagementService.GetAllPlugins().Where(p => p.IsEnabled)) plugin.Kernel.Load(new[] {new PluginUIModule(plugin)}); } }