macosx: Use @available instead of own macros
authorDavid Fuhrmann <dfuhrmann@videolan.org>
Thu, 20 Sep 2018 22:18:24 +0000 (00:18 +0200)
committerDavid Fuhrmann <dfuhrmann@videolan.org>
Mon, 24 Sep 2018 07:33:38 +0000 (09:33 +0200)
@available is advocated now since Xcode 9, it does both a runtime
check for a minimal required OS version, as well as it guards
for partial availability warnings.

modules/gui/macosx/AppleRemote.m
modules/gui/macosx/CompatibilityFixes.h
modules/gui/macosx/VLCInputManager.m
modules/gui/macosx/VLCRemoteControlService.m
modules/gui/macosx/VLCStatusBarIcon.m
modules/gui/macosx/VLCVideoWindowCommon.m

index 452a1e5..2556934 100644 (file)
@@ -89,7 +89,7 @@ const NSTimeInterval HOLD_RECOGNITION_TIME_INTERVAL=0.4;
         [mutableCookieToButtonMapping setObject:[NSNumber numberWithInt:k2009RemoteButtonFullscreen] forKey:@"33_21_20_3_2_33_21_20_3_2_"];
         [mutableCookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteControl_Switched]     forKey:@"42_33_23_21_20_2_33_23_21_20_2_"];
 
-        if (OSX_HIGH_SIERRA_AND_HIGHER) {
+        if (@available(macOS 10.13, *)) {
             [mutableCookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonVolume_Plus]    forKey:@"33_21_20_15_12_2_"];
             [mutableCookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonVolume_Minus]   forKey:@"33_21_20_16_12_2_"];
         }
index 7e91054..20ecf6a 100644 (file)
 #import <Cocoa/Cocoa.h>
 
 #pragma mark -
-#pragma OS detection code
-#define OSX_EL_CAPITAN_AND_HIGHER (NSAppKitVersionNumber >= 1404)
-#define OSX_SIERRA_AND_HIGHER (NSAppKitVersionNumber >= 1485)
-#define OSX_SIERRA_DOT_TWO_AND_HIGHER (NSAppKitVersionNumber >= 1504.76) // this is needed to check for MPRemoteCommandCenter
-#define OSX_HIGH_SIERRA_AND_HIGHER (NSAppKitVersionNumber >= 1560)
-#define OSX_MOJAVE_AND_HIGHER (NSAppKitVersionNumber >= 1639.10)
-
 void swapoutOverride(Class _Nonnull cls, SEL _Nonnull selector);
index b01ac10..dbe245b 100644 (file)
@@ -191,8 +191,10 @@ static int InputEvent(vlc_object_t *p_this, const char *psz_var,
 
         informInputChangedQueue = dispatch_queue_create("org.videolan.vlc.inputChangedQueue", DISPATCH_QUEUE_SERIAL);
 
-        _remoteControlService = [[VLCRemoteControlService alloc] init];
-        [_remoteControlService subscribeToRemoteCommands];
+        if (@available(macOS 10.12.2, *)) {
+            _remoteControlService = [[VLCRemoteControlService alloc] init];
+            [_remoteControlService subscribeToRemoteCommands];
+        }
     }
     return self;
 }
