diff --git a/src/Artemis.Core/Artemis.Core.csproj b/src/Artemis.Core/Artemis.Core.csproj index 74c96f047..b9d5030a1 100644 --- a/src/Artemis.Core/Artemis.Core.csproj +++ b/src/Artemis.Core/Artemis.Core.csproj @@ -185,11 +185,13 @@ + + diff --git a/src/Artemis.Core/Events/DeviceEventArgs.cs b/src/Artemis.Core/Events/DeviceEventArgs.cs new file mode 100644 index 000000000..dc9f6dff9 --- /dev/null +++ b/src/Artemis.Core/Events/DeviceEventArgs.cs @@ -0,0 +1,19 @@ +using System; +using RGB.NET.Core; + +namespace Artemis.Core.Events +{ + public class DeviceEventArgs : EventArgs + { + public DeviceEventArgs() + { + } + + public DeviceEventArgs(IRGBDevice device) + { + Device = device; + } + + public IRGBDevice Device { get; } + } +} \ No newline at end of file diff --git a/src/Artemis.Core/Events/PluginEventArgs.cs b/src/Artemis.Core/Events/PluginEventArgs.cs index a13e08df8..5d3311f93 100644 --- a/src/Artemis.Core/Events/PluginEventArgs.cs +++ b/src/Artemis.Core/Events/PluginEventArgs.cs @@ -5,6 +5,15 @@ namespace Artemis.Core.Events { public class PluginEventArgs : EventArgs { - public IPlugin Plugin { get; set; } + public PluginEventArgs() + { + } + + public PluginEventArgs(IPlugin plugin) + { + Plugin = plugin; + } + + public IPlugin Plugin { get; } } } \ No newline at end of file diff --git a/src/Artemis.Core/Services/CoreService.cs b/src/Artemis.Core/Services/CoreService.cs index 434cb9ef4..82c66e1f4 100644 --- a/src/Artemis.Core/Services/CoreService.cs +++ b/src/Artemis.Core/Services/CoreService.cs @@ -6,10 +6,12 @@ namespace Artemis.Core.Services public class CoreService : ICoreService { private readonly IPluginService _pluginService; + private readonly IDeviceService _deviceService; - public CoreService(IPluginService pluginService) + public CoreService(IPluginService pluginService, IDeviceService deviceService) { _pluginService = pluginService; + _deviceService = deviceService; Task.Run(Initialize); } @@ -23,7 +25,7 @@ namespace Artemis.Core.Services private async Task Initialize() { await _pluginService.LoadPlugins(); - + await _deviceService.LoadDevices(); IsInitialized = true; } } diff --git a/src/Artemis.Core/Services/DeviceService.cs b/src/Artemis.Core/Services/DeviceService.cs new file mode 100644 index 000000000..3f45eae4a --- /dev/null +++ b/src/Artemis.Core/Services/DeviceService.cs @@ -0,0 +1,117 @@ +using System; +using System.Threading.Tasks; +using Artemis.Core.Events; +using Artemis.Core.Services.Interfaces; +using RGB.NET.Brushes; +using RGB.NET.Core; +using RGB.NET.Devices.CoolerMaster; +using RGB.NET.Devices.Corsair; +using RGB.NET.Devices.Logitech; +using RGB.NET.Groups; + +namespace Artemis.Core.Services +{ + public class DeviceService : IDeviceService, IDisposable + { + public DeviceService() + { + Surface = RGBSurface.Instance; + LoadingDevices = false; + + // Let's throw these for now + Surface.Exception += SurfaceOnException; + } + + public bool LoadingDevices { get; private set; } + + public RGBSurface Surface { get; set; } + + public async Task LoadDevices() + { + OnStartedLoadingDevices(); + + await Task.Run(() => + { + // TODO SpoinkyNL 8-1-18: Keep settings into account +// Surface.LoadDevices(AsusDeviceProvider.Instance); + Surface.LoadDevices(CorsairDeviceProvider.Instance); + Surface.LoadDevices(LogitechDeviceProvider.Instance); + Surface.LoadDevices(CoolerMasterDeviceProvider.Instance); +// Surface.LoadDevices(NovationDeviceProvider.Instance); + + // TODO SpoinkyNL 8-1-18: Load alignment + Surface.AlignDevies(); + + // Do some testing, why does this work, how does it know I want to target the surface? Check source! + var ledGroup = new RectangleLedGroup(Surface.SurfaceRectangle) + { + Brush = new SolidColorBrush(new Color(255, 0, 0)) {BrushCalculationMode = BrushCalculationMode.Absolute} + }; + Surface.UpdateMode = UpdateMode.Continuous; + }); + + OnFinishedLoadedDevices(); + } + + public void Dispose() + { + Surface.Dispose(); + } + + private void SurfaceOnException(ExceptionEventArgs args) + { + throw args.Exception; + } + + #region Events + + /// + /// Occurs when a single device has loaded + /// + public event EventHandler DeviceLoaded; + + /// + /// Occurs when a single device has reloaded + /// + public event EventHandler DeviceReloaded; + + /// + /// Occurs when loading all devices has started + /// + public event EventHandler StartedLoadingDevices; + + /// + /// Occurs when loading all devices has finished + /// + public event EventHandler FinishedLoadedDevices; + + private void OnDeviceLoaded(DeviceEventArgs e) + { + DeviceLoaded?.Invoke(this, e); + } + + private void OnDeviceReloaded(DeviceEventArgs e) + { + DeviceReloaded?.Invoke(this, e); + } + + private void OnStartedLoadingDevices() + { + LoadingDevices = true; + StartedLoadingDevices?.Invoke(this, EventArgs.Empty); + } + + private void OnFinishedLoadedDevices() + { + LoadingDevices = false; + FinishedLoadedDevices?.Invoke(this, EventArgs.Empty); + } + + #endregion + } + + public interface IDeviceService : IArtemisService + { + Task LoadDevices(); + } +} \ No newline at end of file diff --git a/src/Artemis.UI/Stylet/ArtemisViewManager.cs b/src/Artemis.UI/Stylet/ArtemisViewManager.cs index d77dd6502..f9ab1316d 100644 --- a/src/Artemis.UI/Stylet/ArtemisViewManager.cs +++ b/src/Artemis.UI/Stylet/ArtemisViewManager.cs @@ -1,7 +1,6 @@ using System.IO; using System.Windows; using System.Windows.Markup; -using Artemis.Core.Exceptions; using Artemis.Plugins.Interfaces; using Stylet; @@ -12,7 +11,7 @@ namespace Artemis.UI.Stylet public ArtemisViewManager(ViewManagerConfig config) : base(config) { } - + public override UIElement CreateViewForModel(object model) { if (model is IPluginViewModel) @@ -32,13 +31,6 @@ namespace Artemis.UI.Stylet // Compile the view if found, must be done on UI thread sadly object view = null; Execute.OnUIThread(() => view = XamlReader.Parse(File.ReadAllText(viewPath))); - var viewType = view.GetType(); - // Make sure it's a valid UIElement - if (viewType.IsAbstract || !typeof(UIElement).IsAssignableFrom(viewType)) - { - var e = new ArtemisPluginException(pluginInfo, $"Found type for view: {viewType.Name}, but it wasn't a class derived from UIElement"); - throw e; - } return (UIElement) view; }