From 779687774bb902e943b5e19f56913771441da976 Mon Sep 17 00:00:00 2001 From: Xavier Rubio Jansana Date: Sun, 18 Nov 2018 12:37:16 +0100 Subject: [PATCH] Adds a verification on whether the process is trusted for Accessibility This fixes/mitigates the issue #674: "Application will not restart after update in macOS Mojave" --- radiant-player-mac/AppDelegate.m | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/radiant-player-mac/AppDelegate.m b/radiant-player-mac/AppDelegate.m index 5b8cec76..9bda8324 100644 --- a/radiant-player-mac/AppDelegate.m +++ b/radiant-player-mac/AppDelegate.m @@ -99,6 +99,9 @@ - (void)RadiantScreenUnlocked { */ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { + + [self verifyAccessibility]; + [window setDelegate:self]; // Load the user preferences. @@ -622,6 +625,30 @@ - (void) ddhidAppleMikey:(DDHidAppleMikey *)mikey press:(unsigned)usageId upOrDo } } +#pragma mark - Accessibility + +- (void) verifyAccessibility +{ + Boolean trusted = AXIsProcessTrusted(); + NSLog(@"Accessibility: process is trusted check: %s", (trusted ? "YES" : "NO")); + if (trusted) { + return; + } + + NSAlert *alert = [[NSAlert alloc] init]; + [alert setMessageText:@"Media keys"]; + [alert setInformativeText:@"Radiant Player needs Accessibility permission to be able to listen for media keys. You will need to enable it from System Preferences.\n\nIf you\'ve updated Radiant Player and you\'re seeing this message, you will have to disable and reenable the permission in order for Radiant Player to work properly.\n\nRadiant Player will now close, and you will have to restart it after enabling the permission."]; + [alert addButtonWithTitle:@"Close"]; + [alert runModal]; + + const void *tkeys[1] = { kAXTrustedCheckOptionPrompt }; + const void *tvalues[1] = { kCFBooleanTrue }; + CFDictionaryRef options = CFDictionaryCreate(NULL, tkeys, tvalues, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + NSLog(@"Accessibility: process is trusted check with prompt: %s", (AXIsProcessTrustedWithOptions(options) ? "YES" : "NO")); + + exit(1); +} + #pragma mark - Web Browser Actions - (void) load:(id)sender