@@ -207,7 +209,9 @@ static int InputEvent(vlc_object_t *p_this, const char *psz_var,
 - (void)deinit
 {
     msg_Dbg(getIntf(), "Deinitializing input manager");
-    [_remoteControlService unsubscribeFromRemoteCommands];
+    if (@available(macOS 10.12.2, *)) {
+        [_remoteControlService unsubscribeFromRemoteCommands];
+    }
 
     if (p_current_input) {
         /* continue playback where you left off */
@@ -317,11 +321,8 @@ static int InputEvent(vlc_object_t *p_this, const char *psz_var,
         [[o_main mainMenu] setPause];
         [[o_main mainWindow] setPause];
 
-        if (OSX_SIERRA_DOT_TWO_AND_HIGHER) {
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wpartial-availability"
+        if (@available(macOS 10.12.2, *)) {
             [MPNowPlayingInfoCenter defaultCenter].playbackState = MPNowPlayingPlaybackStatePlaying;
-#pragma clang diagnostic pop
         }
     } else {
         [[o_main mainMenu] setSubmenusEnabled: FALSE];
@@ -331,11 +332,8 @@ static int InputEvent(vlc_object_t *p_this, const char *psz_var,
         if (state == PAUSE_S) {
             [self releaseSleepBlockers];
 
-            if (OSX_SIERRA_DOT_TWO_AND_HIGHER) {
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wpartial-availability"
+            if (@available(macOS 10.12.2, *)) {
                 [MPNowPlayingInfoCenter defaultCenter].playbackState = MPNowPlayingPlaybackStatePaused;
-#pragma clang diagnostic pop
             }
         }
 
@@ -353,11 +351,8 @@ static int InputEvent(vlc_object_t *p_this, const char *psz_var,
                                                            userInfo: nil
                                                             repeats: NO];
 
-            if (OSX_SIERRA_DOT_TWO_AND_HIGHER) {
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wpartial-availability"
+            if (@available(macOS 10.12.2, *)) {
                 [MPNowPlayingInfoCenter defaultCenter].playbackState = MPNowPlayingPlaybackStateStopped;
-#pragma clang diagnostic pop
             }
         }
     }
@@ -525,42 +520,37 @@ static int InputEvent(vlc_object_t *p_this, const char *psz_var,
     [[[o_main playlist] model] updateItem:p_input_item];
     [[[VLCMain sharedInstance] currentMediaInfoPanel] updatePanelWithItem:p_input_item];
 
-    if (!OSX_SIERRA_DOT_TWO_AND_HIGHER) {
-        return;
-    }
-
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wpartial-availability"
     if (!p_input_item) {
         return;
     }
 
-    NSMutableDictionary *currentlyPlayingTrackInfo = [NSMutableDictionary dictionary];
+    if (@available(macOS 10.12.2, *)) {
+        NSMutableDictionary *currentlyPlayingTrackInfo = [NSMutableDictionary dictionary];
 
-    currentlyPlayingTrackInfo[MPMediaItemPropertyPlaybackDuration] = @(SEC_FROM_VLC_TICK(input_item_GetDuration(p_input_item)));
-    currentlyPlayingTrackInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = @(var_GetInteger(p_current_input, "time"));
-    currentlyPlayingTrackInfo[MPNowPlayingInfoPropertyPlaybackRate] = @(var_GetFloat(p_current_input, "rate"));
+        currentlyPlayingTrackInfo[MPMediaItemPropertyPlaybackDuration] = @(SEC_FROM_VLC_TICK(input_item_GetDuration(p_input_item)));
+        currentlyPlayingTrackInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = @(var_GetInteger(p_current_input, "time"));
+        currentlyPlayingTrackInfo[MPNowPlayingInfoPropertyPlaybackRate] = @(var_GetFloat(p_current_input, "rate"));
 
-    char *psz_title = input_item_GetTitle(p_input_item);
-    if (!psz_title)
-        psz_title = input_item_GetName(p_input_item);
-    currentlyPlayingTrackInfo[MPMediaItemPropertyTitle] = toNSStr(psz_title);
-    FREENULL(psz_title);
+        char *psz_title = input_item_GetTitle(p_input_item);
+        if (!psz_title)
+            psz_title = input_item_GetName(p_input_item);
+        currentlyPlayingTrackInfo[MPMediaItemPropertyTitle] = toNSStr(psz_title);
+        FREENULL(psz_title);
 
-    char *psz_artist = input_item_GetArtist(p_input_item);
-    currentlyPlayingTrackInfo[MPMediaItemPropertyArtist] = toNSStr(psz_artist);
-    FREENULL(psz_artist);
+        char *psz_artist = input_item_GetArtist(p_input_item);
+        currentlyPlayingTrackInfo[MPMediaItemPropertyArtist] = toNSStr(psz_artist);
+        FREENULL(psz_artist);
 
-    char *psz_album = input_item_GetAlbum(p_input_item);
-    currentlyPlayingTrackInfo[MPMediaItemPropertyAlbumTitle] = toNSStr(psz_album);
-    FREENULL(psz_album);
+        char *psz_album = input_item_GetAlbum(p_input_item);
+        currentlyPlayingTrackInfo[MPMediaItemPropertyAlbumTitle] = toNSStr(psz_album);
+        FREENULL(psz_album);
 
-    char *psz_track_number = input_item_GetTrackNumber(p_input_item);
-    currentlyPlayingTrackInfo[MPMediaItemPropertyAlbumTrackNumber] = @([toNSStr(psz_track_number) intValue]);
-    FREENULL(psz_track_number);
+        char *psz_track_number = input_item_GetTrackNumber(p_input_item);
+        currentlyPlayingTrackInfo[MPMediaItemPropertyAlbumTrackNumber] = @([toNSStr(psz_track_number) intValue]);
+        FREENULL(psz_track_number);
 
-    [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = currentlyPlayingTrackInfo;
-#pragma clang diagnostic pop
+        [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = currentlyPlayingTrackInfo;
+    }
 }
 
 - (void)updateMainWindow
index 2e68cac..7dc95a9 100644 (file)
@@ -56,10 +56,6 @@ static inline NSArray * RemoteCommandCenterCommandsToHandle()
 
 - (void)subscribeToRemoteCommands
 {
-    if (!OSX_SIERRA_DOT_TWO_AND_HIGHER) {
-        return;
-    }
-
     MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter];
 
     //Enable when you want to support these
@@ -78,14 +74,11 @@ static inline NSArray * RemoteCommandCenterCommandsToHandle()
     for (MPRemoteCommand *command in RemoteCommandCenterCommandsToHandle()) {
         [command addTarget:self action:@selector(remoteCommandEvent:)];
     }
+
 }
 
 - (void)unsubscribeFromRemoteCommands
 {
-    if (!OSX_SIERRA_DOT_TWO_AND_HIGHER) {
-        return;
-    }
-
     [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = nil;
 
     for (MPRemoteCommand *command in RemoteCommandCenterCommandsToHandle()) {
index 53951c6..2fa8529 100644 (file)
         // Attach pull-down menu
         [self.statusItem setMenu:_vlcStatusBarIconMenu];
 
-        // Visibility is 10.12+
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wpartial-availability"
-        if (OSX_SIERRA_AND_HIGHER) {
+
+        if (@available(macOS 10.12, *)) {
             [self.statusItem setBehavior:NSStatusItemBehaviorRemovalAllowed];
             [self.statusItem setAutosaveName:@"statusBarItem"];
             [self.statusItem addObserver:self forKeyPath:NSStringFromSelector(@selector(isVisible))
         }
     }
 
-    if (OSX_SIERRA_AND_HIGHER) {
+    if (@available(macOS 10.12, *)) {
         // Sync VLC setting with status bar visibility setting (10.12 runtime only)
         [self.statusItem setVisible:YES];
     }
         return;
 
     // Lets keep alive the object in Sierra, and destroy it in older OS versions
-    if (OSX_SIERRA_AND_HIGHER) {
+    if (@available(macOS 10.12, *)) {
         self.statusItem.visible = NO;
     } else {
         [[NSStatusBar systemStatusBar] removeStatusItem:self.statusItem];
         self.statusItem = nil;
     }
-#pragma clang diagnostic pop
 }
 
 - (void)dealloc
index 9785862..63c65ab 100644 (file)
@@ -84,7 +84,7 @@
 
     if (b_nativeFullscreenMode) {
         [self setCollectionBehavior: NSWindowCollectionBehaviorFullScreenPrimary];
-    } else if (OSX_EL_CAPITAN_AND_HIGHER) {
+    } else if (@available(macOS 10.11, *)) {
         // Native fullscreen seems to be default on El Capitan, this disables it explicitely
         [self setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
     }