Move try catch, because i had issues with it throwing when doing the tick - oops

This commit is contained in:
dlprows 2023-09-10 22:05:11 -06:00
parent f0a5a48c73
commit 0d056215bc

View File

@ -137,30 +137,36 @@ public class DialAction : EncoderBase
public override void DialUp(DialPayload payload)
{
//dial unpressed
Logger.Instance.LogMessage(TracingLevel.INFO, "Dial Up");
}
public override void Dispose()
{
Logger.Instance.LogMessage(TracingLevel.DEBUG, "Disposing");
if(_foregroundWindowChangedEvent != IntPtr.Zero)
{
Native.UnhookWinEvent(_foregroundWindowChangedEvent);
}
if (_foregroundWindowChangedEvent != IntPtr.Zero)
{
Native.UnhookWinEvent(_foregroundWindowChangedEvent);
}
_dispatcher.InvokeShutdown();
}
public override async void OnTick()
{
//called once every 1000ms and can be used for updating the title/image of the key
var activeSession = _audioHelper.GetActiveSession(settings.FallbackBehavior);
if(activeSession != null)
try
{
_currentAudioSession = activeSession;
}
//called once every 1000ms and can be used for updating the title/image of the key
var activeSession = _audioHelper.GetActiveSession(settings.FallbackBehavior);
await UpdateStateIfNeeded();
if (activeSession != null)
{
_currentAudioSession = activeSession;
}
await UpdateStateIfNeeded();
}
catch (Exception ex)
{
Logger.Instance.LogMessage(TracingLevel.ERROR, $"Exception on WinEventProc\n {ex}");
}
}
private async Task UpdateStateIfNeeded()
@ -170,7 +176,7 @@ public class DialAction : EncoderBase
var uiState = new UIState(_currentAudioSession);
if ( _previousState != null && uiState != null &&
if (_previousState != null && uiState != null &&
uiState.Title == _previousState.Title &&
uiState.Value.Value == _previousState.Value.Value &&
uiState.Value.Opacity == _previousState.Value.Opacity &&
@ -208,15 +214,7 @@ public class DialAction : EncoderBase
public void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
{
try
{
OnTick();
Thread.Sleep(TimeSpan.FromSeconds(1));
}
catch (Exception ex)
{
Logger.Instance.LogMessage(TracingLevel.ERROR, $"Exception on WinEventProc\n {ex}");
}
OnTick();
}
}