mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 10:32:26 +00:00
Inializing regualr expressions only once for autotype
This commit is contained in:
@@ -334,7 +334,20 @@ static CGKeyCode kMPNumpadKeyCodes[] = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* F1-16 */
|
/* F1-16 */
|
||||||
NSRegularExpression *functionKeyRegExp = [[NSRegularExpression alloc] initWithPattern:kKPKAutotypeFunctionMaskRegularExpression options:NSRegularExpressionCaseInsensitive error:0];
|
static NSRegularExpression *functionKeyRegExp;
|
||||||
|
static NSRegularExpression *numpadKeyRegExp;
|
||||||
|
static NSRegularExpression *delayRegExp;
|
||||||
|
static dispatch_once_t onceToken;
|
||||||
|
dispatch_once(&onceToken, ^{
|
||||||
|
NSString *delayPattern = [[NSString alloc] initWithFormat:@"\\{(%@|%@)[ |=]+([0-9]+)\\}",
|
||||||
|
kKPKAutotypeDelay,
|
||||||
|
kKPKAutotypeVirtualKey/*,
|
||||||
|
kKPKAutotypeVirtualExtendedKey,
|
||||||
|
kKPKAutotypeVirtualNonExtendedKey*/];
|
||||||
|
functionKeyRegExp = [[NSRegularExpression alloc] initWithPattern:kKPKAutotypeFunctionMaskRegularExpression options:NSRegularExpressionCaseInsensitive error:0];
|
||||||
|
numpadKeyRegExp = [[NSRegularExpression alloc] initWithPattern:kKPKAutotypeKeypaddNumberMaskRegularExpression options:NSRegularExpressionCaseInsensitive error:0];
|
||||||
|
delayRegExp = [[NSRegularExpression alloc] initWithPattern:delayPattern options:NSRegularExpressionCaseInsensitive error:0];
|
||||||
|
});
|
||||||
NSTextCheckingResult *functionResult = [functionKeyRegExp firstMatchInString:commandString options:0 range:NSMakeRange(0, commandString.length)];
|
NSTextCheckingResult *functionResult = [functionKeyRegExp firstMatchInString:commandString options:0 range:NSMakeRange(0, commandString.length)];
|
||||||
if(functionResult && functionResult.numberOfRanges == 2) {
|
if(functionResult && functionResult.numberOfRanges == 2) {
|
||||||
NSString *numberString = [commandString substringWithRange:[functionResult rangeAtIndex:1]];
|
NSString *numberString = [commandString substringWithRange:[functionResult rangeAtIndex:1]];
|
||||||
@@ -350,7 +363,6 @@ static CGKeyCode kMPNumpadKeyCodes[] = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Numpad0-9 */
|
/* Numpad0-9 */
|
||||||
NSRegularExpression *numpadKeyRegExp = [[NSRegularExpression alloc] initWithPattern:kKPKAutotypeKeypaddNumberMaskRegularExpression options:NSRegularExpressionCaseInsensitive error:0];
|
|
||||||
NSTextCheckingResult *numpadResult = [numpadKeyRegExp firstMatchInString:commandString options:0 range:NSMakeRange(0, commandString.length)];
|
NSTextCheckingResult *numpadResult = [numpadKeyRegExp firstMatchInString:commandString options:0 range:NSMakeRange(0, commandString.length)];
|
||||||
if(numpadResult && numpadResult.numberOfRanges == 2) {
|
if(numpadResult && numpadResult.numberOfRanges == 2) {
|
||||||
NSString *numberString = [commandString substringWithRange:[numpadResult rangeAtIndex:1]];
|
NSString *numberString = [commandString substringWithRange:[numpadResult rangeAtIndex:1]];
|
||||||
@@ -372,13 +384,6 @@ static CGKeyCode kMPNumpadKeyCodes[] = {
|
|||||||
}
|
}
|
||||||
// TODO: add {APPLICATION <appname>}
|
// TODO: add {APPLICATION <appname>}
|
||||||
/* Delay */
|
/* Delay */
|
||||||
NSString *delayPattern = [[NSString alloc] initWithFormat:@"\\{(%@|%@)[ |=]+([0-9]+)\\}",
|
|
||||||
kKPKAutotypeDelay,
|
|
||||||
kKPKAutotypeVirtualKey/*,
|
|
||||||
kKPKAutotypeVirtualExtendedKey,
|
|
||||||
kKPKAutotypeVirtualNonExtendedKey*/];
|
|
||||||
NSRegularExpression *delayRegExp = [[NSRegularExpression alloc] initWithPattern:delayPattern options:NSRegularExpressionCaseInsensitive error:0];
|
|
||||||
NSAssert(delayRegExp, @"Regex for delay should work!");
|
|
||||||
NSTextCheckingResult *result = [delayRegExp firstMatchInString:commandString options:0 range:NSMakeRange(0, commandString.length)];
|
NSTextCheckingResult *result = [delayRegExp firstMatchInString:commandString options:0 range:NSMakeRange(0, commandString.length)];
|
||||||
if(result && (result.numberOfRanges == 3)) {
|
if(result && (result.numberOfRanges == 3)) {
|
||||||
NSString *uppercaseCommand = [[commandString substringWithRange:[result rangeAtIndex:1]] uppercaseString];
|
NSString *uppercaseCommand = [[commandString substringWithRange:[result rangeAtIndex:1]] uppercaseString];
|
||||||
|
|||||||
38
MacPass/MPAutotypePickchars.m
Normal file
38
MacPass/MPAutotypePickchars.m
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
//
|
||||||
|
// MPAutotypePickchars.m
|
||||||
|
// MacPass
|
||||||
|
//
|
||||||
|
// Created by Michael Starke on 23.11.17.
|
||||||
|
// Copyright © 2017 HicknHack Software GmbH. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "MPAutotypePickchars.h"
|
||||||
|
#import "MPPickcharViewController.h"
|
||||||
|
|
||||||
|
@implementation MPAutotypePickchars
|
||||||
|
|
||||||
|
- (void)execute {
|
||||||
|
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||||
|
|
||||||
|
|
||||||
|
MPPickcharViewController *vc = [[MPPickcharViewController alloc] init];
|
||||||
|
vc.sourceValue = @"ThisIsANicePassword";
|
||||||
|
vc.countToPick = 10;
|
||||||
|
|
||||||
|
|
||||||
|
NSPanel *panel = [[NSPanel alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100)
|
||||||
|
styleMask:NSWindowStyleMaskNonactivatingPanel|NSWindowStyleMaskTitled
|
||||||
|
backing:NSBackingStoreRetained
|
||||||
|
defer:YES];
|
||||||
|
panel.level = NSScreenSaverWindowLevel;
|
||||||
|
panel.contentViewController = vc;
|
||||||
|
[panel center];
|
||||||
|
[panel makeKeyAndOrderFront:self];
|
||||||
|
|
||||||
|
if(NSModalResponseOK == [NSApp runModalForWindow:panel]) {
|
||||||
|
// Do some stuff!
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
Reference in New Issue
Block a user