github-15 - add ability to ignore processes

This commit is contained in:
dlprows 2025-01-25 16:51:28 -07:00
parent cd306b0aab
commit d8b4bf340b
5 changed files with 76 additions and 0 deletions

View File

@ -17,6 +17,7 @@ public class AudioHelper
int _retryFallbackCount = 0;
public List<Override> Overrides { get; set; }
public List<string> Ignored { get; set; }
public IAudioSession Current { get; private set; }
@ -224,6 +225,11 @@ public class AudioHelper
return new List<Process>();
}
if(processes.Any(x => Ignored.Contains(x.ProcessName)))
{
return new List<Process>();
}
try
{
//note. in instances where you launch a game from steam. this ends up mapping the process to both steam and to the game. which is unfortunate

View File

@ -33,12 +33,16 @@ public class DialAction : EncoderBase
[JsonProperty("overrides")]
public string Overrides { get; set; }
[JsonProperty("ignored")]
public string Ignored { get; set; }
public static PluginSettings CreateDefaultSettings()
{
PluginSettings instance = new PluginSettings();
instance.FallbackBehavior = FallbackBehavior.SystemSounds;
instance.StepSize = 1;
instance.Overrides = DefaultOverrides;
instance.Ignored = "";
return instance;
}
}
@ -57,9 +61,20 @@ public class DialAction : EncoderBase
else
{
settings = payload.Settings.ToObject<PluginSettings>();
bool save = false;
if(string.IsNullOrEmpty(settings.Overrides))
{
settings.Overrides = DefaultOverrides;
save = true;
}
if(string.IsNullOrEmpty(settings.Ignored))
{
settings.Ignored = "";
save = true;
}
if(save)
{
_ = SaveSettings();
}
}
@ -69,6 +84,7 @@ public class DialAction : EncoderBase
try
{
_audioHelper.Overrides = OverrideParser.Parse(settings.Overrides);
_audioHelper.Ignored = IgnoreParser.Parse(settings.Ignored);
//just in case we fail to get the active session, don't prevent the plugin from launching
var session = _audioHelper.GetActiveSession(settings.FallbackBehavior);
_ = UpdateStateIfNeeded(session);
@ -238,6 +254,7 @@ public class DialAction : EncoderBase
{
Tools.AutoPopulateSettings(settings, payload.Settings);
_audioHelper.Overrides = OverrideParser.Parse(settings.Overrides);
_audioHelper.Ignored = IgnoreParser.Parse(settings.Ignored);
//_ = SaveSettings();
}
catch (Exception ex)

View File

@ -67,6 +67,7 @@
<Compile Include="FallbackBehavior.cs" />
<Compile Include="AudioHelpers\NameAndIconHelper.cs" />
<Compile Include="InternalsVisibleTo.cs" />
<Compile Include="Overrides\IgnoreParser.cs" />
<Compile Include="Overrides\Override.cs" />
<Compile Include="Overrides\MatchType.cs" />
<Compile Include="Overrides\OverrideParser.cs" />

View File

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FocusVolumeControl.Overrides
{
internal class IgnoreParser
{
public static List<string> Parse(string raw)
{
var ignores = new List<string>();
if (raw == null)
{
return ignores;
}
var lines = raw.Split(new[] { "\r\n", "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries);
foreach (var line in lines)
{
if (string.IsNullOrEmpty(line) || line.StartsWith("//"))
{
continue;
}
var str = line.Trim();
ignores.Add(line.Trim());
}
return ignores;
}
}
}

View File

@ -61,6 +61,22 @@
</details>
<div type="textarea" class="sdpi-item">
<div class="sdpi-item-label">Ignored</div>
<span class="sdpi-item-value" textarea>
<textarea type="textarea" class="sdProperty" id="ignored" oninput="setSettings()"></textarea>
</span>
</div>
<details>
<summary>Ignored Details</summary>
<p>Sometimes you may not want certain processes to be controlable.</p>
<p>In this case, you can add a list of process names which will be ignored.</p>
<p>ex:<br /> chrome</p>
<p>Blank lines can be used for spacing<br/>Lines starting with // are ignored</p>
<p>To get a process name, you can use task manager, right click on a process and select properties</p>
<p>Process names are case sensitive and must match exactly</p>
</details>
</div>
</body>