diff --git a/atom/browser/browser_mac.mm b/atom/browser/browser_mac.mm index d09b13b1d4..e7960bafc8 100644 --- a/atom/browser/browser_mac.mm +++ b/atom/browser/browser_mac.mm @@ -145,9 +145,13 @@ void Browser::SetUserActivity(const std::string& type, } std::string Browser::GetCurrentActivityType() { - NSUserActivity* userActivity = - [[AtomApplication sharedApplication] getCurrentActivity]; - return base::SysNSStringToUTF8(userActivity.activityType); + if (@available(macOS 10.10, *)) { + NSUserActivity* userActivity = + [[AtomApplication sharedApplication] getCurrentActivity]; + return base::SysNSStringToUTF8(userActivity.activityType); + } else { + return std::string(); + } } void Browser::InvalidateCurrentActivity() { diff --git a/atom/browser/mac/atom_application.h b/atom/browser/mac/atom_application.h index 5015608d6f..b0a8742ee9 100644 --- a/atom/browser/mac/atom_application.h +++ b/atom/browser/mac/atom_application.h @@ -11,7 +11,7 @@ NSUserActivityDelegate> { @private BOOL handlingSendEvent_; - base::scoped_nsobject currentActivity_; + base::scoped_nsobject currentActivity_ API_AVAILABLE(macosx(10.10)); NSCondition* handoffLock_; BOOL updateReceived_; base::Callback shouldShutdown_; @@ -27,7 +27,7 @@ // CrAppControlProtocol: - (void)setHandlingSendEvent:(BOOL)handlingSendEvent; -- (NSUserActivity*)getCurrentActivity; +- (NSUserActivity*)getCurrentActivity API_AVAILABLE(macosx(10.10)); - (void)setCurrentActivity:(NSString*)type withUserInfo:(NSDictionary*)userInfo withWebpageURL:(NSURL*)webpageURL; diff --git a/atom/browser/mac/atom_application.mm b/atom/browser/mac/atom_application.mm index ef7238bfda..ed849fbf17 100644 --- a/atom/browser/mac/atom_application.mm +++ b/atom/browser/mac/atom_application.mm @@ -58,13 +58,15 @@ inline void dispatch_sync_main(dispatch_block_t block) { - (void)setCurrentActivity:(NSString*)type withUserInfo:(NSDictionary*)userInfo withWebpageURL:(NSURL*)webpageURL { - currentActivity_ = base::scoped_nsobject( - [[NSUserActivity alloc] initWithActivityType:type]); - [currentActivity_ setUserInfo:userInfo]; - [currentActivity_ setWebpageURL:webpageURL]; - [currentActivity_ setDelegate:self]; - [currentActivity_ becomeCurrent]; - [currentActivity_ setNeedsSave:YES]; + if (@available(macOS 10.10, *)) { + currentActivity_ = base::scoped_nsobject( + [[NSUserActivity alloc] initWithActivityType:type]); + [currentActivity_ setUserInfo:userInfo]; + [currentActivity_ setWebpageURL:webpageURL]; + [currentActivity_ setDelegate:self]; + [currentActivity_ becomeCurrent]; + [currentActivity_ setNeedsSave:YES]; + } } - (NSUserActivity*)getCurrentActivity { @@ -90,7 +92,7 @@ inline void dispatch_sync_main(dispatch_block_t block) { [handoffLock_ unlock]; } -- (void)userActivityWillSave:(NSUserActivity *)userActivity { +- (void)userActivityWillSave:(NSUserActivity *)userActivity API_AVAILABLE(macosx(10.10)) { __block BOOL shouldWait = NO; dispatch_sync_main(^{ std::string activity_type(base::SysNSStringToUTF8(userActivity.activityType)); @@ -114,7 +116,7 @@ inline void dispatch_sync_main(dispatch_block_t block) { [userActivity setNeedsSave:YES]; } -- (void)userActivityWasContinued:(NSUserActivity *)userActivity { +- (void)userActivityWasContinued:(NSUserActivity *)userActivity API_AVAILABLE(macosx(10.10)) { dispatch_async(dispatch_get_main_queue(), ^{ std::string activity_type(base::SysNSStringToUTF8(userActivity.activityType)); std::unique_ptr user_info = diff --git a/atom/browser/mac/atom_application_delegate.mm b/atom/browser/mac/atom_application_delegate.mm index e210ad2b6a..8a79f4de6e 100644 --- a/atom/browser/mac/atom_application_delegate.mm +++ b/atom/browser/mac/atom_application_delegate.mm @@ -96,7 +96,8 @@ static base::mac::ScopedObjCClassSwizzler* g_swizzle_imk_input_session; - (BOOL)application:(NSApplication*)sender continueUserActivity:(NSUserActivity*)userActivity - restorationHandler:(void (^)(NSArray*restorableObjects))restorationHandler { + restorationHandler:(void (^)(NSArray*restorableObjects))restorationHandler + API_AVAILABLE(macosx(10.10)) { std::string activity_type(base::SysNSStringToUTF8(userActivity.activityType)); std::unique_ptr user_info = atom::NSDictionaryToDictionaryValue(userActivity.userInfo); diff --git a/atom/browser/native_browser_view_mac.mm b/atom/browser/native_browser_view_mac.mm index 86df632638..bf285249b6 100644 --- a/atom/browser/native_browser_view_mac.mm +++ b/atom/browser/native_browser_view_mac.mm @@ -50,7 +50,9 @@ const NSAutoresizingMaskOptions kDefaultAutoResizingMask = postNotificationName:NSWindowWillMoveNotification object:self]; - [self.window performWindowDragWithEvent:event]; + if (@available(macOS 10.11, *)) { + [self.window performWindowDragWithEvent:event]; + } return; } diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index dfe5c2e360..e832c25261 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -314,59 +314,60 @@ bool ScopedDisableResize::disable_resize_ = false; shell_->SetResizable(true); // Hide the native toolbar before entering fullscreen, so there is no visual // artifacts. - if (base::mac::IsAtLeastOS10_10() && - shell_->title_bar_style() == atom::NativeWindowMac::HIDDEN_INSET) { - NSWindow* window = shell_->GetNativeWindow(); - [window setToolbar:nil]; + if (@available(macOS 10.10, *)) { + if (shell_->title_bar_style() == atom::NativeWindowMac::HIDDEN_INSET) { + NSWindow* window = shell_->GetNativeWindow(); + [window setToolbar:nil]; + } } } - (void)windowDidEnterFullScreen:(NSNotification*)notification { shell_->NotifyWindowEnterFullScreen(); - // For frameless window we don't show set title for normal mode since the - // titlebar is expected to be empty, but after entering fullscreen mode we - // have to set one, because title bar is visible here. - NSWindow* window = shell_->GetNativeWindow(); - if ((shell_->transparent() || !shell_->has_frame()) && - base::mac::IsAtLeastOS10_10() && - // FIXME(zcbenz): Showing titlebar for hiddenInset window is weird under + if (@available(macOS 10.10, *)) { + // For frameless window we don't show set title for normal mode since the + // titlebar is expected to be empty, but after entering fullscreen mode we + // have to set one, because title bar is visible here. + NSWindow* window = shell_->GetNativeWindow(); + if ((shell_->transparent() || !shell_->has_frame()) && + // FIXME(zcbenz): Showing titlebar for hiddenInset window is weird under + // fullscreen mode. + // Show title if fullscreen_window_title flag is set + (shell_->title_bar_style() != atom::NativeWindowMac::HIDDEN_INSET || + shell_->fullscreen_window_title())) { + [window setTitleVisibility:NSWindowTitleVisible]; + } + + // Restore the native toolbar immediately after entering fullscreen, if we do + // this before leaving fullscreen, traffic light buttons will be jumping. + if (shell_->title_bar_style() == atom::NativeWindowMac::HIDDEN_INSET) { + base::scoped_nsobject toolbar( + [[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"]); + [toolbar setShowsBaselineSeparator:NO]; + [window setToolbar:toolbar]; + + // Set window style to hide the toolbar, otherwise the toolbar will show in // fullscreen mode. - // Show title if fullscreen_window_title flag is set - (shell_->title_bar_style() != atom::NativeWindowMac::HIDDEN_INSET || - shell_->fullscreen_window_title())) { - [window setTitleVisibility:NSWindowTitleVisible]; - } - - // Restore the native toolbar immediately after entering fullscreen, if we do - // this before leaving fullscreen, traffic light buttons will be jumping. - if (base::mac::IsAtLeastOS10_10() && - shell_->title_bar_style() == atom::NativeWindowMac::HIDDEN_INSET) { - base::scoped_nsobject toolbar( - [[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"]); - [toolbar setShowsBaselineSeparator:NO]; - [window setToolbar:toolbar]; - - // Set window style to hide the toolbar, otherwise the toolbar will show in - // fullscreen mode. - shell_->SetStyleMask(true, NSFullSizeContentViewWindowMask); + shell_->SetStyleMask(true, NSFullSizeContentViewWindowMask); + } } } - (void)windowWillExitFullScreen:(NSNotification*)notification { - // Restore the titlebar visibility. - NSWindow* window = shell_->GetNativeWindow(); - if ((shell_->transparent() || !shell_->has_frame()) && - base::mac::IsAtLeastOS10_10() && - (shell_->title_bar_style() != atom::NativeWindowMac::HIDDEN_INSET || - shell_->fullscreen_window_title())) { - [window setTitleVisibility:NSWindowTitleHidden]; - } + if (@available(macOS 10.10, *)) { + // Restore the titlebar visibility. + NSWindow* window = shell_->GetNativeWindow(); + if ((shell_->transparent() || !shell_->has_frame()) && + (shell_->title_bar_style() != atom::NativeWindowMac::HIDDEN_INSET || + shell_->fullscreen_window_title())) { + [window setTitleVisibility:NSWindowTitleHidden]; + } - // Turn off the style for toolbar. - if (base::mac::IsAtLeastOS10_10() && - shell_->title_bar_style() == atom::NativeWindowMac::HIDDEN_INSET) { - shell_->SetStyleMask(false, NSFullSizeContentViewWindowMask); + // Turn off the style for toolbar. + if (shell_->title_bar_style() == atom::NativeWindowMac::HIDDEN_INSET) { + shell_->SetStyleMask(false, NSFullSizeContentViewWindowMask); + } } } @@ -487,7 +488,8 @@ enum { enable_larger_than_screen_ = enable; } -- (void)resetTouchBar:(const std::vector&)settings { +- (void)resetTouchBar:(const std::vector&)settings + API_AVAILABLE(macosx(10.12.2)) { if (![self respondsToSelector:@selector(touchBar)]) return; atom_touch_bar_.reset([[AtomTouchBar alloc] initWithDelegate:self @@ -496,12 +498,13 @@ enum { self.touchBar = nil; } -- (void)refreshTouchBarItem:(const std::string&)item_id { +- (void)refreshTouchBarItem:(const std::string&)item_id + API_AVAILABLE(macosx(10.12.2)) { if (atom_touch_bar_ && self.touchBar) [atom_touch_bar_ refreshTouchBarItem:self.touchBar id:item_id]; } -- (NSTouchBar*)makeTouchBar { +- (NSTouchBar*)makeTouchBar API_AVAILABLE(macosx(10.12.2)) { if (atom_touch_bar_) return [atom_touch_bar_ makeTouchBar]; else @@ -509,14 +512,15 @@ enum { } - (NSTouchBarItem*)touchBar:(NSTouchBar*)touchBar - makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier { + makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier API_AVAILABLE(macosx(10.12.2)) { if (touchBar && atom_touch_bar_) return [atom_touch_bar_ makeItemForIdentifier:identifier]; else return nil; } -- (void)setEscapeTouchBarItem:(const mate::PersistentDictionary&)item { +- (void)setEscapeTouchBarItem:(const mate::PersistentDictionary&)item + API_AVAILABLE(macosx(10.12.2)) { if (atom_touch_bar_ && self.touchBar) [atom_touch_bar_ setEscapeTouchBarItem:item forTouchBar:self.touchBar]; } @@ -828,10 +832,11 @@ NativeWindowMac::NativeWindowMac(const mate::Dictionary& options, } NSUInteger styleMask = NSTitledWindowMask; - if (title_bar_style_ == CUSTOM_BUTTONS_ON_HOVER && - base::mac::IsAtLeastOS10_10() && - (!useStandardWindow || transparent() || !has_frame())) { - styleMask = NSFullSizeContentViewWindowMask; + if (@available(macOS 10.10, *)) { + if (title_bar_style_ == CUSTOM_BUTTONS_ON_HOVER && + (!useStandardWindow || transparent() || !has_frame())) { + styleMask = NSFullSizeContentViewWindowMask; + } } if (minimizable) { styleMask |= NSMiniaturizableWindowMask; @@ -885,7 +890,7 @@ NativeWindowMac::NativeWindowMac(const mate::Dictionary& options, [window_ setDisableKeyOrMainWindow:YES]; if (transparent() || !has_frame()) { - if (base::mac::IsAtLeastOS10_10()) { + if (@available(macOS 10.10, *)) { // Don't show title bar. [window_ setTitlebarAppearsTransparent:YES]; [window_ setTitleVisibility:NSWindowTitleHidden]; @@ -897,11 +902,11 @@ NativeWindowMac::NativeWindowMac(const mate::Dictionary& options, // Create a tab only if tabbing identifier is specified and window has // a native title bar. if (tabbingIdentifier.empty() || transparent() || !has_frame()) { - if ([window_ respondsToSelector:@selector(tabbingMode)]) { + if (@available(macOS 10.12, *)) { [window_ setTabbingMode:NSWindowTabbingModeDisallowed]; } } else { - if ([window_ respondsToSelector:@selector(tabbingIdentifier)]) { + if (@available(macOS 10.12, *)) { [window_ setTabbingIdentifier:base::SysUTF8ToNSString(tabbingIdentifier)]; } } @@ -911,14 +916,14 @@ NativeWindowMac::NativeWindowMac(const mate::Dictionary& options, // Hide the title bar background if (title_bar_style_ != NORMAL) { - if (base::mac::IsAtLeastOS10_10()) { + if (@available(macOS 10.10, *)) { [window_ setTitlebarAppearsTransparent:YES]; } } // Hide the title bar. if (title_bar_style_ == HIDDEN_INSET) { - if (base::mac::IsAtLeastOS10_10()) { + if (@available(macOS 10.10, *)) { base::scoped_nsobject toolbar( [[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"]); [toolbar setShowsBaselineSeparator:NO]; @@ -1650,31 +1655,31 @@ void NativeWindowMac::SetAutoHideCursor(bool auto_hide) { } void NativeWindowMac::SelectPreviousTab() { - if ([window_ respondsToSelector:@selector(selectPreviousTab:)]) { + if (@available(macOS 10.12, *)) { [window_ selectPreviousTab:nil]; } } void NativeWindowMac::SelectNextTab() { - if ([window_ respondsToSelector:@selector(selectNextTab:)]) { + if (@available(macOS 10.12, *)) { [window_ selectNextTab:nil]; } } void NativeWindowMac::MergeAllWindows() { - if ([window_ respondsToSelector:@selector(mergeAllWindows:)]) { + if (@available(macOS 10.12, *)) { [window_ mergeAllWindows:nil]; } } void NativeWindowMac::MoveTabToNewWindow() { - if ([window_ respondsToSelector:@selector(moveTabToNewWindow:)]) { + if (@available(macOS 10.12, *)) { [window_ moveTabToNewWindow:nil]; } } void NativeWindowMac::ToggleTabBar() { - if ([window_ respondsToSelector:@selector(toggleTabBar:)]) { + if (@available(macOS 10.12, *)) { [window_ toggleTabBar:nil]; } } @@ -1683,91 +1688,91 @@ bool NativeWindowMac::AddTabbedWindow(NativeWindow* window) { if (window_.get() == window->GetNativeWindow()) { return false; } else { - if ([window_ respondsToSelector:@selector(addTabbedWindow:ordered:)]) + if (@available(macOS 10.12, *)) [window_ addTabbedWindow:window->GetNativeWindow() ordered:NSWindowAbove]; } return true; } void NativeWindowMac::SetVibrancy(const std::string& type) { - if (!base::mac::IsAtLeastOS10_10()) return; + if (@available(macOS 10.10, *)) { + NSView* vibrant_view = [window_ vibrantView]; - NSView* vibrant_view = [window_ vibrantView]; + if (type.empty()) { + if (background_color_before_vibrancy_) { + [window_ setBackgroundColor:background_color_before_vibrancy_]; + [window_ setTitlebarAppearsTransparent:transparency_before_vibrancy_]; + } + if (vibrant_view == nil) return; - if (type.empty()) { - if (background_color_before_vibrancy_) { - [window_ setBackgroundColor:background_color_before_vibrancy_]; - [window_ setTitlebarAppearsTransparent:transparency_before_vibrancy_]; + [vibrant_view removeFromSuperview]; + [window_ setVibrantView:nil]; + ui::GpuSwitchingManager::SetTransparent(transparent()); + + return; } - if (vibrant_view == nil) return; - [vibrant_view removeFromSuperview]; - [window_ setVibrantView:nil]; - ui::GpuSwitchingManager::SetTransparent(transparent()); + background_color_before_vibrancy_.reset([[window_ backgroundColor] retain]); + transparency_before_vibrancy_ = [window_ titlebarAppearsTransparent]; + ui::GpuSwitchingManager::SetTransparent(true); - return; - } - - background_color_before_vibrancy_.reset([[window_ backgroundColor] retain]); - transparency_before_vibrancy_ = [window_ titlebarAppearsTransparent]; - ui::GpuSwitchingManager::SetTransparent(true); - - if (title_bar_style_ != NORMAL) { - [window_ setTitlebarAppearsTransparent:YES]; - [window_ setBackgroundColor:[NSColor clearColor]]; - } - - NSVisualEffectView* effect_view = (NSVisualEffectView*)vibrant_view; - if (effect_view == nil) { - effect_view = [[[NSVisualEffectView alloc] - initWithFrame: [[window_ contentView] bounds]] autorelease]; - [window_ setVibrantView:(NSView*)effect_view]; - - [effect_view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; - [effect_view setBlendingMode:NSVisualEffectBlendingModeBehindWindow]; - [effect_view setState:NSVisualEffectStateActive]; - [[window_ contentView] addSubview:effect_view - positioned:NSWindowBelow - relativeTo:nil]; - } - - NSVisualEffectMaterial vibrancyType = NSVisualEffectMaterialLight; - - if (type == "appearance-based") { - vibrancyType = NSVisualEffectMaterialAppearanceBased; - } else if (type == "light") { - vibrancyType = NSVisualEffectMaterialLight; - } else if (type == "dark") { - vibrancyType = NSVisualEffectMaterialDark; - } else if (type == "titlebar") { - vibrancyType = NSVisualEffectMaterialTitlebar; - } - - if (base::mac::IsAtLeastOS10_11()) { - // TODO(kevinsawicki): Use NSVisualEffectMaterial* constants directly once - // they are available in the minimum SDK version - if (type == "selection") { - // NSVisualEffectMaterialSelection - vibrancyType = static_cast(4); - } else if (type == "menu") { - // NSVisualEffectMaterialMenu - vibrancyType = static_cast(5); - } else if (type == "popover") { - // NSVisualEffectMaterialPopover - vibrancyType = static_cast(6); - } else if (type == "sidebar") { - // NSVisualEffectMaterialSidebar - vibrancyType = static_cast(7); - } else if (type == "medium-light") { - // NSVisualEffectMaterialMediumLight - vibrancyType = static_cast(8); - } else if (type == "ultra-dark") { - // NSVisualEffectMaterialUltraDark - vibrancyType = static_cast(9); + if (title_bar_style_ != NORMAL) { + [window_ setTitlebarAppearsTransparent:YES]; + [window_ setBackgroundColor:[NSColor clearColor]]; } - } - [effect_view setMaterial:vibrancyType]; + NSVisualEffectView* effect_view = (NSVisualEffectView*)vibrant_view; + if (effect_view == nil) { + effect_view = [[[NSVisualEffectView alloc] + initWithFrame: [[window_ contentView] bounds]] autorelease]; + [window_ setVibrantView:(NSView*)effect_view]; + + [effect_view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; + [effect_view setBlendingMode:NSVisualEffectBlendingModeBehindWindow]; + [effect_view setState:NSVisualEffectStateActive]; + [[window_ contentView] addSubview:effect_view + positioned:NSWindowBelow + relativeTo:nil]; + } + + NSVisualEffectMaterial vibrancyType = NSVisualEffectMaterialLight; + + if (type == "appearance-based") { + vibrancyType = NSVisualEffectMaterialAppearanceBased; + } else if (type == "light") { + vibrancyType = NSVisualEffectMaterialLight; + } else if (type == "dark") { + vibrancyType = NSVisualEffectMaterialDark; + } else if (type == "titlebar") { + vibrancyType = NSVisualEffectMaterialTitlebar; + } + + if (@available(macOS 10.11, *)) { + // TODO(kevinsawicki): Use NSVisualEffectMaterial* constants directly once + // they are available in the minimum SDK version + if (type == "selection") { + // NSVisualEffectMaterialSelection + vibrancyType = static_cast(4); + } else if (type == "menu") { + // NSVisualEffectMaterialMenu + vibrancyType = static_cast(5); + } else if (type == "popover") { + // NSVisualEffectMaterialPopover + vibrancyType = static_cast(6); + } else if (type == "sidebar") { + // NSVisualEffectMaterialSidebar + vibrancyType = static_cast(7); + } else if (type == "medium-light") { + // NSVisualEffectMaterialMediumLight + vibrancyType = static_cast(8); + } else if (type == "ultra-dark") { + // NSVisualEffectMaterialUltraDark + vibrancyType = static_cast(9); + } + } + + [effect_view setMaterial:vibrancyType]; + } } void NativeWindowMac::SetTouchBar( diff --git a/atom/browser/ui/cocoa/atom_touch_bar.h b/atom/browser/ui/cocoa/atom_touch_bar.h index 75f894b7fb..80fda66ee6 100644 --- a/atom/browser/ui/cocoa/atom_touch_bar.h +++ b/atom/browser/ui/cocoa/atom_touch_bar.h @@ -31,16 +31,16 @@ window:(atom::NativeWindow*)window settings:(const std::vector&)settings; -- (NSTouchBar*)makeTouchBar; -- (NSTouchBar*)touchBarFromItemIdentifiers:(NSMutableArray*)items; +- (NSTouchBar*)makeTouchBar API_AVAILABLE(macosx(10.12.2)); +- (NSTouchBar*)touchBarFromItemIdentifiers:(NSMutableArray*)items API_AVAILABLE(macosx(10.12.2)); - (NSMutableArray*)identifiersFromSettings: (const std::vector&)settings; - (void)refreshTouchBarItem:(NSTouchBar*)touchBar - id:(const std::string&)item_id; + id:(const std::string&)item_id API_AVAILABLE(macosx(10.12.2)); - (void)addNonDefaultTouchBarItems: (const std::vector&)items; - (void)setEscapeTouchBarItem:(const mate::PersistentDictionary&)item - forTouchBar:(NSTouchBar*)touchBar; + forTouchBar:(NSTouchBar*)touchBar API_AVAILABLE(macosx(10.12.2)); - (NSString*)idFromIdentifier:(NSString*)identifier withPrefix:(NSString*)prefix; @@ -51,35 +51,36 @@ // Selector actions - (void)buttonAction:(id)sender; -- (void)colorPickerAction:(id)sender; -- (void)sliderAction:(id)sender; +- (void)colorPickerAction:(id)sender API_AVAILABLE(macosx(10.12.2)); +- (void)sliderAction:(id)sender API_AVAILABLE(macosx(10.12.2)); // Helpers to create touch bar items -- (NSTouchBarItem*)makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier; +- (NSTouchBarItem*)makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier + API_AVAILABLE(macosx(10.12.2)); - (NSTouchBarItem*)makeButtonForID:(NSString*)id - withIdentifier:(NSString*)identifier; + withIdentifier:(NSString*)identifier API_AVAILABLE(macosx(10.12.2)); - (NSTouchBarItem*)makeLabelForID:(NSString*)id - withIdentifier:(NSString*)identifier; + withIdentifier:(NSString*)identifier API_AVAILABLE(macosx(10.12.2)); - (NSTouchBarItem*)makeColorPickerForID:(NSString*)id - withIdentifier:(NSString*)identifier; + withIdentifier:(NSString*)identifier API_AVAILABLE(macosx(10.12.2)); - (NSTouchBarItem*)makeSliderForID:(NSString*)id - withIdentifier:(NSString*)identifier; + withIdentifier:(NSString*)identifier API_AVAILABLE(macosx(10.12.2)); - (NSTouchBarItem*)makePopoverForID:(NSString*)id - withIdentifier:(NSString*)identifier; + withIdentifier:(NSString*)identifier API_AVAILABLE(macosx(10.12.2)); - (NSTouchBarItem*)makeGroupForID:(NSString*)id - withIdentifier:(NSString*)identifier; + withIdentifier:(NSString*)identifier API_AVAILABLE(macosx(10.12.2)); // Helpers to update touch bar items - (void)updateButton:(NSCustomTouchBarItem*)item - withSettings:(const mate::PersistentDictionary&)settings; + withSettings:(const mate::PersistentDictionary&)settings API_AVAILABLE(macosx(10.12.2)); - (void)updateLabel:(NSCustomTouchBarItem*)item - withSettings:(const mate::PersistentDictionary&)settings; + withSettings:(const mate::PersistentDictionary&)settings API_AVAILABLE(macosx(10.12.2)); - (void)updateColorPicker:(NSColorPickerTouchBarItem*)item - withSettings:(const mate::PersistentDictionary&)settings; + withSettings:(const mate::PersistentDictionary&)settings API_AVAILABLE(macosx(10.12.2)); - (void)updateSlider:(NSSliderTouchBarItem*)item - withSettings:(const mate::PersistentDictionary&)settings; + withSettings:(const mate::PersistentDictionary&)settings API_AVAILABLE(macosx(10.12.2)); - (void)updatePopover:(NSPopoverTouchBarItem*)item - withSettings:(const mate::PersistentDictionary&)settings; + withSettings:(const mate::PersistentDictionary&)settings API_AVAILABLE(macosx(10.12.2)); @end diff --git a/atom/browser/ui/cocoa/atom_touch_bar.mm b/atom/browser/ui/cocoa/atom_touch_bar.mm index d5c9a0f811..1e0ee7b695 100644 --- a/atom/browser/ui/cocoa/atom_touch_bar.mm +++ b/atom/browser/ui/cocoa/atom_touch_bar.mm @@ -51,32 +51,34 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; - (NSMutableArray*)identifiersFromSettings:(const std::vector&)dicts { NSMutableArray* identifiers = [NSMutableArray array]; - for (const auto& item : dicts) { - std::string type; - std::string item_id; - if (item.Get("type", &type) && item.Get("id", &item_id)) { - NSTouchBarItemIdentifier identifier = nil; - if (type == "spacer") { - std::string size; - item.Get("size", &size); - if (size == "large") { - identifier = NSTouchBarItemIdentifierFixedSpaceLarge; - } else if (size == "flexible") { - identifier = NSTouchBarItemIdentifierFlexibleSpace; + if (@available(macOS 10.12.2, *)) { + for (const auto& item : dicts) { + std::string type; + std::string item_id; + if (item.Get("type", &type) && item.Get("id", &item_id)) { + NSTouchBarItemIdentifier identifier = nil; + if (type == "spacer") { + std::string size; + item.Get("size", &size); + if (size == "large") { + identifier = NSTouchBarItemIdentifierFixedSpaceLarge; + } else if (size == "flexible") { + identifier = NSTouchBarItemIdentifierFlexibleSpace; + } else { + identifier = NSTouchBarItemIdentifierFixedSpaceSmall; + } } else { - identifier = NSTouchBarItemIdentifierFixedSpaceSmall; + identifier = [self identifierFromID:item_id type:type]; } - } else { - identifier = [self identifierFromID:item_id type:type]; - } - if (identifier) { - settings_[item_id] = item; - [identifiers addObject:identifier]; + if (identifier) { + settings_[item_id] = item; + [identifiers addObject:identifier]; + } } } + [identifiers addObject:NSTouchBarItemIdentifierOtherItemsProxy]; } - [identifiers addObject:NSTouchBarItemIdentifierOtherItemsProxy]; return identifiers; } @@ -116,7 +118,8 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; - (void)refreshTouchBarItem:(NSTouchBar*)touchBar id:(NSTouchBarItemIdentifier)identifier withType:(const std::string&)item_type - withSettings:(const mate::PersistentDictionary&)settings { + withSettings:(const mate::PersistentDictionary&)settings + API_AVAILABLE(macosx(10.12.2)) { NSTouchBarItem* item = [touchBar itemForIdentifier:identifier]; if (!item) return; @@ -245,14 +248,14 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; details); } -- (void)scrubber:(NSScrubber*)scrubber didSelectItemAtIndex:(NSInteger)selectedIndex { +- (void)scrubber:(NSScrubber*)scrubber didSelectItemAtIndex:(NSInteger)selectedIndex API_AVAILABLE(macosx(10.12.2)) { base::DictionaryValue details; details.SetInteger("selectedIndex", selectedIndex); details.SetString("type", "select"); window_->NotifyTouchBarItemInteraction([scrubber.identifier UTF8String], details); } -- (void)scrubber:(NSScrubber*)scrubber didHighlightItemAtIndex:(NSInteger)highlightedIndex { +- (void)scrubber:(NSScrubber*)scrubber didHighlightItemAtIndex:(NSInteger)highlightedIndex API_AVAILABLE(macosx(10.12.2)) { base::DictionaryValue details; details.SetInteger("highlightedIndex", highlightedIndex); details.SetString("type", "highlight"); @@ -494,7 +497,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; } - (void)updateGroup:(NSGroupTouchBarItem*)item - withSettings:(const mate::PersistentDictionary&)settings { + withSettings:(const mate::PersistentDictionary&)settings API_AVAILABLE(macosx(10.12.2)) { mate::PersistentDictionary child; if (!settings.Get("child", &child)) return; @@ -505,7 +508,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; } - (NSTouchBarItem*)makeSegmentedControlForID:(NSString*)id - withIdentifier:(NSString*)identifier { + withIdentifier:(NSString*)identifier API_AVAILABLE(macosx(10.12.2)) { std::string s_id([id UTF8String]); if (![self hasItemWithID:s_id]) return nil; @@ -525,7 +528,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; } - (void)updateSegmentedControl:(NSCustomTouchBarItem*)item - withSettings:(const mate::PersistentDictionary&)settings { + withSettings:(const mate::PersistentDictionary&)settings API_AVAILABLE(macosx(10.12.2)) { NSSegmentedControl* control = item.view; @@ -582,7 +585,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; } - (NSTouchBarItem*)makeScrubberForID:(NSString*)id - withIdentifier:(NSString*)identifier { + withIdentifier:(NSString*)identifier API_AVAILABLE(macosx(10.12.2)) { std::string s_id([id UTF8String]); if (![self hasItemWithID:s_id]) return nil; @@ -606,7 +609,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; } - (void)updateScrubber:(NSCustomTouchBarItem*)item - withSettings:(const mate::PersistentDictionary&)settings { + withSettings:(const mate::PersistentDictionary&)settings API_AVAILABLE(macosx(10.12.2)) { NSScrubber* scrubber = item.view; bool showsArrowButtons = false; @@ -649,7 +652,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; [scrubber reloadData]; } -- (NSInteger)numberOfItemsForScrubber:(NSScrubber*)scrubber { +- (NSInteger)numberOfItemsForScrubber:(NSScrubber*)scrubber API_AVAILABLE(macosx(10.12.2)) { std::string s_id([[scrubber identifier] UTF8String]); if (![self hasItemWithID:s_id]) return 0; @@ -660,7 +663,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; } - (NSScrubberItemView*)scrubber:(NSScrubber*)scrubber - viewForItemAtIndex:(NSInteger)index { + viewForItemAtIndex:(NSInteger)index API_AVAILABLE(macosx(10.12.2)) { std::string s_id([[scrubber identifier] UTF8String]); if (![self hasItemWithID:s_id]) return nil; @@ -694,7 +697,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; } - (NSSize)scrubber:(NSScrubber *)scrubber layout:(NSScrubberFlowLayout *)layout sizeForItemAtIndex:(NSInteger)itemIndex -{ +API_AVAILABLE(macosx(10.12.2)) { NSInteger width = 50; NSInteger height = 30; NSInteger margin = 15; diff --git a/atom/browser/ui/cocoa/touch_bar_forward_declarations.h b/atom/browser/ui/cocoa/touch_bar_forward_declarations.h index 66dbed7afb..281672c304 100644 --- a/atom/browser/ui/cocoa/touch_bar_forward_declarations.h +++ b/atom/browser/ui/cocoa/touch_bar_forward_declarations.h @@ -259,7 +259,7 @@ static const NSTouchBarItemIdentifier NSTouchBarItemIdentifierOtherItemsProxy = @class NSTouchBarItem; @interface NSWindow (TouchBarSDK) -@property(strong, readonly) NSTouchBar* touchBar; +@property(strong, readonly) NSTouchBar* touchBar API_AVAILABLE(macosx(10.12.2)); @end #endif // MAC_OS_X_VERSION_10_12_1 diff --git a/brightray/browser/mac/cocoa_notification.h b/brightray/browser/mac/cocoa_notification.h index 41f6d4b5a4..066528ee49 100644 --- a/brightray/browser/mac/cocoa_notification.h +++ b/brightray/browser/mac/cocoa_notification.h @@ -29,7 +29,8 @@ class CocoaNotification : public Notification { void NotificationDisplayed(); void NotificationReplied(const std::string& reply); void NotificationActivated(); - void NotificationActivated(NSUserNotificationAction* action); + void NotificationActivated(NSUserNotificationAction* action) + API_AVAILABLE(macosx(10.10)); NSUserNotification* notification() const { return notification_; } diff --git a/brightray/browser/mac/cocoa_notification.mm b/brightray/browser/mac/cocoa_notification.mm index 5201baa363..a8241b4e24 100644 --- a/brightray/browser/mac/cocoa_notification.mm +++ b/brightray/browser/mac/cocoa_notification.mm @@ -69,18 +69,22 @@ void CocoaNotification::Show(const NotificationOptions& options) { } else { // All of the rest are appended to the list of additional actions NSString* actionIdentifier = [NSString stringWithFormat:@"%@Action%d", identifier, i]; - NSUserNotificationAction* notificationAction = - [NSUserNotificationAction actionWithIdentifier:actionIdentifier - title:base::SysUTF16ToNSString(action.text)]; - [additionalActions addObject:notificationAction]; - additional_action_indices_.insert(std::make_pair(base::SysNSStringToUTF8(actionIdentifier), i)); + if (@available(macOS 10.10, *)) { + NSUserNotificationAction* notificationAction = + [NSUserNotificationAction actionWithIdentifier:actionIdentifier + title:base::SysUTF16ToNSString(action.text)]; + [additionalActions addObject:notificationAction]; + additional_action_indices_.insert(std::make_pair(base::SysNSStringToUTF8(actionIdentifier), i)); + } } } i++; } if ([additionalActions count] > 0 && [notification_ respondsToSelector:@selector(setAdditionalActions:)]) { - [notification_ setAdditionalActions:additionalActions]; // Requires macOS 10.10 + if (@available(macOS 10.10, *)) { + [notification_ setAdditionalActions:additionalActions]; + } } if (options.has_reply) { diff --git a/brightray/browser/mac/notification_center_delegate.mm b/brightray/browser/mac/notification_center_delegate.mm index 634af3dc15..f1402e2401 100644 --- a/brightray/browser/mac/notification_center_delegate.mm +++ b/brightray/browser/mac/notification_center_delegate.mm @@ -41,8 +41,12 @@ notification->NotificationActivated(); } else if (notif.activationType == NSUserNotificationActivationTypeReplied) { notification->NotificationReplied([notif.response.string UTF8String]); - } else if (notif.activationType == NSUserNotificationActivationTypeAdditionalActionClicked) { - notification->NotificationActivated([notif additionalActivationAction]); + } else { + if (@available(macOS 10.10, *)) { + if (notif.activationType == NSUserNotificationActivationTypeAdditionalActionClicked) { + notification->NotificationActivated([notif additionalActivationAction]); + } + } } } }