diff --git a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs
index 27c1472..f87eede 100644
--- a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs
+++ b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs
@@ -1,4 +1,7 @@
-using System;
+// ReSharper disable MemberCanBePrivate.Global
+// ReSharper disable UnusedMember.Global
+
+using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
@@ -16,10 +19,11 @@ namespace RGB.NET.Devices.CoolerMaster
{
#region Properties & Fields
+ private static CoolerMasterDeviceProvider _instance;
///
/// Gets the singleton instance.
///
- public static CoolerMasterDeviceProvider Instance { get; } = new CoolerMasterDeviceProvider();
+ public static CoolerMasterDeviceProvider Instance => _instance ?? new CoolerMasterDeviceProvider();
///
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
@@ -60,8 +64,15 @@ namespace RGB.NET.Devices.CoolerMaster
#region Constructors
- private CoolerMasterDeviceProvider()
- { }
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Thrown if this constructor is called even if there is already an instance of this class.
+ public CoolerMasterDeviceProvider()
+ {
+ if (_instance != null) throw new InvalidOperationException($"There can be only one instanc of type {nameof(CoolerMasterDeviceProvider)}");
+ _instance = this;
+ }
#endregion
diff --git a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs
index d9d0f28..d1bbdb4 100644
--- a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs
+++ b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs
@@ -1,6 +1,7 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
+using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Runtime.InteropServices;
@@ -17,10 +18,11 @@ namespace RGB.NET.Devices.Corsair
{
#region Properties & Fields
+ private static CorsairDeviceProvider _instance;
///
/// Gets the singleton instance.
///
- public static CorsairDeviceProvider Instance { get; } = new CorsairDeviceProvider();
+ public static CorsairDeviceProvider Instance => _instance ?? new CorsairDeviceProvider();
///
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
@@ -66,8 +68,15 @@ namespace RGB.NET.Devices.Corsair
#region Constructors
- private CorsairDeviceProvider()
- { }
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Thrown if this constructor is called even if there is already an instance of this class.
+ public CorsairDeviceProvider()
+ {
+ if (_instance != null) throw new InvalidOperationException($"There can be only one instanc of type {nameof(CorsairDeviceProvider)}");
+ _instance = this;
+ }
#endregion
diff --git a/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs b/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs
index 1d9a4c0..f3071b4 100644
--- a/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs
+++ b/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs
@@ -1,4 +1,7 @@
-using System;
+// ReSharper disable MemberCanBePrivate.Global
+// ReSharper disable UnusedMember.Global
+
+using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
@@ -15,10 +18,11 @@ namespace RGB.NET.Devices.Logitech
{
#region Properties & Fields
+ private static LogitechDeviceProvider _instance;
///
/// Gets the singleton instance.
///
- public static LogitechDeviceProvider Instance { get; } = new LogitechDeviceProvider();
+ public static LogitechDeviceProvider Instance => _instance ?? new LogitechDeviceProvider();
///
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
@@ -55,8 +59,15 @@ namespace RGB.NET.Devices.Logitech
#region Constructors
- private LogitechDeviceProvider()
- { }
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Thrown if this constructor is called even if there is already an instance of this class.
+ public LogitechDeviceProvider()
+ {
+ if (_instance != null) throw new InvalidOperationException($"There can be only one instanc of type {nameof(LogitechDeviceProvider)}");
+ _instance = this;
+ }
#endregion
diff --git a/RGB.NET.WPF/Controls/RGBSurfaceVisualizer.cs b/RGB.NET.WPF/Controls/RGBSurfaceVisualizer.cs
index 8881eba..51a3e07 100644
--- a/RGB.NET.WPF/Controls/RGBSurfaceVisualizer.cs
+++ b/RGB.NET.WPF/Controls/RGBSurfaceVisualizer.cs
@@ -1,4 +1,5 @@
-using System.Windows;
+using System.Collections.Generic;
+using System.Windows;
using System.Windows.Controls;
using RGB.NET.Core;
@@ -21,6 +22,9 @@ namespace RGB.NET.WPF.Controls
private RGBSurface _surface;
private Canvas _canvas;
+ //TODO DarthAffe 17.06.2017: This is ugly - redesign how device connect/disconnect is generally handled!
+ private readonly List _newDevices = new List();
+
#endregion
#region Constructors
@@ -29,22 +33,36 @@ namespace RGB.NET.WPF.Controls
/// Initializes a new instance of the class.
///
public RGBSurfaceVisualizer()
+ {
+ this.Loaded += OnLoaded;
+ this.Unloaded += OnUnloaded;
+ }
+
+ private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
{
_surface = RGBSurface.Instance;
_surface.SurfaceLayoutChanged += RGBSurfaceOnSurfaceLayoutChanged;
foreach (IRGBDevice device in _surface.Devices)
- AddDevice(device);
+ _newDevices.Add(device);
+
+ UpdateSurface();
+ }
+
+ private void OnUnloaded(object sender, RoutedEventArgs routedEventArgs)
+ {
+ _surface.SurfaceLayoutChanged -= RGBSurfaceOnSurfaceLayoutChanged;
+ _canvas?.Children.Clear();
+ _newDevices.Clear();
}
private void RGBSurfaceOnSurfaceLayoutChanged(SurfaceLayoutChangedEventArgs args)
{
if (args.DeviceAdded)
foreach (IRGBDevice device in args.Devices)
- AddDevice(device);
+ _newDevices.Add(device);
- _canvas.Width = _surface.SurfaceRectangle.Size.Width;
- _canvas.Height = _surface.SurfaceRectangle.Size.Height;
+ UpdateSurface();
}
#endregion
@@ -54,12 +72,21 @@ namespace RGB.NET.WPF.Controls
///
public override void OnApplyTemplate()
{
+ _canvas?.Children.Clear();
_canvas = (Canvas)GetTemplateChild(PART_CANVAS);
+ UpdateSurface();
}
- private void AddDevice(IRGBDevice device)
+ private void UpdateSurface()
{
- _canvas.Children.Add(new RGBDeviceVisualizer { Device = device });
+ if ((_canvas == null) || (_newDevices.Count == 0)) return;
+
+ foreach (IRGBDevice device in _newDevices)
+ _canvas.Children.Add(new RGBDeviceVisualizer { Device = device });
+ _newDevices.Clear();
+
+ _canvas.Width = _surface.SurfaceRectangle.Size.Width;
+ _canvas.Height = _surface.SurfaceRectangle.Size.Height;
}
#endregion