Add in the ability to make custom overrides.

Fixed issues with the CSS in the property inspector
Make it so i can actually write unit tests if i want to
This commit is contained in:
2024-04-20 21:19:44 -06:00
parent 7abbc92080
commit fdfa32909f
29 changed files with 810 additions and 216 deletions

View File

@ -0,0 +1,10 @@
namespace FocusVolumeControl.Overrides
{
public enum MatchType
{
Equal,
StartsWith,
EndsWith,
Regex,
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FocusVolumeControl.Overrides
{
public class Override
{
public MatchType MatchType { get; set; }
public string WindowQuery { get; set; }
public string AudioProcessName { get; set; }
}
}

View File

@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FocusVolumeControl.Overrides
{
internal class OverrideParser
{
public static List<Override> Parse(string raw)
{
var overrides = new List<Override>();
if (raw == null)
{
return overrides;
}
var lines = raw.Split(new[] { "\r\n", "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries);
Override tmp = null;
foreach (var line in lines)
{
if (string.IsNullOrEmpty(line) || line.StartsWith("//"))
{
continue;
}
var split = line.Split(':');
if (split.Length > 1)
{
if (!string.IsNullOrEmpty(tmp?.WindowQuery) && !string.IsNullOrEmpty(tmp?.AudioProcessName))
{
overrides.Add(tmp);
}
tmp = new Override();
if (string.Equals(split[0], "eq", StringComparison.OrdinalIgnoreCase))
{
tmp.MatchType = MatchType.Equal;
}
else if (string.Equals(split[0], "start", StringComparison.OrdinalIgnoreCase))
{
tmp.MatchType = MatchType.StartsWith;
}
else if (string.Equals(split[0], "end", StringComparison.OrdinalIgnoreCase))
{
tmp.MatchType = MatchType.EndsWith;
}
else if (string.Equals(split[0], "regex", StringComparison.OrdinalIgnoreCase))
{
tmp.MatchType = MatchType.Regex;
}
else
{
continue;
}
tmp.WindowQuery = split[1].Trim();
}
else if (tmp != null)
{
tmp.AudioProcessName = split[0].Trim();
}
}
if (!string.IsNullOrEmpty(tmp?.WindowQuery) && !string.IsNullOrEmpty(tmp?.AudioProcessName))
{
overrides.Add(tmp);
}
return overrides;
}
}
}