mirror of
https://github.com/ckaczor/WorkIndicator.git
synced 2026-01-14 01:25:45 -05:00
Handle device removal/addition
This commit is contained in:
@@ -15,11 +15,15 @@ namespace WorkIndicator
|
||||
public static class LightController
|
||||
{
|
||||
private static StoplightIndicator _stoplightIndicator;
|
||||
private static UsbService _usbService;
|
||||
private static bool _initialized;
|
||||
private static Status _status = Status.Auto;
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
_usbService = new UsbService();
|
||||
_usbService.DevicesChanged += DevicesChanged;
|
||||
|
||||
_stoplightIndicator = new StoplightIndicator();
|
||||
_stoplightIndicator.SetLight(StoplightIndicator.Light.Yellow, StoplightIndicator.LightState.On);
|
||||
|
||||
@@ -29,6 +33,14 @@ namespace WorkIndicator
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
private static void DevicesChanged()
|
||||
{
|
||||
_stoplightIndicator?.Dispose();
|
||||
_stoplightIndicator = new StoplightIndicator();
|
||||
|
||||
UpdateLights();
|
||||
}
|
||||
|
||||
private static void AudioWatcher_MicrophoneInUseChanged(bool microphoneInUse)
|
||||
{
|
||||
UpdateLights();
|
||||
@@ -44,6 +56,8 @@ namespace WorkIndicator
|
||||
_stoplightIndicator.SetLights(StoplightIndicator.LightState.Off, StoplightIndicator.LightState.Off, StoplightIndicator.LightState.Off);
|
||||
_stoplightIndicator.Dispose();
|
||||
|
||||
_usbService.Dispose();
|
||||
|
||||
_initialized = false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user