Revert "Adjusted checks for auto-type permissions"

This reverts commit 7095d55670.

# Conflicts:
#	MacPass/MPAutotypeEnvironment.h
#	MacPass/MPAutotypeEnvironment.m
This commit is contained in:
Michael Starke
2020-11-03 11:15:50 +01:00
parent 499b7fdd6b
commit e82e2fe4a2
6 changed files with 20 additions and 40 deletions

View File

@@ -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");

View File

@@ -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;

View File

@@ -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 {

View File

@@ -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

View File

@@ -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 = @"";
}

View File

@@ -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];