[vlc-commits] macosx: SPMediaKeyTap: Always use default bundle identifiers list

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


vlc/vlc-3.0 | branch: master | Marvin Scholz <epirat07 at gmail.com> | Wed Aug  1 22:55:13 2018 +0200| [1f145948af1f3494503082e27bd1a10154905695] | committer: Felix Paul Kühne

macosx: SPMediaKeyTap: Always use default bundle identifiers list

Do not read the list from the user defaults, it is unlikely anyone
ever has to customize this.

(cherry picked from commit 4221ab456bf634a62eb56ecbbd4276c6e1505dbe)
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=1f145948af1f3494503082e27bd1a10154905695
---

 modules/gui/macosx/SPMediaKeyTap.h      |  3 --
 modules/gui/macosx/SPMediaKeyTap.m      | 84 +++++++++++++++++----------------
 modules/gui/macosx/VLCCoreInteraction.m |  8 ++--
 3 files changed, 47 insertions(+), 48 deletions(-)

diff --git a/modules/gui/macosx/SPMediaKeyTap.h b/modules/gui/macosx/SPMediaKeyTap.h
index 092e56d5f5..4e0287c528 100644
--- a/modules/gui/macosx/SPMediaKeyTap.h
+++ b/modules/gui/macosx/SPMediaKeyTap.h
@@ -31,8 +31,6 @@
 
 @interface SPMediaKeyTap : NSObject
 
-+ (NSArray*)defaultMediaKeyUserBundleIdentifiers;
-
 - (id)initWithDelegate:(id)delegate;
 
 + (BOOL)usesGlobalMediaKeyTap;
