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