Add settings for fallback behavior

update action icon with padding
This commit is contained in:
2023-08-20 20:52:48 -06:00
parent 1dc8ab8a2d
commit 90c014e932
24 changed files with 760 additions and 786 deletions

View File

@ -0,0 +1,82 @@
using CoreAudio;
using System;
using System.Collections.Generic;
using System.Linq;
using BarRaider.SdTools;
using System.Drawing;
namespace FocusVolumeControl.AudioSessions;
public class ActiveAudioSessionWrapper : IAudioSession
{
public string DisplayName { get; set; }
public string ExecutablePath { get; set; }
private List<SimpleAudioVolume> Volume { get; } = new List<SimpleAudioVolume>();
string _icon;
public string GetIcon()
{
if (string.IsNullOrEmpty(_icon))
{
try
{
var tmp = Icon.ExtractAssociatedIcon(ExecutablePath);
_icon = Tools.ImageToBase64(tmp.ToBitmap(), true);
}
catch
{
_icon = "Image/pluginIcon.png";
}
}
return _icon;
}
public bool Any()
{
return Volume.Any();
}
public int Count => Volume.Count;
public void AddVolume(SimpleAudioVolume volume)
{
Volume.Add(volume);
}
public void ToggleMute()
{
//when all volumes are muted, Volume.All will return true
//so we swap from muted to false (opposite of Volume.All)
//when any volumes are unmuted, Volume.All will return false
//so we set muted to true (opposite of Volume.All)
var muted = Volume.All(x => x.Mute);
Volume.ForEach(x => x.Mute = !muted);
}
public bool IsMuted()
{
return Volume.All(x => x.Mute);
}
public void IncrementVolumeLevel(int step, int ticks)
{
//if you have more than one volume. they will all get set based on the first volume control
var level = Volume.FirstOrDefault()?.MasterVolume ?? 0;
level += (0.01f * step) * ticks;
level = Math.Max(level, 0);
level = Math.Min(level, 1);
Volume.ForEach(x => x.MasterVolume = level);
}
public int GetVolumeLevel()
{
var level = Volume.FirstOrDefault()?.MasterVolume ?? 0;
return (int)(level * 100);
}
}

View File

@ -0,0 +1,16 @@
namespace FocusVolumeControl.AudioSessions;
public interface IAudioSession
{
public string DisplayName { get; }
public string GetIcon();
public void ToggleMute();
public bool IsMuted();
public void IncrementVolumeLevel(int step, int ticks);
public int GetVolumeLevel();
}

View File

@ -0,0 +1,38 @@
using CoreAudio;
using System;
namespace FocusVolumeControl.AudioSessions;
internal class SystemSoundsAudioSession : IAudioSession
{
public SystemSoundsAudioSession(SimpleAudioVolume volumeControl)
{
_volumeControl = volumeControl;
}
SimpleAudioVolume _volumeControl;
public string DisplayName => "System sounds";
public string GetIcon() => "Images/systemSounds";
public void ToggleMute()
{
_volumeControl.Mute = !_volumeControl.Mute;
}
public bool IsMuted() => _volumeControl.Mute;
public void IncrementVolumeLevel(int step, int ticks)
{
var level = _volumeControl.MasterVolume;
level += (0.01f * step) * ticks;
level = Math.Max(level, 0);
level = Math.Min(level, 1);
_volumeControl.MasterVolume = level;
}
public int GetVolumeLevel() => (int)(_volumeControl.MasterVolume * 100);
}

View File

@ -0,0 +1,38 @@
using CoreAudio;
using System;
namespace FocusVolumeControl.AudioSessions;
internal class SystemVolumeAudioSession : IAudioSession
{
public SystemVolumeAudioSession(AudioEndpointVolume volumeControl)
{
_volumeControl = volumeControl;
}
AudioEndpointVolume _volumeControl;
public string DisplayName => "System Volume";
public string GetIcon() => "Images/actionIcon";
public void ToggleMute()
{
_volumeControl.Mute = !_volumeControl.Mute;
}
public bool IsMuted() => _volumeControl.Mute;
public void IncrementVolumeLevel(int step, int ticks)
{
var level = _volumeControl.MasterVolumeLevelScalar;
level += (0.01f * step) * ticks;
level = Math.Max(level, 0);
level = Math.Min(level, 1);
_volumeControl.MasterVolumeLevelScalar = level;
}
public int GetVolumeLevel() => (int)(_volumeControl.MasterVolumeLevelScalar * 100);
}