Compare commits
No commits in common. "f9b23a62a36fa62d0e18784eb8f830b2fdad274e" and "1fea2a2e1186d258193aeb309872e167b9f388b7" have entirely different histories.
f9b23a62a3
...
1fea2a2e11
@ -54,14 +54,6 @@ public class AudioHelper
|
||||
|
||||
static object _lock = new object();
|
||||
|
||||
public void ResetCache()
|
||||
{
|
||||
lock(_lock)
|
||||
{
|
||||
_current = null;
|
||||
}
|
||||
}
|
||||
|
||||
public IAudioSession GetActiveSession(FallbackBehavior fallbackBehavior)
|
||||
{
|
||||
lock (_lock)
|
||||
@ -75,11 +67,11 @@ public class AudioHelper
|
||||
|
||||
if(_current == null)
|
||||
{
|
||||
if(fallbackBehavior == FallbackBehavior.SystemSounds && _current is not SystemSoundsAudioSession)
|
||||
if(fallbackBehavior == FallbackBehavior.SystemSounds)
|
||||
{
|
||||
_current = GetSystemSounds();
|
||||
}
|
||||
else if(fallbackBehavior == FallbackBehavior.SystemVolume && _current is not SystemVolumeAudioSession)
|
||||
else if(fallbackBehavior == FallbackBehavior.SystemVolume)
|
||||
{
|
||||
_current = GetSystemVolume();
|
||||
}
|
||||
|
@ -73,56 +73,54 @@ public class DialAction : EncoderBase
|
||||
_ = UpdateStateIfNeeded();
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
Logger.Instance.LogMessage(TracingLevel.DEBUG, "Disposing");
|
||||
if (_foregroundWindowChangedEvent != IntPtr.Zero)
|
||||
{
|
||||
Native.UnhookWinEvent(_foregroundWindowChangedEvent);
|
||||
}
|
||||
_dispatcher.InvokeShutdown();
|
||||
}
|
||||
|
||||
public override async void DialDown(DialPayload payload)
|
||||
{
|
||||
try
|
||||
{
|
||||
//dial pressed down
|
||||
Logger.Instance.LogMessage(TracingLevel.INFO, "Dial Down");
|
||||
await ToggleMuteAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Instance.LogMessage(TracingLevel.ERROR, $"Unexpected Error in DialDown:\n {ex}");
|
||||
}
|
||||
}
|
||||
public override void DialUp(DialPayload payload) { }
|
||||
|
||||
public override async void TouchPress(TouchpadPressPayload payload)
|
||||
{
|
||||
try
|
||||
{
|
||||
Logger.Instance.LogMessage(TracingLevel.INFO, "Touch Press");
|
||||
if (payload.IsLongPress)
|
||||
{
|
||||
await ResetAllAsync();
|
||||
_audioHelper.ResetAll();
|
||||
}
|
||||
else
|
||||
{
|
||||
await ToggleMuteAsync();
|
||||
}
|
||||
}
|
||||
|
||||
async Task ToggleMuteAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
if (_currentAudioSession != null)
|
||||
{
|
||||
_currentAudioSession.ToggleMute();
|
||||
await UpdateStateIfNeeded();
|
||||
}
|
||||
else
|
||||
{
|
||||
await Connection.ShowAlert();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Instance.LogMessage(TracingLevel.ERROR, $"Unexpected Error in TouchPress:\n {ex}");
|
||||
await Connection.ShowAlert();
|
||||
Logger.Instance.LogMessage(TracingLevel.ERROR, $"Unable to toggle mute: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public override async void DialRotate(DialRotatePayload payload)
|
||||
{
|
||||
try
|
||||
{
|
||||
Logger.Instance.LogMessage(TracingLevel.INFO, "Dial Rotate");
|
||||
//dial rotated. ticks positive for right, negative for left
|
||||
try
|
||||
{
|
||||
if (_currentAudioSession != null)
|
||||
{
|
||||
_currentAudioSession.IncrementVolumeLevel(settings.StepSize, payload.Ticks);
|
||||
@ -135,46 +133,24 @@ public class DialAction : EncoderBase
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_audioHelper.ResetCache();
|
||||
await Connection.ShowAlert();
|
||||
Logger.Instance.LogMessage(TracingLevel.ERROR, $"Unable to increment volume:\n {ex}");
|
||||
Logger.Instance.LogMessage(TracingLevel.ERROR, $"Unable to toggle mute: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
async Task ResetAllAsync()
|
||||
public override void DialUp(DialPayload payload)
|
||||
{
|
||||
try
|
||||
{
|
||||
_audioHelper.ResetAll();
|
||||
}
|
||||
catch
|
||||
{
|
||||
_audioHelper.ResetCache();
|
||||
await Connection.ShowAlert();
|
||||
throw;
|
||||
}
|
||||
//dial unpressed
|
||||
}
|
||||
|
||||
async Task ToggleMuteAsync()
|
||||
public override void Dispose()
|
||||
{
|
||||
try
|
||||
Logger.Instance.LogMessage(TracingLevel.DEBUG, "Disposing");
|
||||
if (_foregroundWindowChangedEvent != IntPtr.Zero)
|
||||
{
|
||||
if (_currentAudioSession != null)
|
||||
{
|
||||
_currentAudioSession.ToggleMute();
|
||||
await UpdateStateIfNeeded();
|
||||
}
|
||||
else
|
||||
{
|
||||
await Connection.ShowAlert();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
_audioHelper.ResetCache();
|
||||
await Connection.ShowAlert();
|
||||
throw;
|
||||
Native.UnhookWinEvent(_foregroundWindowChangedEvent);
|
||||
}
|
||||
_dispatcher.InvokeShutdown();
|
||||
}
|
||||
|
||||
public override async void OnTick()
|
||||
@ -193,8 +169,7 @@ public class DialAction : EncoderBase
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_audioHelper.ResetCache();
|
||||
Logger.Instance.LogMessage(TracingLevel.ERROR, $"Exception on Tick:\n {ex}");
|
||||
Logger.Instance.LogMessage(TracingLevel.ERROR, $"Exception on WinEventProc\n {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,6 +177,7 @@ public class DialAction : EncoderBase
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
if (_currentAudioSession != null)
|
||||
{
|
||||
|
||||
@ -224,7 +200,7 @@ public class DialAction : EncoderBase
|
||||
_previousState = uiState;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception ex )
|
||||
{
|
||||
Logger.Instance.LogMessage(TracingLevel.ERROR, $"Failed to update screen\n {ex}");
|
||||
}
|
||||
@ -237,40 +213,20 @@ public class DialAction : EncoderBase
|
||||
|
||||
|
||||
public override void ReceivedSettings(ReceivedSettingsPayload payload)
|
||||
{
|
||||
try
|
||||
{
|
||||
Tools.AutoPopulateSettings(settings, payload.Settings);
|
||||
SaveSettings();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Instance.LogMessage(TracingLevel.ERROR, $"Unexpected Error in SaveSettings:\n {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SaveSettings()
|
||||
private Task SaveSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
await Connection.SetSettingsAsync(JObject.FromObject(settings));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Instance.LogMessage(TracingLevel.ERROR, $"Unexpected Error in SaveSettings:\n {ex}");
|
||||
}
|
||||
return Connection.SetSettingsAsync(JObject.FromObject(settings));
|
||||
}
|
||||
|
||||
|
||||
public void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
|
||||
{
|
||||
try
|
||||
{
|
||||
OnTick();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Instance.LogMessage(TracingLevel.ERROR, $"Unexpected Error in DialDown:\n {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user