Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolved #232 Fixed issue with RegEx process name filtering not acting as expected #233

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ deploy-to-ec2*
*.orig
Thumbs.db
src/Carnac.sln.ide/
.vs/

# Cake - Uncomment if you are using it
tools/**
Expand Down
36 changes: 10 additions & 26 deletions src/Carnac.Logic/KeyProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public class KeyProvider : IKeyProvider
readonly IPasswordModeService passwordModeService;
readonly IDesktopLockEventService desktopLockEventService;
readonly PopupSettings settings;
string currentFilter = null;

private readonly IList<Keys> modifierKeys =
new List<Keys>
Expand Down Expand Up @@ -55,31 +54,13 @@ public KeyProvider(IInterceptKeys interceptKeysSource, IPasswordModeService pass
settings = settingsProvider.GetSettings<PopupSettings>();
}

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<KeyPress> GetKeyStream()
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/Carnac.Tests/KeyProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,6 @@ public async Task no_output_with_no_match_filter()
// assert
Assert.Equal(0, processedKeys.Count);
}

}
}
3 changes: 3 additions & 0 deletions src/Carnac.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ II.2.12 &lt;HandlesEvent /&gt;&#xD;
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=TypesAndNamespaces/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="aa_bb" /&gt;&lt;/Policy&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpFileLayoutPatternsUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>