Added Accessibilty verification for macOS 10.14 to allow for better user experince

This commit is contained in:
Michael Starke
2018-09-25 11:18:13 +02:00
parent 009d198421
commit 05ac9a0142
2 changed files with 25 additions and 1 deletions

View File

@@ -55,6 +55,8 @@ NSString *const kMPProcessIdentifierKey = @"kMPProcessIdentifierKey";
@implementation MPAutotypeDaemon
@dynamic autotypeSupported;
#pragma mark -
#pragma mark Lifecylce
@@ -93,6 +95,7 @@ static MPAutotypeDaemon *_sharedInstance;
name:NSWorkspaceDidDeactivateApplicationNotification
object:nil];
}
[self checkForAccessibiltyPermissions];
return self;
}
@@ -105,6 +108,14 @@ static MPAutotypeDaemon *_sharedInstance;
#pragma mark -
#pragma mark Properties
- (BOOL)autotypeSupported {
if(@available(macOS 10.14, *)) {
return AXIsProcessTrusted();
}
/* macOS 10.13 and lower allows us to send key events regardless of accessibilty trust */
return YES;
}
- (void)setEnabled:(BOOL)enabled {
if(_enabled != enabled) {
_enabled = enabled;
@@ -122,6 +133,16 @@ static MPAutotypeDaemon *_sharedInstance;
}
}
- (void)checkForAccessibiltyPermissions {
if(@available(macOS 10.14, *)) {
CFStringRef keys[] = { kAXTrustedCheckOptionPrompt };
CFBooleanRef values[] = { kCFBooleanTrue };
CFDictionaryRef dictRef = CFDictionaryCreate(kCFAllocatorDefault, (const void **)keys, (const void **)values, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
AXIsProcessTrustedWithOptions(dictRef);
CFRelease(dictRef);
}
}
#pragma mark -
#pragma mark Autotype Invocation
- (void)performAutotypeForEntry:(KPKEntry *)entry {