diff --git a/MacPass/MPAutotypeDaemon.m b/MacPass/MPAutotypeDaemon.m index f16bb7d1..0fbce36c 100644 --- a/MacPass/MPAutotypeDaemon.m +++ b/MacPass/MPAutotypeDaemon.m @@ -55,6 +55,7 @@ @property (strong) NSRunningApplication *previousApplication; // The application that was active before we got invoked @property (assign) NSTimeInterval userActionRequested; @property (strong) id applicationActivationObserver; +@property (nonatomic, readonly) BOOL hasNecessaryAutotypePermissions; @end @implementation MPAutotypeDaemon @@ -130,6 +131,10 @@ static MPAutotypeDaemon *_sharedInstance; } } +- (BOOL)hasNecessaryAutotypePermissions { + return MPAutotypeDoctor.defaultDoctor.hasNecessaryAutotypePermissions; +} + #pragma mark - #pragma mark Autotype Invocation - (void)performAutotypeForEntry:(KPKEntry *)entry { @@ -144,7 +149,7 @@ static MPAutotypeDaemon *_sharedInstance; } - (void)_didPressHotKey { - MPAutotypeEnvironment *env = [MPAutotypeEnvironment environmentWithTargetApplication:nil entry:nil overrideSequence:nil]; + MPAutotypeEnvironment *env = [MPAutotypeEnvironment environmentWithTargetApplication:NSWorkspace.sharedWorkspace.frontmostApplication entry:nil overrideSequence:nil]; [self _runAutotypeWithEnvironment:env]; } @@ -188,14 +193,8 @@ static MPAutotypeDaemon *_sharedInstance; if(env.isSelfTargeting) { return; // we do not want to target ourselves } - BOOL hasNeededPermissions = NO; - if(env.globalAutotype) { - hasNeededPermissions = [MPAutotypeDoctor.defaultDoctor hasNecessaryPermissionForTask:MPAutotypeTaskGlobalAutotype]; - } - else { - hasNeededPermissions = [MPAutotypeDoctor.defaultDoctor hasNecessaryPermissionForTask:MPAutotypeTaskAutotype]; - } - if(!hasNeededPermissions) { + + if(!self.hasNecessaryAutotypePermissions) { NSUserNotification *notification = [[NSUserNotification alloc] init]; notification.title = NSLocalizedString(@"AUTOTYPE_NOTIFICATION_PERMISSIONS_MISSING_TITLE", "Title for autotype feedback on missing permissions"); notification.informativeText = NSLocalizedString(@"AUTOTYPE_NOTIFICATION_MACPASS_IS_MISSING_PERMISSIONS", "Notification: Autotype failed, MacPass has not enough permissions to perform autotype"); diff --git a/MacPass/MPAutotypeDoctor.h b/MacPass/MPAutotypeDoctor.h index b2edc5a1..55d02a3b 100644 --- a/MacPass/MPAutotypeDoctor.h +++ b/MacPass/MPAutotypeDoctor.h @@ -12,14 +12,10 @@ NS_ASSUME_NONNULL_BEGIN @interface MPAutotypeDoctor : NSObject -typedef NS_ENUM(NSUInteger, MPAutotypeTask) { - MPAutotypeTaskAutotype, - MPAutotypeTaskGlobalAutotype -}; @property (class, readonly, strong) MPAutotypeDoctor *defaultDoctor; +@property (nonatomic, readonly) BOOL hasNecessaryAutotypePermissions; // MacPass has all the permissions it needs to run autotype on the current system -- (BOOL)hasNecessaryPermissionForTask:(MPAutotypeTask)task; - (BOOL)hasScreenRecordingPermissions:(NSError *__autoreleasing*)error; - (BOOL)hasAccessibiltyPermissions:(NSError *__autoreleasing*)error; diff --git a/MacPass/MPAutotypeDoctor.m b/MacPass/MPAutotypeDoctor.m index 32407258..4ab90555 100644 --- a/MacPass/MPAutotypeDoctor.m +++ b/MacPass/MPAutotypeDoctor.m @@ -51,17 +51,14 @@ return instance; } -- (BOOL)hasNecessaryPermissionForTask:(MPAutotypeTask)task { - BOOL permissionsOK = YES; - switch(task) { - case MPAutotypeTaskGlobalAutotype: - permissionsOK &= [self hasScreenRecordingPermissions:NULL]; - // fallthrough! - case MPAutotypeTaskAutotype: - permissionsOK &= [self hasAccessibiltyPermissions:NULL]; - break; +- (BOOL)hasNecessaryAutotypePermissions { + if(![self hasAccessibiltyPermissions:NULL]) { + return NO; } - return permissionsOK; + if(![self hasScreenRecordingPermissions:NULL]) { + return NO; + } + return YES; } - (BOOL)hasScreenRecordingPermissions:(NSError *__autoreleasing*)error { diff --git a/MacPass/MPAutotypeEnvironment.h b/MacPass/MPAutotypeEnvironment.h index f2736e00..c805327c 100644 --- a/MacPass/MPAutotypeEnvironment.h +++ b/MacPass/MPAutotypeEnvironment.h @@ -25,15 +25,9 @@ NS_ASSUME_NONNULL_BEGIN @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 -@property (readonly) BOOL globalAutotype; /// YES, if autotype is run as global autotype, NO otherwise -+ (instancetype)environmentWithTargetApplication:(NSRunningApplication * _Nullable)targetApplication entry:(KPKEntry * _Nullable)entry overrideSequence:(NSString * _Nullable)overrideSequence; - -/// Create a environment for the autotype execution capturing the current exection context -/// @param targetApplication the application to target, supply nil to use the front most application (for e.g. Global Autotype) -/// @param entry the entry to use, if one is preferred (e.g. when being invoked via Perform Autotype) -/// @param overrdieSequence a custom sequence that should take precedence over any provided by the entry -- (instancetype)initWithTargetApplication:(NSRunningApplication * _Nullable)targetApplication entry:(KPKEntry * _Nullable)entry overrideSequence:(NSString * _Nullable)overrdieSequence 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 cc2664dd..dd91af80 100644 --- a/MacPass/MPAutotypeEnvironment.m +++ b/MacPass/MPAutotypeEnvironment.m @@ -20,16 +20,10 @@ - (instancetype)initWithTargetApplication:(NSRunningApplication *)targetApplication entry:(KPKEntry *)entry overrideSequence:(NSString *)overrdieSequence { self = [super init]; if(self) { - _globalAutotype = NO; _preferredEntry = entry; _hidden = NSRunningApplication.currentApplication.isHidden; _overrideSequence = [overrdieSequence copy]; - /* capture the front most application if no one was supplied */ - if(nil == targetApplication) { - _globalAutotype = YES; - targetApplication = NSWorkspace.sharedWorkspace.frontmostApplication; - } - if(nil == targetApplication) { + if(!targetApplication) { _pid = -1; _windowTitle = @""; } diff --git a/MacPass/MPIntegrationPreferencesController.m b/MacPass/MPIntegrationPreferencesController.m index 0ba1ba97..c4ccdfbc 100644 --- a/MacPass/MPIntegrationPreferencesController.m +++ b/MacPass/MPIntegrationPreferencesController.m @@ -106,7 +106,7 @@ - (void)_updateAccessabilityWarning { - BOOL hasAutotypeSupport = [MPAutotypeDoctor.defaultDoctor hasNecessaryPermissionForTask:MPAutotypeTaskGlobalAutotype]; + BOOL hasAutotypeSupport = MPAutotypeDoctor.defaultDoctor.hasNecessaryAutotypePermissions; if(hasAutotypeSupport) { [self.autotypeStackView setVisibilityPriority:NSStackViewVisibilityPriorityNotVisible forView:self.autotypeWarningTextField];