[vlc-commits] macosx: SPMediaKeyTap: Improve error handling

Marvin Scholz git at videolan.org
Fri Aug 3 01:45:50 CEST 2018


vlc/vlc-3.0 | branch: master | Marvin Scholz <epirat07 at gmail.com> | Wed Aug  1 20:31:47 2018 +0200| [658f37b0c869d439bd234077c6e66e340d1a64ca] | committer: Felix Paul Kühne

macosx: SPMediaKeyTap: Improve error handling

(cherry picked from commit 5ed5ef0c99d83570e05b2467e342363251c4da06)
Signed-off-by: Felix Paul Kühne <felix at feepk.net>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=658f37b0c869d439bd234077c6e66e340d1a64ca
---

 modules/gui/macosx/SPMediaKeyTap.h      |  2 +-
 modules/gui/macosx/SPMediaKeyTap.m      | 12 ++++++++++--
 modules/gui/macosx/VLCCoreInteraction.m | 12 ++++++++----
 3 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/modules/gui/macosx/SPMediaKeyTap.h b/modules/gui/macosx/SPMediaKeyTap.h
index 82519ffd4c..78b4ce9b3c 100644
--- a/modules/gui/macosx/SPMediaKeyTap.h
+++ b/modules/gui/macosx/SPMediaKeyTap.h
@@ -33,7 +33,7 @@
 -(id)initWithDelegate:(id)delegate;
 
 +(BOOL)usesGlobalMediaKeyTap;
--(void)startWatchingMediaKeys;
+-(BOOL)startWatchingMediaKeys;
 -(void)stopWatchingMediaKeys;
 -(void)handleAndReleaseMediaKeyEvent:(NSEvent *)event;
 @end
diff --git a/modules/gui/macosx/SPMediaKeyTap.m b/modules/gui/macosx/SPMediaKeyTap.m
index c7c97e25de..57f5fb00aa 100644
--- a/modules/gui/macosx/SPMediaKeyTap.m
+++ b/modules/gui/macosx/SPMediaKeyTap.m
@@ -69,7 +69,7 @@ static CGEventRef tapEventCallback(CGEventTapProxy proxy, CGEventType type, CGEv
     _app_switching_ref = NULL;
 }
 
--(void)startWatchingMediaKeys;{
+-(BOOL)startWatchingMediaKeys;{
     // Prevent having multiple mediaKeys threads
     [self stopWatchingMediaKeys];
 
@@ -82,13 +82,21 @@ static CGEventRef tapEventCallback(CGEventTapProxy proxy, CGEventType type, CGEv
                                   CGEventMaskBit(NX_SYSDEFINED),
                                   tapEventCallback,
                                   (__bridge void * __nullable)(self));
-    assert(_eventPort != NULL);
+
+    // Can be NULL if the app has no accessibility access permission
+    if (_eventPort == NULL)
+        return NO;
 
     _eventPortSource = CFMachPortCreateRunLoopSource(kCFAllocatorSystemDefault, _eventPort, 0);
     assert(_eventPortSource != NULL);
 
+    if (_eventPortSource == NULL)
+        return NO;
+
     // Let's do this in a separate thread so that a slow app doesn't lag the event tap
     [NSThread detachNewThreadSelector:@selector(eventTapThread) toTarget:self withObject:nil];
+
+    return YES;
 }
 -(void)stopWatchingMediaKeys;
 {
diff --git a/modules/gui/macosx/VLCCoreInteraction.m b/modules/gui/macosx/VLCCoreInteraction.m
index 636095a6a5..bfe7706673 100644
--- a/modules/gui/macosx/VLCCoreInteraction.m
+++ b/modules/gui/macosx/VLCCoreInteraction.m
@@ -879,14 +879,18 @@ static int BossCallback(vlc_object_t *p_this, const char *psz_var,
     if (b_mediaKeySupport && ([[[main playlist] model] hasChildren] ||
                               [[main inputManager] hasInput])) {
         if (!b_mediaKeyTrapEnabled) {
-            b_mediaKeyTrapEnabled = YES;
-            msg_Dbg(p_intf, "Enable media key support");
-            [_mediaKeyController startWatchingMediaKeys];
+            msg_Dbg(p_intf, "Enabling media key support");
+            if ([_mediaKeyController startWatchingMediaKeys]) {
+                b_mediaKeyTrapEnabled = YES;
+            } else {
+                msg_Warn(p_intf, "Failed to enable media key support, likely "
+                    "app needs to be whitelisted in Security Settings.");
+            }
         }
     } else {
         if (b_mediaKeyTrapEnabled) {
             b_mediaKeyTrapEnabled = NO;
-            msg_Dbg(p_intf, "Disable media key support");
+            msg_Dbg(p_intf, "Disabling media key support");
             [_mediaKeyController stopWatchingMediaKeys];
         }
     }



More information about the vlc-commits mailing list