From 47e3333d7708e6620c66564b3ec81fbd0e2503c0 Mon Sep 17 00:00:00 2001 From: Chris Sebok Date: Wed, 19 Feb 2020 15:06:56 +0000 Subject: [PATCH] Resolved #232 Fixed issue with RegEx process nmae filtering not acting as expected --- .gitignore | 1 + src/Carnac.Logic/KeyProvider.cs | 36 ++++++++-------------------- src/Carnac.Tests/KeyProviderTests.cs | 1 + src/Carnac.sln.DotSettings | 3 +++ 4 files changed, 15 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index 30197d54..454c0c56 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ deploy-to-ec2* *.orig Thumbs.db src/Carnac.sln.ide/ +.vs/ # Cake - Uncomment if you are using it tools/** diff --git a/src/Carnac.Logic/KeyProvider.cs b/src/Carnac.Logic/KeyProvider.cs index 66f05236..faed7ae5 100644 --- a/src/Carnac.Logic/KeyProvider.cs +++ b/src/Carnac.Logic/KeyProvider.cs @@ -21,7 +21,6 @@ public class KeyProvider : IKeyProvider readonly IPasswordModeService passwordModeService; readonly IDesktopLockEventService desktopLockEventService; readonly PopupSettings settings; - string currentFilter = null; private readonly IList modifierKeys = new List @@ -55,31 +54,13 @@ public KeyProvider(IInterceptKeys interceptKeysSource, IPasswordModeService pass settings = settingsProvider.GetSettings(); } - private bool ShouldFilterProcess(out Regex filterRegex) + private Regex GetRegEx() { - filterRegex = null; - if (settings?.ProcessFilterExpression != currentFilter) + if(settings?.ProcessFilterExpression == null) { - currentFilter = settings?.ProcessFilterExpression; - - if (!string.IsNullOrEmpty(currentFilter)) - { - try - { - filterRegex = new Regex(currentFilter, RegexOptions.IgnoreCase | RegexOptions.Compiled, TimeSpan.FromSeconds(1)); - } - catch - { - filterRegex = null; - } - } - else - { - filterRegex = null; - } + return null; } - - return (filterRegex != null); + return new Regex(settings?.ProcessFilterExpression, RegexOptions.IgnoreCase | RegexOptions.Compiled, TimeSpan.FromSeconds(1)); } public IObservable GetKeyStream() @@ -129,14 +110,17 @@ bool IsModifierKeyPress(InterceptKeyEventArgs interceptKeyEventArgs) KeyPress ToCarnacKeyPress(InterceptKeyEventArgs interceptKeyEventArgs) { var process = AssociatedProcessUtilities.GetAssociatedProcess(); + if (process == null) { return null; } + + Debug.WriteLine("processName: " + process.ProcessName); + + var filterRegex = GetRegEx(); - // see if this process is one being filtered for - Regex filterRegex; - if (ShouldFilterProcess(out filterRegex) && !filterRegex.IsMatch(process.ProcessName)) + if (filterRegex != null && !filterRegex.IsMatch(process.ProcessName)) { return null; } diff --git a/src/Carnac.Tests/KeyProviderTests.cs b/src/Carnac.Tests/KeyProviderTests.cs index 415036e9..0bce1f3f 100644 --- a/src/Carnac.Tests/KeyProviderTests.cs +++ b/src/Carnac.Tests/KeyProviderTests.cs @@ -141,5 +141,6 @@ public async Task no_output_with_no_match_filter() // assert Assert.Equal(0, processedKeys.Count); } + } } \ No newline at end of file diff --git a/src/Carnac.sln.DotSettings b/src/Carnac.sln.DotSettings index 267141e1..6e5757ca 100644 --- a/src/Carnac.sln.DotSettings +++ b/src/Carnac.sln.DotSettings @@ -213,6 +213,9 @@ II.2.12 <HandlesEvent /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"><ExtraRule Prefix="" Suffix="" Style="aa_bb" /></Policy> True + True + True + True True True True \ No newline at end of file