From fc4368af87f62635ae54cb00c1a080b0b3546d51 Mon Sep 17 00:00:00 2001 From: Chris Kaczor Date: Tue, 31 Mar 2015 14:26:43 -0400 Subject: [PATCH] Workaround for Skype API events no longer working --- Delcom/StoplightIndicator.cs | 3 +++ LightController.cs | 24 ++++++++++++++++++++++-- Properties/Settings.Designer.cs | 11 ++++++++++- Properties/Settings.settings | 3 +++ app.config | 3 +++ 5 files changed, 41 insertions(+), 3 deletions(-) diff --git a/Delcom/StoplightIndicator.cs b/Delcom/StoplightIndicator.cs index 3f9d9cb..ab23f7f 100644 --- a/Delcom/StoplightIndicator.cs +++ b/Delcom/StoplightIndicator.cs @@ -71,6 +71,9 @@ namespace WorkIndicator.Delcom public void SetLights(LightState red, LightState yellow, LightState green) { + if (_red == red && _yellow == yellow && _green == green) + return; + int port1 = 0; _red = red; diff --git a/LightController.cs b/LightController.cs index 633f205..e80b9e0 100644 --- a/LightController.cs +++ b/LightController.cs @@ -24,6 +24,7 @@ namespace WorkIndicator private static bool _initialized; private static Status _status = Status.Auto; private static Timer _retryTimer; + private static Timer _updateTimer; public static void Initialize() { @@ -33,6 +34,10 @@ namespace WorkIndicator InitializeWindowDetection(); InitializeSkypeDetection(); + _updateTimer = new Timer(Properties.Settings.Default.UpdateInterval.TotalMilliseconds) { AutoReset = false }; + _updateTimer.Elapsed += HandleUpdateTimerElapsed; + _updateTimer.Start(); + _initialized = true; } @@ -41,6 +46,8 @@ namespace WorkIndicator if (!_initialized) return; + _updateTimer.Dispose(); + TerminateWindowDetection(); TerminateSkypeDetection(); @@ -118,10 +125,16 @@ namespace WorkIndicator _skype = new Skype(); _skype.Attach(); + var skype = (ISkype) _skype; + skype.Mute = !skype.Mute; + skype.Mute = !skype.Mute; + _ISkypeEvents_Event skypeEvents = _skype; skypeEvents.CallStatus += HandleSkypeCallStatus; skypeEvents.Mute += HandleSkypeEventsMute; + + UpdateLights(); } catch (Exception) { @@ -140,12 +153,19 @@ namespace WorkIndicator InitializeSkypeDetection(); } - static void HandleSkypeEventsMute(bool mute) + private static void HandleUpdateTimerElapsed(object sender, ElapsedEventArgs e) + { + UpdateLights(); + + _updateTimer.Start(); + } + + private static void HandleSkypeEventsMute(bool mute) { UpdateLights(); } - static void HandleSkypeCallStatus(Call call, TCallStatus status) + private static void HandleSkypeCallStatus(Call call, TCallStatus status) { UpdateLights(); } diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs index a4f363f..f3d048d 100644 --- a/Properties/Settings.Designer.cs +++ b/Properties/Settings.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.34209 +// Runtime Version:4.0.30319.0 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -55,5 +55,14 @@ namespace WorkIndicator.Properties { return ((global::System.TimeSpan)(this["RetryInterval"])); } } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("00:00:00.5000000")] + public global::System.TimeSpan UpdateInterval { + get { + return ((global::System.TimeSpan)(this["UpdateInterval"])); + } + } } } diff --git a/Properties/Settings.settings b/Properties/Settings.settings index 930dcb3..3568384 100644 --- a/Properties/Settings.settings +++ b/Properties/Settings.settings @@ -11,5 +11,8 @@ 00:00:10 + + 00:00:00.5000000 + \ No newline at end of file diff --git a/app.config b/app.config index 6e48c60..c196370 100644 --- a/app.config +++ b/app.config @@ -23,6 +23,9 @@ 00:00:10 + + 00:00:00.5000000 +