From 6d4bf603300e2aeadf8b9446b8758367bb8730b8 Mon Sep 17 00:00:00 2001 From: reuk Date: Mon, 1 Jul 2024 17:13:37 +0100 Subject: [PATCH] Platform: Remove compatibility checks for macOS 10.9 --- .../juce_ScopedLowPowerModeDisabler.cpp | 8 +- .../accessibility/juce_Accessibility_mac.mm | 63 +++++------- .../native/juce_FileChooser_mac.mm | 12 +-- .../native/juce_NSViewComponentPeer_mac.mm | 6 +- .../native/juce_NativeMessageBox_mac.mm | 11 +-- .../native/juce_PushNotifications_mac.cpp | 99 +++++++++---------- .../native/juce_WebBrowserComponent_mac.mm | 11 +-- modules/juce_video/native/juce_Video_mac.h | 7 +- 8 files changed, 82 insertions(+), 135 deletions(-) diff --git a/modules/juce_events/native/juce_ScopedLowPowerModeDisabler.cpp b/modules/juce_events/native/juce_ScopedLowPowerModeDisabler.cpp index 99f0a1faa1..a89f3dae7e 100644 --- a/modules/juce_events/native/juce_ScopedLowPowerModeDisabler.cpp +++ b/modules/juce_events/native/juce_ScopedLowPowerModeDisabler.cpp @@ -42,15 +42,13 @@ class ScopedLowPowerModeDisabler::Pimpl public: Pimpl() { - if (@available (macOS 10.9, *)) - activity = [[NSProcessInfo processInfo] beginActivityWithOptions: NSActivityUserInitiatedAllowingIdleSystemSleep - reason: @"App must remain in high-power mode"]; + activity = [[NSProcessInfo processInfo] beginActivityWithOptions: NSActivityUserInitiatedAllowingIdleSystemSleep + reason: @"App must remain in high-power mode"]; } ~Pimpl() { - if (@available (macOS 10.9, *)) - [[NSProcessInfo processInfo] endActivity: activity]; + [[NSProcessInfo processInfo] endActivity: activity]; } private: diff --git a/modules/juce_gui_basics/native/accessibility/juce_Accessibility_mac.mm b/modules/juce_gui_basics/native/accessibility/juce_Accessibility_mac.mm index c523e3db1b..36031ab251 100644 --- a/modules/juce_gui_basics/native/accessibility/juce_Accessibility_mac.mm +++ b/modules/juce_gui_basics/native/accessibility/juce_Accessibility_mac.mm @@ -872,27 +872,15 @@ static void sendHandlerNotification (const AccessibilityHandler& handler, if (! areAnyAccessibilityClientsActive() || notification == NSAccessibilityNotificationName{}) return; - if (@available (macOS 10.9, *)) + if (id accessibilityElement = static_cast (handler.getNativeImplementation())) { - if (id accessibilityElement = static_cast (handler.getNativeImplementation())) - { - sendAccessibilityEvent (accessibilityElement, notification, - (notification == NSAccessibilityLayoutChangedNotification - ? @{ NSAccessibilityUIElementsKey: @[ accessibilityElement ] } - : nil)); - } + sendAccessibilityEvent (accessibilityElement, notification, + (notification == NSAccessibilityLayoutChangedNotification + ? @{ NSAccessibilityUIElementsKey: @[ accessibilityElement ] } + : nil)); } } -static NSAccessibilityNotificationName layoutChangedNotification() -{ - if (@available (macOS 10.9, *)) - return NSAccessibilityLayoutChangedNotification; - - static NSString* layoutChangedString = @"AXLayoutChanged"; - return layoutChangedString; -} - void detail::AccessibilityHelpers::notifyAccessibilityEvent (const AccessibilityHandler& handler, Event eventType) { auto notification = [eventType] @@ -901,7 +889,7 @@ void detail::AccessibilityHelpers::notifyAccessibilityEvent (const Accessibility { case Event::elementCreated: return NSAccessibilityCreatedNotification; case Event::elementDestroyed: return NSAccessibilityUIElementDestroyedNotification; - case Event::elementMovedOrResized: return layoutChangedNotification(); + case Event::elementMovedOrResized: return NSAccessibilityLayoutChangedNotification; case Event::focusChanged: return NSAccessibilityFocusedUIElementChangedNotification; case Event::windowOpened: return NSAccessibilityWindowCreatedNotification; case Event::windowClosed: break; @@ -925,7 +913,7 @@ void AccessibilityHandler::notifyAccessibilityEvent (AccessibilityEvent eventTyp case AccessibilityEvent::textChanged: case AccessibilityEvent::valueChanged: return NSAccessibilityValueChangedNotification; case AccessibilityEvent::titleChanged: return NSAccessibilityTitleChangedNotification; - case AccessibilityEvent::structureChanged: return layoutChangedNotification(); + case AccessibilityEvent::structureChanged: return NSAccessibilityLayoutChangedNotification; } return NSAccessibilityNotificationName{}; @@ -939,31 +927,28 @@ void AccessibilityHandler::postAnnouncement (const String& announcementString, A if (! areAnyAccessibilityClientsActive()) return; - if (@available (macOS 10.9, *)) + auto nsPriority = [priority] { - auto nsPriority = [priority] + // The below doesn't get noticed by the @available check above + JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wunguarded-availability") + + switch (priority) { - // The below doesn't get noticed by the @available check above - JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wunguarded-availability") + case AnnouncementPriority::low: return NSAccessibilityPriorityLow; + case AnnouncementPriority::medium: return NSAccessibilityPriorityMedium; + case AnnouncementPriority::high: return NSAccessibilityPriorityHigh; + } - switch (priority) - { - case AnnouncementPriority::low: return NSAccessibilityPriorityLow; - case AnnouncementPriority::medium: return NSAccessibilityPriorityMedium; - case AnnouncementPriority::high: return NSAccessibilityPriorityHigh; - } + jassertfalse; + return NSAccessibilityPriorityLow; - jassertfalse; - return NSAccessibilityPriorityLow; + JUCE_END_IGNORE_WARNINGS_GCC_LIKE + }(); - JUCE_END_IGNORE_WARNINGS_GCC_LIKE - }(); - - sendAccessibilityEvent (static_cast ([NSApp mainWindow]), - NSAccessibilityAnnouncementRequestedNotification, - @{ NSAccessibilityAnnouncementKey: juceStringToNS (announcementString), - NSAccessibilityPriorityKey: @(nsPriority) }); - } + sendAccessibilityEvent (static_cast ([NSApp mainWindow]), + NSAccessibilityAnnouncementRequestedNotification, + @{ NSAccessibilityAnnouncementKey: juceStringToNS (announcementString), + NSAccessibilityPriorityKey: @(nsPriority) }); } } // namespace juce diff --git a/modules/juce_gui_basics/native/juce_FileChooser_mac.mm b/modules/juce_gui_basics/native/juce_FileChooser_mac.mm index a3070263ef..6544d649d7 100644 --- a/modules/juce_gui_basics/native/juce_FileChooser_mac.mm +++ b/modules/juce_gui_basics/native/juce_FileChooser_mac.mm @@ -255,17 +255,7 @@ private: exitModalState (0); - const auto okResult = []() -> NSInteger - { - if (@available (macOS 10.9, *)) - return NSModalResponseOK; - - JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wdeprecated-declarations") - return NSFileHandlingPanelOKButton; - JUCE_END_IGNORE_WARNINGS_GCC_LIKE - }(); - - if (panel != nil && result == okResult) + if (panel != nil && result == NSModalResponseOK) { auto addURLResult = [&chooserResults] (NSURL* urlToAdd) { diff --git a/modules/juce_gui_basics/native/juce_NSViewComponentPeer_mac.mm b/modules/juce_gui_basics/native/juce_NSViewComponentPeer_mac.mm index 89226b14b8..7f788c0597 100644 --- a/modules/juce_gui_basics/native/juce_NSViewComponentPeer_mac.mm +++ b/modules/juce_gui_basics/native/juce_NSViewComponentPeer_mac.mm @@ -261,8 +261,7 @@ public: if (! [window isOpaque]) [window setBackgroundColor: [NSColor clearColor]]; - if (@available (macOS 10.9, *)) - [view setAppearance: [NSAppearance appearanceNamed: NSAppearanceNameAqua]]; + [view setAppearance: [NSAppearance appearanceNamed: NSAppearanceNameAqua]]; [window setHasShadow: ((windowStyleFlags & windowHasDropShadow) != 0)]; @@ -2783,9 +2782,6 @@ struct JuceNSWindowClass final : public NSViewComponentPeerWrapperhasNativeTitleBar() && (owner->getStyleFlags() & ComponentPeer::windowIsResizable) == 0) [owner->window setStyleMask: NSWindowStyleMaskBorderless]; diff --git a/modules/juce_gui_basics/native/juce_NativeMessageBox_mac.mm b/modules/juce_gui_basics/native/juce_NativeMessageBox_mac.mm index b977591d9b..db86983a18 100644 --- a/modules/juce_gui_basics/native/juce_NativeMessageBox_mac.mm +++ b/modules/juce_gui_basics/native/juce_NativeMessageBox_mac.mm @@ -60,15 +60,12 @@ std::unique_ptr ScopedMessageBoxInterface::create (co { if (auto* window = [view window]) { - if (@available (macOS 10.9, *)) + [alertWindow.get() beginSheetModalForWindow: window completionHandler: ^(NSModalResponse result) { - [alertWindow.get() beginSheetModalForWindow: window completionHandler: ^(NSModalResponse result) - { - onDone (result); - }]; + onDone (result); + }]; - return; - } + return; } } } diff --git a/modules/juce_gui_extra/native/juce_PushNotifications_mac.cpp b/modules/juce_gui_extra/native/juce_PushNotifications_mac.cpp index e3906f60e6..05ee92ca16 100644 --- a/modules/juce_gui_extra/native/juce_PushNotifications_mac.cpp +++ b/modules/juce_gui_extra/native/juce_PushNotifications_mac.cpp @@ -85,52 +85,49 @@ namespace PushNotificationsDelegateDetailsOsx if (n.actions.size() > 0) notification.actionButtonTitle = juceStringToNS (n.actions.getReference (0).title); - if (@available (macOS 10.9, *)) + notification.identifier = juceStringToNS (n.identifier); + + if (n.actions.size() > 0) { - notification.identifier = juceStringToNS (n.identifier); + notification.hasReplyButton = n.actions.getReference (0).style == Action::text; + notification.responsePlaceholder = juceStringToNS (n.actions.getReference (0).textInputPlaceholder); + } - if (n.actions.size() > 0) + auto* imageDirectory = n.icon.contains ("/") + ? juceStringToNS (n.icon.upToLastOccurrenceOf ("/", false, true)) + : [NSString string]; + + auto* imageName = juceStringToNS (n.icon.fromLastOccurrenceOf ("/", false, false) + .upToLastOccurrenceOf (".", false, false)); + auto* imageExtension = juceStringToNS (n.icon.fromLastOccurrenceOf (".", false, false)); + + NSString* imagePath = nil; + + if ([imageDirectory length] == NSUInteger (0)) + { + imagePath = [[NSBundle mainBundle] pathForResource: imageName + ofType: imageExtension]; + } + else + { + imagePath = [[NSBundle mainBundle] pathForResource: imageName + ofType: imageExtension + inDirectory: imageDirectory]; + } + + notification.contentImage = [[NSImage alloc] initWithContentsOfFile: imagePath]; + + if (@available (macOS 10.10, *)) + { + if (n.actions.size() > 1) { - notification.hasReplyButton = n.actions.getReference (0).style == Action::text; - notification.responsePlaceholder = juceStringToNS (n.actions.getReference (0).textInputPlaceholder); - } + auto additionalActions = [NSMutableArray arrayWithCapacity: (NSUInteger) n.actions.size() - 1]; - auto* imageDirectory = n.icon.contains ("/") - ? juceStringToNS (n.icon.upToLastOccurrenceOf ("/", false, true)) - : [NSString string]; + for (int a = 1; a < n.actions.size(); ++a) + [additionalActions addObject: [NSUserNotificationAction actionWithIdentifier: juceStringToNS (n.actions[a].identifier) + title: juceStringToNS (n.actions[a].title)]]; - auto* imageName = juceStringToNS (n.icon.fromLastOccurrenceOf ("/", false, false) - .upToLastOccurrenceOf (".", false, false)); - auto* imageExtension = juceStringToNS (n.icon.fromLastOccurrenceOf (".", false, false)); - - NSString* imagePath = nil; - - if ([imageDirectory length] == NSUInteger (0)) - { - imagePath = [[NSBundle mainBundle] pathForResource: imageName - ofType: imageExtension]; - } - else - { - imagePath = [[NSBundle mainBundle] pathForResource: imageName - ofType: imageExtension - inDirectory: imageDirectory]; - } - - notification.contentImage = [[NSImage alloc] initWithContentsOfFile: imagePath]; - - if (@available (macOS 10.10, *)) - { - if (n.actions.size() > 1) - { - auto additionalActions = [NSMutableArray arrayWithCapacity: (NSUInteger) n.actions.size() - 1]; - - for (int a = 1; a < n.actions.size(); ++a) - [additionalActions addObject: [NSUserNotificationAction actionWithIdentifier: juceStringToNS (n.actions[a].identifier) - title: juceStringToNS (n.actions[a].title)]]; - - notification.additionalActions = additionalActions; - } + notification.additionalActions = additionalActions; } } @@ -165,13 +162,10 @@ namespace PushNotificationsDelegateDetailsOsx notif.soundToPlay = URL (nsStringToJuce (n.soundName)); notif.properties = nsDictionaryToVar (n.userInfo); - if (@available (macOS 10.9, *)) - { - notif.identifier = nsStringToJuce (n.identifier); + notif.identifier = nsStringToJuce (n.identifier); - if (n.contentImage != nil) - notif.icon = nsStringToJuce ([n.contentImage name]); - } + if (n.contentImage != nil) + notif.icon = nsStringToJuce ([n.contentImage name]); Array actions; @@ -180,14 +174,11 @@ namespace PushNotificationsDelegateDetailsOsx Action action; action.title = nsStringToJuce (n.actionButtonTitle); - if (@available (macOS 10.9, *)) - { - if (n.hasReplyButton) - action.style = Action::text; + if (n.hasReplyButton) + action.style = Action::text; - if (n.responsePlaceholder != nil) - action.textInputPlaceholder = nsStringToJuce (n.responsePlaceholder); - } + if (n.responsePlaceholder != nil) + action.textInputPlaceholder = nsStringToJuce (n.responsePlaceholder); actions.add (action); } diff --git a/modules/juce_gui_extra/native/juce_WebBrowserComponent_mac.mm b/modules/juce_gui_extra/native/juce_WebBrowserComponent_mac.mm index 3b47e8fbac..a049a4bf50 100644 --- a/modules/juce_gui_extra/native/juce_WebBrowserComponent_mac.mm +++ b/modules/juce_gui_extra/native/juce_WebBrowserComponent_mac.mm @@ -72,16 +72,7 @@ static NSMutableURLRequest* getRequestForURL (const String& url, const StringArr { NSString* urlString = juceStringToNS (url); - if (@available (macOS 10.9, *)) - { - urlString = [urlString stringByAddingPercentEncodingWithAllowedCharacters: [NSCharacterSet URLQueryAllowedCharacterSet]]; - } - else - { - JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wdeprecated-declarations") - urlString = [urlString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; - JUCE_END_IGNORE_WARNINGS_GCC_LIKE - } + urlString = [urlString stringByAddingPercentEncodingWithAllowedCharacters: [NSCharacterSet URLQueryAllowedCharacterSet]]; if (NSURL* nsURL = [NSURL URLWithString: urlString]) { diff --git a/modules/juce_video/native/juce_Video_mac.h b/modules/juce_video/native/juce_Video_mac.h index 2463889ab4..e515c5a2d9 100644 --- a/modules/juce_video/native/juce_Video_mac.h +++ b/modules/juce_video/native/juce_Video_mac.h @@ -597,9 +597,8 @@ private: { wrappedPlayer = [&]() -> std::unique_ptr { - if (@available (macOS 10.9, *)) - if (useNativeControls) - return std::make_unique(); + if (useNativeControls) + return std::make_unique(); return std::make_unique(); }(); @@ -669,7 +668,7 @@ private: NSUniquePtr playerLayer { [[AVPlayerLayer alloc] init] }; }; - class API_AVAILABLE (macos (10.9)) WrappedPlayerView : public WrappedPlayer + class WrappedPlayerView : public WrappedPlayer { public: WrappedPlayerView() = default;