@@ -49,7 +47,6 @@
 extern "C" {
 #endif
 
-extern NSString *kMediaKeyUsingBundleIdentifiersDefaultsKey;
 extern NSString *kIgnoreMediaKeysDefaultsKey;
 
 #ifdef __cplusplus
diff --git a/modules/gui/macosx/SPMediaKeyTap.m b/modules/gui/macosx/SPMediaKeyTap.m
index 7b1d061819..0950978c64 100644
--- a/modules/gui/macosx/SPMediaKeyTap.m
+++ b/modules/gui/macosx/SPMediaKeyTap.m
@@ -25,6 +25,8 @@
 #import "SPMediaKeyTap.h"
 #import "SPInvocationGrabbing.h"
 
+NSString *kIgnoreMediaKeysDefaultsKey = @"SPIgnoreMediaKeys";
+
 @interface SPMediaKeyTap () {
     EventHandlerRef _app_switching_ref;
     EventHandlerRef _app_terminating_ref;
@@ -162,42 +164,47 @@ static CGEventRef tapEventCallback(CGEventTapProxy proxy, CGEventType type, CGEv
 #endif
 }
 
-+ (NSArray*)defaultMediaKeyUserBundleIdentifiers
++ (NSArray*)mediaKeyUserBundleIdentifiers
 {
-    return [NSArray arrayWithObjects:
+    static NSArray *bundleIdentifiers;
+    static dispatch_once_t onceToken;
+    dispatch_once(&onceToken, ^{
+        bundleIdentifiers = @[
             [[NSBundle mainBundle] bundleIdentifier], // your app
-             @"com.spotify.client",
-             @"com.apple.iTunes",
-             @"com.apple.QuickTimePlayerX",
-             @"com.apple.quicktimeplayer",
-             @"com.apple.iWork.Keynote",
-             @"com.apple.iPhoto",
-             @"org.videolan.vlc",
-             @"com.apple.Aperture",
-             @"com.plexsquared.Plex",
-             @"com.soundcloud.desktop",
-             @"org.niltsh.MPlayerX",
-             @"com.ilabs.PandorasHelper",
-             @"com.mahasoftware.pandabar",
-             @"com.bitcartel.pandorajam",
-             @"org.clementine-player.clementine",
-             @"fm.last.Last.fm",
-             @"fm.last.Scrobbler",
-             @"com.beatport.BeatportPro",
-             @"com.Timenut.SongKey",
-             @"com.macromedia.fireworks", // the tap messes up their mouse input
-             @"at.justp.Theremin",
-             @"ru.ya.themblsha.YandexMusic",
-             @"com.jriver.MediaCenter18",
-             @"com.jriver.MediaCenter19",
-             @"com.jriver.MediaCenter20",
-             @"co.rackit.mate",
-             @"com.ttitt.b-music",
-             @"com.beardedspice.BeardedSpice",
-             @"com.plug.Plug",
-             @"com.netease.163music",
-            nil
-    ];
+            @"com.spotify.client",
+            @"com.apple.iTunes",
+            @"com.apple.QuickTimePlayerX",
+            @"com.apple.quicktimeplayer",
+            @"com.apple.iWork.Keynote",
+            @"com.apple.iPhoto",
+            @"org.videolan.vlc",
+            @"com.apple.Aperture",
+            @"com.plexsquared.Plex",
+            @"com.soundcloud.desktop",
+            @"org.niltsh.MPlayerX",
+            @"com.ilabs.PandorasHelper",
+            @"com.mahasoftware.pandabar",
+            @"com.bitcartel.pandorajam",
+            @"org.clementine-player.clementine",
+            @"fm.last.Last.fm",
+            @"fm.last.Scrobbler",
+            @"com.beatport.BeatportPro",
+            @"com.Timenut.SongKey",
+            @"com.macromedia.fireworks", // the tap messes up their mouse input
+            @"at.justp.Theremin",
+            @"ru.ya.themblsha.YandexMusic",
+            @"com.jriver.MediaCenter18",
+            @"com.jriver.MediaCenter19",
+            @"com.jriver.MediaCenter20",
+            @"co.rackit.mate",
+            @"com.ttitt.b-music",
+            @"com.beardedspice.BeardedSpice",
+            @"com.plug.Plug",
+            @"com.netease.163music",
+        ];
+    });
+
+    return bundleIdentifiers;
 }
 
 
@@ -295,11 +302,6 @@ static CGEventRef tapEventCallback(CGEventTapProxy proxy, CGEventType type, CGEv
 
 #pragma mark Task switching callbacks
 
-NSString *kMediaKeyUsingBundleIdentifiersDefaultsKey = @"SPApplicationsNeedingMediaKeys";
-NSString *kIgnoreMediaKeysDefaultsKey = @"SPIgnoreMediaKeys";
-
-
-
 - (void)mediaKeyAppListChanged
 {
     if([_mediaKeyAppList count] == 0) return;
@@ -335,8 +337,8 @@ NSString *kIgnoreMediaKeysDefaultsKey = @"SPIgnoreMediaKeys";
     );
     NSString *bundleIdentifier = [processInfo objectForKey:(id)kCFBundleIdentifierKey];
 
-    NSArray *whitelistIdentifiers = [[NSUserDefaults standardUserDefaults] arrayForKey:kMediaKeyUsingBundleIdentifiersDefaultsKey];
-    if(![whitelistIdentifiers containsObject:bundleIdentifier]) return;
+    if (![[SPMediaKeyTap mediaKeyUserBundleIdentifiers] containsObject:bundleIdentifier])
+        return;
 
     [_mediaKeyAppList removeObject:psnv];
     [_mediaKeyAppList insertObject:psnv atIndex:0];
diff --git a/modules/gui/macosx/VLCCoreInteraction.m b/modules/gui/macosx/VLCCoreInteraction.m
index bfe7706673..62a88159aa 100644
--- a/modules/gui/macosx/VLCCoreInteraction.m
+++ b/modules/gui/macosx/VLCCoreInteraction.m
@@ -102,11 +102,11 @@ static int BossCallback(vlc_object_t *p_this, const char *psz_var,
         b_mediaKeySupport = var_InheritBool(p_intf, "macosx-mediakeys");
         if (b_mediaKeySupport) {
             _mediaKeyController = [[SPMediaKeyTap alloc] initWithDelegate:self];
-            [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
-                                                                     [SPMediaKeyTap defaultMediaKeyUserBundleIdentifiers], kMediaKeyUsingBundleIdentifiersDefaultsKey,
-                                                                     nil]];
         }
-        [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(coreChangedMediaKeySupportSetting:) name:VLCMediaKeySupportSettingChangedNotification object: nil];
+        [[NSNotificationCenter defaultCenter] addObserver:self
+                                                 selector:@selector(coreChangedMediaKeySupportSetting:)
+                                                     name:VLCMediaKeySupportSettingChangedNotification
+                                                   object:nil];
 
         /* init Apple Remote support */
         _remote = [[AppleRemote alloc] init];



More information about the vlc-commits mailing list