Compare commits
4 Commits
84a9a89074
...
v1.1.0
Author | SHA1 | Date | |
---|---|---|---|
f9b23a62a3 | |||
06266daa92 | |||
1fea2a2e11 | |||
2e44a27b2b |
@ -54,6 +54,14 @@ public class AudioHelper
|
|||||||
|
|
||||||
static object _lock = new object();
|
static object _lock = new object();
|
||||||
|
|
||||||
|
public void ResetCache()
|
||||||
|
{
|
||||||
|
lock(_lock)
|
||||||
|
{
|
||||||
|
_current = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public IAudioSession GetActiveSession(FallbackBehavior fallbackBehavior)
|
public IAudioSession GetActiveSession(FallbackBehavior fallbackBehavior)
|
||||||
{
|
{
|
||||||
lock (_lock)
|
lock (_lock)
|
||||||
@ -67,11 +75,11 @@ public class AudioHelper
|
|||||||
|
|
||||||
if(_current == null)
|
if(_current == null)
|
||||||
{
|
{
|
||||||
if(fallbackBehavior == FallbackBehavior.SystemSounds)
|
if(fallbackBehavior == FallbackBehavior.SystemSounds && _current is not SystemSoundsAudioSession)
|
||||||
{
|
{
|
||||||
_current = GetSystemSounds();
|
_current = GetSystemSounds();
|
||||||
}
|
}
|
||||||
else if(fallbackBehavior == FallbackBehavior.SystemVolume)
|
else if(fallbackBehavior == FallbackBehavior.SystemVolume && _current is not SystemVolumeAudioSession)
|
||||||
{
|
{
|
||||||
_current = GetSystemVolume();
|
_current = GetSystemVolume();
|
||||||
}
|
}
|
||||||
|
@ -70,56 +70,59 @@ public class DialAction : EncoderBase
|
|||||||
_thread.Start();
|
_thread.Start();
|
||||||
|
|
||||||
_currentAudioSession = settings.FallbackBehavior == FallbackBehavior.SystemSounds ? _audioHelper.GetSystemSounds() : _audioHelper.GetSystemVolume();
|
_currentAudioSession = settings.FallbackBehavior == FallbackBehavior.SystemSounds ? _audioHelper.GetSystemSounds() : _audioHelper.GetSystemVolume();
|
||||||
|
_ = 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)
|
public override async void DialDown(DialPayload payload)
|
||||||
{
|
{
|
||||||
//dial pressed down
|
try
|
||||||
Logger.Instance.LogMessage(TracingLevel.INFO, "Dial Down");
|
{
|
||||||
await ToggleMuteAsync();
|
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)
|
public override async void TouchPress(TouchpadPressPayload payload)
|
||||||
{
|
|
||||||
Logger.Instance.LogMessage(TracingLevel.INFO, "Touch Press");
|
|
||||||
if (payload.IsLongPress)
|
|
||||||
{
|
|
||||||
_audioHelper.ResetAll();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
await ToggleMuteAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async Task ToggleMuteAsync()
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Logger.Instance.LogMessage(TracingLevel.INFO, "Touch Press");
|
||||||
if (_currentAudioSession != null)
|
if (payload.IsLongPress)
|
||||||
{
|
{
|
||||||
_currentAudioSession.ToggleMute();
|
await ResetAllAsync();
|
||||||
await UpdateStateIfNeeded();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await Connection.ShowAlert();
|
await ToggleMuteAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
await Connection.ShowAlert();
|
Logger.Instance.LogMessage(TracingLevel.ERROR, $"Unexpected Error in TouchPress:\n {ex}");
|
||||||
Logger.Instance.LogMessage(TracingLevel.ERROR, $"Unable to toggle mute: {ex.Message}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async void DialRotate(DialRotatePayload payload)
|
public override async void DialRotate(DialRotatePayload payload)
|
||||||
{
|
{
|
||||||
Logger.Instance.LogMessage(TracingLevel.INFO, "Dial Rotate");
|
|
||||||
//dial rotated. ticks positive for right, negative for left
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Logger.Instance.LogMessage(TracingLevel.INFO, "Dial Rotate");
|
||||||
|
//dial rotated. ticks positive for right, negative for left
|
||||||
if (_currentAudioSession != null)
|
if (_currentAudioSession != null)
|
||||||
{
|
{
|
||||||
_currentAudioSession.IncrementVolumeLevel(settings.StepSize, payload.Ticks);
|
_currentAudioSession.IncrementVolumeLevel(settings.StepSize, payload.Ticks);
|
||||||
@ -132,24 +135,46 @@ public class DialAction : EncoderBase
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
_audioHelper.ResetCache();
|
||||||
await Connection.ShowAlert();
|
await Connection.ShowAlert();
|
||||||
Logger.Instance.LogMessage(TracingLevel.ERROR, $"Unable to toggle mute: {ex.Message}");
|
Logger.Instance.LogMessage(TracingLevel.ERROR, $"Unable to increment volume:\n {ex}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DialUp(DialPayload payload)
|
async Task ResetAllAsync()
|
||||||
{
|
{
|
||||||
//dial unpressed
|
try
|
||||||
}
|
|
||||||
|
|
||||||
public override void Dispose()
|
|
||||||
{
|
|
||||||
Logger.Instance.LogMessage(TracingLevel.DEBUG, "Disposing");
|
|
||||||
if (_foregroundWindowChangedEvent != IntPtr.Zero)
|
|
||||||
{
|
{
|
||||||
Native.UnhookWinEvent(_foregroundWindowChangedEvent);
|
_audioHelper.ResetAll();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
_audioHelper.ResetCache();
|
||||||
|
await Connection.ShowAlert();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task ToggleMuteAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_currentAudioSession != null)
|
||||||
|
{
|
||||||
|
_currentAudioSession.ToggleMute();
|
||||||
|
await UpdateStateIfNeeded();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await Connection.ShowAlert();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
_audioHelper.ResetCache();
|
||||||
|
await Connection.ShowAlert();
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
_dispatcher.InvokeShutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async void OnTick()
|
public override async void OnTick()
|
||||||
@ -168,32 +193,40 @@ public class DialAction : EncoderBase
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logger.Instance.LogMessage(TracingLevel.ERROR, $"Exception on WinEventProc\n {ex}");
|
_audioHelper.ResetCache();
|
||||||
|
Logger.Instance.LogMessage(TracingLevel.ERROR, $"Exception on Tick:\n {ex}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task UpdateStateIfNeeded()
|
private async Task UpdateStateIfNeeded()
|
||||||
{
|
{
|
||||||
if (_currentAudioSession != null)
|
try
|
||||||
{
|
{
|
||||||
|
if (_currentAudioSession != null)
|
||||||
var uiState = new UIState(_currentAudioSession);
|
|
||||||
|
|
||||||
if (_previousState != null && uiState != null &&
|
|
||||||
uiState.Title == _previousState.Title &&
|
|
||||||
uiState.Value.Value == _previousState.Value.Value &&
|
|
||||||
uiState.Value.Opacity == _previousState.Value.Opacity &&
|
|
||||||
uiState.Indicator.Value == _previousState.Indicator.Value &&
|
|
||||||
uiState.Indicator.Opacity == _previousState.Indicator.Opacity &&
|
|
||||||
uiState.icon.Value == _previousState.icon.Value &&
|
|
||||||
uiState.icon.Opacity == _previousState.icon.Opacity
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await Connection.SetFeedbackAsync(uiState);
|
var uiState = new UIState(_currentAudioSession);
|
||||||
_previousState = uiState;
|
|
||||||
|
if (_previousState != null && uiState != null &&
|
||||||
|
uiState.Title == _previousState.Title &&
|
||||||
|
uiState.Value.Value == _previousState.Value.Value &&
|
||||||
|
uiState.Value.Opacity == _previousState.Value.Opacity &&
|
||||||
|
uiState.Indicator.Value == _previousState.Indicator.Value &&
|
||||||
|
uiState.Indicator.Opacity == _previousState.Indicator.Opacity &&
|
||||||
|
uiState.icon.Value == _previousState.icon.Value &&
|
||||||
|
uiState.icon.Opacity == _previousState.icon.Opacity
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await Connection.SetFeedbackAsync(uiState);
|
||||||
|
_previousState = uiState;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.Instance.LogMessage(TracingLevel.ERROR, $"Failed to update screen\n {ex}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,19 +238,39 @@ public class DialAction : EncoderBase
|
|||||||
|
|
||||||
public override void ReceivedSettings(ReceivedSettingsPayload payload)
|
public override void ReceivedSettings(ReceivedSettingsPayload payload)
|
||||||
{
|
{
|
||||||
Tools.AutoPopulateSettings(settings, payload.Settings);
|
try
|
||||||
SaveSettings();
|
{
|
||||||
|
Tools.AutoPopulateSettings(settings, payload.Settings);
|
||||||
|
SaveSettings();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.Instance.LogMessage(TracingLevel.ERROR, $"Unexpected Error in SaveSettings:\n {ex}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task SaveSettings()
|
private async Task SaveSettings()
|
||||||
{
|
{
|
||||||
return Connection.SetSettingsAsync(JObject.FromObject(settings));
|
try
|
||||||
|
{
|
||||||
|
await Connection.SetSettingsAsync(JObject.FromObject(settings));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.Instance.LogMessage(TracingLevel.ERROR, $"Unexpected Error in SaveSettings:\n {ex}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
OnTick();
|
try
|
||||||
|
{
|
||||||
|
OnTick();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.Instance.LogMessage(TracingLevel.ERROR, $"Unexpected Error in DialDown:\n {ex}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
"Name": "Focused Application Volume",
|
"Name": "Focused Application Volume",
|
||||||
"Description": "Control the volume of the focused application",
|
"Description": "Control the volume of the focused application",
|
||||||
"URL": "https://github.com/dlprows/FocusVolumeControl",
|
"URL": "https://github.com/dlprows/FocusVolumeControl",
|
||||||
"Version": "1.0.1",
|
"Version": "1.1.0",
|
||||||
"CodePath": "FocusVolumeControl",
|
"CodePath": "FocusVolumeControl",
|
||||||
"Category": "Volume Control [dlprows]",
|
"Category": "Volume Control [dlprows]",
|
||||||
"Icon": "Images/pluginIcon",
|
"Icon": "Images/pluginIcon",
|
||||||
|
Reference in New Issue
Block a user