From 6f1fcad0cae307d6ecd28d03ce1cb54b8cb95a56 Mon Sep 17 00:00:00 2001 From: Michael Starke Date: Fri, 10 Jul 2020 16:24:44 +0200 Subject: [PATCH] Added override sequence to autotype environment --- MacPass/MPAutotypeDaemon.m | 4 ++-- MacPass/MPAutotypeEnvironment.h | 5 +++-- MacPass/MPAutotypeEnvironment.m | 10 ++++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/MacPass/MPAutotypeDaemon.m b/MacPass/MPAutotypeDaemon.m index eb44d267..0fbce36c 100644 --- a/MacPass/MPAutotypeDaemon.m +++ b/MacPass/MPAutotypeDaemon.m @@ -143,13 +143,13 @@ static MPAutotypeDaemon *_sharedInstance; - (void)performAutotypeForEntry:(KPKEntry *)entry overrideSequence:(NSString *)sequence { if(entry) { - MPAutotypeEnvironment *env = [MPAutotypeEnvironment environmentWithTargetApplication:self.previousApplication entry:entry]; + MPAutotypeEnvironment *env = [MPAutotypeEnvironment environmentWithTargetApplication:self.previousApplication entry:entry overrideSequence:sequence]; [self _runAutotypeWithEnvironment:env]; } } - (void)_didPressHotKey { - MPAutotypeEnvironment *env = [MPAutotypeEnvironment environmentWithTargetApplication:NSWorkspace.sharedWorkspace.frontmostApplication entry:nil]; + MPAutotypeEnvironment *env = [MPAutotypeEnvironment environmentWithTargetApplication:NSWorkspace.sharedWorkspace.frontmostApplication entry:nil overrideSequence:nil]; [self _runAutotypeWithEnvironment:env]; } diff --git a/MacPass/MPAutotypeEnvironment.h b/MacPass/MPAutotypeEnvironment.h index 8c756475..c805327c 100644 --- a/MacPass/MPAutotypeEnvironment.h +++ b/MacPass/MPAutotypeEnvironment.h @@ -24,9 +24,10 @@ NS_ASSUME_NONNULL_BEGIN @property (readonly, copy) NSString *windowTitle; /// The window title of the target application. @property (readonly) BOOL hidden; /// If set to YES, MacPass was hidden when autotype was initiated @property (readonly) BOOL isSelfTargeting; /// If MacPass should autotype to itself, YES, otherwise NO +@property (readonly) NSString *overrideSequence; /// If set, this sequence is used for running the command regardless of the matched one -+ (instancetype)environmentWithTargetApplication:(NSRunningApplication *)targetApplication entry:(KPKEntry * _Nullable)entry; -- (instancetype)initWithTargetApplication:(NSRunningApplication *)targetApplication entry:(KPKEntry * _Nullable)entry NS_DESIGNATED_INITIALIZER; ++ (instancetype)environmentWithTargetApplication:(NSRunningApplication *)targetApplication entry:(KPKEntry * _Nullable)entry overrideSequence:(NSString * _Nullable)overrideSequence; +- (instancetype)initWithTargetApplication:(NSRunningApplication *)targetApplication entry:(KPKEntry * _Nullable)entry overrideSequence:(NSString * _Nullable)overrdieSequence NS_DESIGNATED_INITIALIZER; - (instancetype)init NS_UNAVAILABLE; @end diff --git a/MacPass/MPAutotypeEnvironment.m b/MacPass/MPAutotypeEnvironment.m index a1b37ca3..dd91af80 100644 --- a/MacPass/MPAutotypeEnvironment.m +++ b/MacPass/MPAutotypeEnvironment.m @@ -13,14 +13,16 @@ @implementation MPAutotypeEnvironment -+ (instancetype)environmentWithTargetApplication:(NSRunningApplication *)targetApplication entry:(KPKEntry *)entry { - return [[MPAutotypeEnvironment alloc] initWithTargetApplication:targetApplication entry:entry]; ++ (instancetype)environmentWithTargetApplication:(NSRunningApplication *)targetApplication entry:(KPKEntry *)entry overrideSequence:(NSString *)overrideSequence { + return [[MPAutotypeEnvironment alloc] initWithTargetApplication:targetApplication entry:entry overrideSequence:overrideSequence]; } -- (instancetype)initWithTargetApplication:(NSRunningApplication *)targetApplication entry:(KPKEntry *)entry { +- (instancetype)initWithTargetApplication:(NSRunningApplication *)targetApplication entry:(KPKEntry *)entry overrideSequence:(NSString *)overrdieSequence { self = [super init]; if(self) { _preferredEntry = entry; + _hidden = NSRunningApplication.currentApplication.isHidden; + _overrideSequence = [overrdieSequence copy]; if(!targetApplication) { _pid = -1; _windowTitle = @""; @@ -41,7 +43,7 @@ } } } - _hidden = NSRunningApplication.currentApplication.isHidden; + } return self; }