From b08d9dfe73d8a470e2f2fb8b7397708e1b1f1bd6 Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Sat, 22 Jan 2022 20:55:09 +0800 Subject: [PATCH] if #available mac Removes if #available for anything less than macOS 11 --- Mac/AppAssets.swift | 118 ++--- Mac/AppDelegate.swift | 26 +- ...ltinSmartFeedInspectorViewController.swift | 4 +- .../FolderInspectorViewController.swift | 8 +- Mac/MainWindow/Detail/DetailWebView.swift | 36 +- .../Detail/DetailWebViewController.swift | 19 +- Mac/MainWindow/MainWindowController.swift | 470 +++++++----------- .../Sidebar/Cell/SidebarCellAppearance.swift | 6 +- .../Cell/TimelineCellAppearance.swift | 6 +- .../Timeline/TimelineTableRowView.swift | 21 +- .../Timeline/TimelineViewController.swift | 5 +- ...AccountsFeedWranglerWindowController.swift | 6 +- .../AccountsFeedbinWindowController.swift | 6 +- .../AccountsNewsBlurWindowController.swift | 6 +- .../AccountsReaderAPIWindowController.swift | 6 +- .../Accounts/AddAccountsView.swift | 58 +-- .../EnableExtensionPointView.swift | 59 +-- 17 files changed, 288 insertions(+), 572 deletions(-) diff --git a/Mac/AppAssets.swift b/Mac/AppAssets.swift index 74c69df40..fa6851b01 100644 --- a/Mac/AppAssets.swift +++ b/Mac/AppAssets.swift @@ -100,19 +100,11 @@ struct AppAssets { }() static var filterActive: RSImage = { - if #available(macOS 11.0, *) { - return NSImage(systemSymbolName: "line.horizontal.3.decrease.circle.fill", accessibilityDescription: nil)! - } else { - return RSImage(named: "filterActive")! - } + return NSImage(systemSymbolName: "line.horizontal.3.decrease.circle.fill", accessibilityDescription: nil)! }() static var filterInactive: RSImage = { - if #available(macOS 11.0, *) { - return NSImage(systemSymbolName: "line.horizontal.3.decrease.circle", accessibilityDescription: nil)! - } else { - return RSImage(named: "filterInactive")! - } + return NSImage(systemSymbolName: "line.horizontal.3.decrease.circle", accessibilityDescription: nil)! }() static var iconLightBackgroundColor: NSColor = { @@ -156,14 +148,10 @@ struct AppAssets { }() static var masterFolderImage: IconImage { - if #available(macOS 11.0, *) { - let image = NSImage(systemSymbolName: "folder", accessibilityDescription: nil)! - let preferredColor = NSColor(named: "AccentColor")! - let coloredImage = image.tinted(with: preferredColor) - return IconImage(coloredImage, isSymbol: true, isBackgroundSupressed: true, preferredColor: preferredColor.cgColor) - } else { - return IconImage(RSImage(named: NSImage.folderName)!) - } + let image = NSImage(systemSymbolName: "folder", accessibilityDescription: nil)! + let preferredColor = NSColor(named: "AccentColor")! + let coloredImage = image.tinted(with: preferredColor) + return IconImage(coloredImage, isSymbol: true, isBackgroundSupressed: true, preferredColor: preferredColor.cgColor) } static var markAllAsReadImage: RSImage = { @@ -181,35 +169,19 @@ struct AppAssets { }() static var preferencesToolbarAccountsImage: RSImage = { - if #available(macOS 11.0, *) { - return NSImage(systemSymbolName: "at", accessibilityDescription: nil)! - } else { - return NSImage(named: NSImage.userAccountsName)! - } + return NSImage(systemSymbolName: "at", accessibilityDescription: nil)! }() static var preferencesToolbarExtensionsImage: RSImage = { - if #available(macOS 11.0, *) { - return RSImage(named: "preferencesToolbarExtensions")! - } else { - return NSImage(contentsOfFile: "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/KEXT.icns")! - } + return RSImage(named: "preferencesToolbarExtensions")! }() static var preferencesToolbarGeneralImage: RSImage = { - if #available(macOS 11.0, *) { - return NSImage(systemSymbolName: "gearshape", accessibilityDescription: nil)! - } else { - return NSImage(named: NSImage.preferencesGeneralName)! - } + return NSImage(systemSymbolName: "gearshape", accessibilityDescription: nil)! }() static var preferencesToolbarAdvancedImage: RSImage = { - if #available(macOS 11.0, *) { - return NSImage(systemSymbolName: "gearshape.2", accessibilityDescription: nil)! - } else { - return NSImage(named: NSImage.advancedName)! - } + return NSImage(systemSymbolName: "gearshape.2", accessibilityDescription: nil)! }() @available(macOS 11.0, *) @@ -252,14 +224,10 @@ struct AppAssets { }() static var starredFeedImage: IconImage = { - if #available(macOS 11.0, *) { - let image = NSImage(systemSymbolName: "star.fill", accessibilityDescription: nil)! - let preferredColor = NSColor(named: "StarColor")! - let coloredImage = image.tinted(with: preferredColor) - return IconImage(coloredImage, isSymbol: true, isBackgroundSupressed: true, preferredColor: preferredColor.cgColor) - } else { - return IconImage(RSImage(named: NSImage.smartBadgeTemplateName)!, isBackgroundSupressed: true) - } + let image = NSImage(systemSymbolName: "star.fill", accessibilityDescription: nil)! + let preferredColor = NSColor(named: "StarColor")! + let coloredImage = image.tinted(with: preferredColor) + return IconImage(coloredImage, isSymbol: true, isBackgroundSupressed: true, preferredColor: preferredColor.cgColor) }() static var timelineSeparatorColor: NSColor = { @@ -275,63 +243,37 @@ struct AppAssets { }() static var todayFeedImage: IconImage = { - if #available(macOS 11.0, *) { - let image = NSImage(systemSymbolName: "sun.max.fill", accessibilityDescription: nil)! - let preferredColor = NSColor.orange - let coloredImage = image.tinted(with: preferredColor) - return IconImage(coloredImage, isSymbol: true, isBackgroundSupressed: true, preferredColor: preferredColor.cgColor) - } else { - return IconImage(RSImage(named: NSImage.smartBadgeTemplateName)!, isBackgroundSupressed: true) - } + let image = NSImage(systemSymbolName: "sun.max.fill", accessibilityDescription: nil)! + let preferredColor = NSColor.orange + let coloredImage = image.tinted(with: preferredColor) + return IconImage(coloredImage, isSymbol: true, isBackgroundSupressed: true, preferredColor: preferredColor.cgColor) }() static var unreadFeedImage: IconImage = { - if #available(macOS 11.0, *) { - let image = NSImage(systemSymbolName: "largecircle.fill.circle", accessibilityDescription: nil)! - let preferredColor = NSColor(named: "AccentColor")! - let coloredImage = image.tinted(with: preferredColor) - return IconImage(coloredImage, isSymbol: true, isBackgroundSupressed: true, preferredColor: preferredColor.cgColor) - } else { - return IconImage(RSImage(named: NSImage.smartBadgeTemplateName)!, isBackgroundSupressed: true) - } + let image = NSImage(systemSymbolName: "largecircle.fill.circle", accessibilityDescription: nil)! + let preferredColor = NSColor(named: "AccentColor")! + let coloredImage = image.tinted(with: preferredColor) + return IconImage(coloredImage, isSymbol: true, isBackgroundSupressed: true, preferredColor: preferredColor.cgColor) }() static var swipeMarkReadImage: RSImage = { - if #available(OSX 11.0, *) { - return RSImage(systemSymbolName: "circle", accessibilityDescription: "Mark Read")! - .withSymbolConfiguration(.init(scale: .large))! - } else { - // TODO: remove swipeMarkRead asset when dropping support for macOS 10.15 - return RSImage(named: "swipeMarkRead")! - } + return RSImage(systemSymbolName: "circle", accessibilityDescription: "Mark Read")! + .withSymbolConfiguration(.init(scale: .large))! }() static var swipeMarkUnreadImage: RSImage = { - if #available(OSX 11.0, *) { - return RSImage(systemSymbolName: "largecircle.fill.circle", accessibilityDescription: "Mark Unread")! - .withSymbolConfiguration(.init(scale: .large))! - } else { - // TODO: remove swipeMarkUnread asset when dropping support for macOS 10.15 - return RSImage(named: "swipeMarkUnread")! - } + return RSImage(systemSymbolName: "largecircle.fill.circle", accessibilityDescription: "Mark Unread")! + .withSymbolConfiguration(.init(scale: .large))! }() static var swipeMarkStarredImage: RSImage = { - if #available(OSX 11.0, *) { - return RSImage(systemSymbolName: "star.fill", accessibilityDescription: "Star")! - .withSymbolConfiguration(.init(scale: .large))! - } else { - return RSImage(named: "swipeMarkStarred")! - } + return RSImage(systemSymbolName: "star.fill", accessibilityDescription: "Star")! + .withSymbolConfiguration(.init(scale: .large))! }() static var swipeMarkUnstarredImage: RSImage = { - if #available(OSX 11.0, *) { - return RSImage(systemSymbolName: "star", accessibilityDescription: "Unstar")! - .withSymbolConfiguration(.init(scale: .large))! - } else { - return RSImage(named: "swipeMarkUnstarred")! - } + return RSImage(systemSymbolName: "star", accessibilityDescription: "Unstar")! + .withSymbolConfiguration(.init(scale: .large))! }() static var starColor: NSColor = { diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index 86692df48..3307734d8 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -396,11 +396,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, func createMainWindowController() -> MainWindowController { let controller: MainWindowController - if #available(macOS 11.0, *) { - controller = windowControllerWithName("UnifiedWindow") as! MainWindowController - } else { - controller = windowControllerWithName("MainWindow") as! MainWindowController - } + controller = windowControllerWithName("UnifiedWindow") as! MainWindowController if !(mainWindowController?.isOpen ?? false) { mainWindowControllers.removeAll() @@ -828,30 +824,20 @@ internal extension AppDelegate { attrs[.font] = NSFont.systemFont(ofSize: NSFont.smallSystemFontSize) attrs[.foregroundColor] = NSColor.textColor - if #available(macOS 11.0, *) { - let titleParagraphStyle = NSMutableParagraphStyle() - titleParagraphStyle.alignment = .center - attrs[.paragraphStyle] = titleParagraphStyle - } + let titleParagraphStyle = NSMutableParagraphStyle() + titleParagraphStyle.alignment = .center + attrs[.paragraphStyle] = titleParagraphStyle let websiteText = NSMutableAttributedString() websiteText.append(NSAttributedString(string: NSLocalizedString("Author's Website", comment: "Author's Website"), attributes: attrs)) - if #available(macOS 11.0, *) { - websiteText.append(NSAttributedString(string: "\n")) - } else { - websiteText.append(NSAttributedString(string: " ")) - } + websiteText.append(NSAttributedString(string: "\n")) attrs[.link] = theme.creatorHomePage websiteText.append(NSAttributedString(string: theme.creatorHomePage, attributes: attrs)) let textViewWidth: CGFloat - if #available(macOS 11.0, *) { - textViewWidth = 200 - } else { - textViewWidth = 400 - } + textViewWidth = 200 let textView = NSTextView(frame: CGRect(x: 0, y: 0, width: textViewWidth, height: 15)) textView.isEditable = false diff --git a/Mac/Inspector/BuiltinSmartFeedInspectorViewController.swift b/Mac/Inspector/BuiltinSmartFeedInspectorViewController.swift index bbd1a928d..3c6c7b908 100644 --- a/Mac/Inspector/BuiltinSmartFeedInspectorViewController.swift +++ b/Mac/Inspector/BuiltinSmartFeedInspectorViewController.swift @@ -64,8 +64,6 @@ private extension BuiltinSmartFeedInspectorViewController { func updateUI() { nameTextField?.stringValue = smartFeed?.nameForDisplay ?? "" windowTitle = smartFeed?.nameForDisplay ?? NSLocalizedString("Smart Feed Inspector", comment: "Smart Feed Inspector window title") - if #available(macOS 11.0, *) { - smartFeedImageView?.image = smartFeed?.smallIcon?.image - } + smartFeedImageView?.image = smartFeed?.smallIcon?.image } } diff --git a/Mac/Inspector/FolderInspectorViewController.swift b/Mac/Inspector/FolderInspectorViewController.swift index d67dfca80..63f76b0d7 100644 --- a/Mac/Inspector/FolderInspectorViewController.swift +++ b/Mac/Inspector/FolderInspectorViewController.swift @@ -47,11 +47,9 @@ final class FolderInspectorViewController: NSViewController, Inspector { override func viewDidLoad() { updateUI() - if #available(macOS 11.0, *) { - let image = NSImage(systemSymbolName: "folder", accessibilityDescription: nil)! - folderImageView.image = image - folderImageView.contentTintColor = NSColor.controlAccentColor - } + let image = NSImage(systemSymbolName: "folder", accessibilityDescription: nil)! + folderImageView.image = image + folderImageView.contentTintColor = NSColor.controlAccentColor NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange(_:)), name: .DisplayNameDidChange, object: nil) } diff --git a/Mac/MainWindow/Detail/DetailWebView.swift b/Mac/MainWindow/Detail/DetailWebView.swift index a6e4a5c45..3fd16cb5e 100644 --- a/Mac/MainWindow/Detail/DetailWebView.swift +++ b/Mac/MainWindow/Detail/DetailWebView.swift @@ -74,26 +74,24 @@ final class DetailWebView: WKWebView { This code adjusts the height of the window by -1pt/+1pt, which puts the webview back in the correct place. */ - if #available(macOS 11, *) { - guard var frame = window?.frame else { - return - } - - guard !inBigSurOffsetFix else { - return - } - - inBigSurOffsetFix = true - - defer { - inBigSurOffsetFix = false - } - - frame.size = NSSize(width: window!.frame.width, height: window!.frame.height - 1) - window!.setFrame(frame, display: false) - frame.size = NSSize(width: window!.frame.width, height: window!.frame.height + 1) - window!.setFrame(frame, display: false) + guard var frame = window?.frame else { + return } + + guard !inBigSurOffsetFix else { + return + } + + inBigSurOffsetFix = true + + defer { + inBigSurOffsetFix = false + } + + frame.size = NSSize(width: window!.frame.width, height: window!.frame.height - 1) + window!.setFrame(frame, display: false) + frame.size = NSSize(width: window!.frame.width, height: window!.frame.height + 1) + window!.setFrame(frame, display: false) } } diff --git a/Mac/MainWindow/Detail/DetailWebViewController.swift b/Mac/MainWindow/Detail/DetailWebViewController.swift index 664d4c723..0c3465f03 100644 --- a/Mac/MainWindow/Detail/DetailWebViewController.swift +++ b/Mac/MainWindow/Detail/DetailWebViewController.swift @@ -108,20 +108,6 @@ final class DetailWebViewController: NSViewController { view = webView - // Use the safe area layout guides if they are available. - if #available(OSX 11.0, *) { - // These constraints have been removed as they were unsatisfiable after removing NSBox. - } else { - let constraints = [ - webView.topAnchor.constraint(equalTo: view.topAnchor), - webView.bottomAnchor.constraint(equalTo: view.bottomAnchor), - webView.leadingAnchor.constraint(equalTo: view.leadingAnchor), - webView.trailingAnchor.constraint(equalTo: view.trailingAnchor), - ] - NSLayoutConstraint.activate(constraints) - } - - // Hide the web view until the first reload (navigation) is complete (plus some delay) to avoid the awful white flash that happens on the initial display in dark mode. // See bug #901. webView.isHidden = true @@ -333,10 +319,7 @@ private extension DetailWebViewController { } func fetchScrollInfo(_ completion: @escaping (ScrollInfo?) -> Void) { - var javascriptString = "var x = {contentHeight: document.body.scrollHeight, offsetY: document.body.scrollTop}; x" - if #available(macOS 10.15, *) { - javascriptString = "var x = {contentHeight: document.body.scrollHeight, offsetY: window.pageYOffset}; x" - } + let javascriptString = "var x = {contentHeight: document.body.scrollHeight, offsetY: window.pageYOffset}; x" webView.evaluateJavaScript(javascriptString) { (info, error) in guard let info = info as? [String: Any] else { diff --git a/Mac/MainWindow/MainWindowController.swift b/Mac/MainWindow/MainWindowController.swift index 6eee441f9..cea30f75e 100644 --- a/Mac/MainWindow/MainWindowController.swift +++ b/Mac/MainWindow/MainWindowController.swift @@ -67,18 +67,12 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations { updateArticleThemeMenu() - if #available(macOS 11.0, *) { - let toolbar = NSToolbar(identifier: "MainWindowToolbar") - toolbar.allowsUserCustomization = true - toolbar.autosavesConfiguration = true - toolbar.displayMode = .iconOnly - toolbar.delegate = self - self.window?.toolbar = toolbar - } else { - if !AppDefaults.shared.showTitleOnMainWindow { - window?.titleVisibility = .hidden - } - } + let toolbar = NSToolbar(identifier: "MainWindowToolbar") + toolbar.allowsUserCustomization = true + toolbar.autosavesConfiguration = true + toolbar.displayMode = .iconOnly + toolbar.delegate = self + self.window?.toolbar = toolbar if let window = window { let point = NSPoint(x: 128, y: 64) @@ -776,173 +770,130 @@ extension NSToolbarItem.Identifier { extension MainWindowController: NSToolbarDelegate { func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? { - if #available(macOS 11.0, *) { + switch itemIdentifier { - switch itemIdentifier { + case .sidebarToggle: + let title = NSLocalizedString("Toggle Sidebar", comment: "Toggle Sidebar") + return buildToolbarButton(.toggleSidebar, title, AppAssets.sidebarToggleImage, "toggleTheSidebar:") - case .sidebarToggle: - let title = NSLocalizedString("Toggle Sidebar", comment: "Toggle Sidebar") - return buildToolbarButton(.toggleSidebar, title, AppAssets.sidebarToggleImage, "toggleTheSidebar:") - - case .refresh: - let title = NSLocalizedString("Refresh", comment: "Refresh") - return buildToolbarButton(.refresh, title, AppAssets.refreshImage, "refreshAll:") - - case .newSidebarItemMenu: - let toolbarItem = NSMenuToolbarItem(itemIdentifier: .newSidebarItemMenu) - toolbarItem.image = AppAssets.addNewSidebarItemImage - let description = NSLocalizedString("Add Item", comment: "Add Item") - toolbarItem.toolTip = description - toolbarItem.label = description - toolbarItem.menu = buildNewSidebarItemMenu() - return toolbarItem - - case .markAllAsRead: - let title = NSLocalizedString("Mark All as Read", comment: "Mark All as Read") - return buildToolbarButton(.markAllAsRead, title, AppAssets.markAllAsReadImage, "markAllAsRead:") - - case .toggleReadArticlesFilter: - let title = NSLocalizedString("Read Articles Filter", comment: "Read Articles Filter") - return buildToolbarButton(.toggleReadArticlesFilter, title, AppAssets.filterInactive, "toggleReadArticlesFilter:") - - case .timelineTrackingSeparator: - return NSTrackingSeparatorToolbarItem(identifier: .timelineTrackingSeparator, splitView: splitViewController!.splitView, dividerIndex: 1) - - case .markRead: - let title = NSLocalizedString("Mark Read", comment: "Mark Read") - return buildToolbarButton(.markRead, title, AppAssets.readClosedImage, "toggleRead:") - - case .markStar: - let title = NSLocalizedString("Star", comment: "Star") - return buildToolbarButton(.markStar, title, AppAssets.starOpenImage, "toggleStarred:") - - case .nextUnread: - let title = NSLocalizedString("Next Unread", comment: "Next Unread") - return buildToolbarButton(.nextUnread, title, AppAssets.nextUnreadImage, "nextUnread:") - - case .readerView: - let toolbarItem = RSToolbarItem(itemIdentifier: .readerView) - toolbarItem.autovalidates = true - let description = NSLocalizedString("Reader View", comment: "Reader View") - toolbarItem.toolTip = description - toolbarItem.label = description - let button = ArticleExtractorButton() - button.action = #selector(toggleArticleExtractor(_:)) - toolbarItem.view = button - return toolbarItem - - case .share: - let title = NSLocalizedString("Share", comment: "Share") - return buildToolbarButton(.share, title, AppAssets.shareImage, "toolbarShowShareMenu:") - - case .openInBrowser: - let title = NSLocalizedString("Open in Browser", comment: "Open in Browser") - return buildToolbarButton(.openInBrowser, title, AppAssets.openInBrowserImage, "openArticleInBrowser:") - - case .articleThemeMenu: - articleThemeMenuToolbarItem.image = AppAssets.articleTheme - let description = NSLocalizedString("Article Theme", comment: "Article Theme") - articleThemeMenuToolbarItem.toolTip = description - articleThemeMenuToolbarItem.label = description - return articleThemeMenuToolbarItem - - case .search: - let toolbarItem = NSSearchToolbarItem(itemIdentifier: .search) - let description = NSLocalizedString("Search", comment: "Search") - toolbarItem.toolTip = description - toolbarItem.label = description - return toolbarItem - - case .cleanUp: - let title = NSLocalizedString("Clean Up", comment: "Clean Up") - return buildToolbarButton(.cleanUp, title, AppAssets.cleanUpImage, "cleanUp:") - - default: - break - } - - } + case .refresh: + let title = NSLocalizedString("Refresh", comment: "Refresh") + return buildToolbarButton(.refresh, title, AppAssets.refreshImage, "refreshAll:") - return nil + case .newSidebarItemMenu: + let toolbarItem = NSMenuToolbarItem(itemIdentifier: .newSidebarItemMenu) + toolbarItem.image = AppAssets.addNewSidebarItemImage + let description = NSLocalizedString("Add Item", comment: "Add Item") + toolbarItem.toolTip = description + toolbarItem.label = description + toolbarItem.menu = buildNewSidebarItemMenu() + return toolbarItem + + case .markAllAsRead: + let title = NSLocalizedString("Mark All as Read", comment: "Mark All as Read") + return buildToolbarButton(.markAllAsRead, title, AppAssets.markAllAsReadImage, "markAllAsRead:") + + case .toggleReadArticlesFilter: + let title = NSLocalizedString("Read Articles Filter", comment: "Read Articles Filter") + return buildToolbarButton(.toggleReadArticlesFilter, title, AppAssets.filterInactive, "toggleReadArticlesFilter:") + + case .timelineTrackingSeparator: + return NSTrackingSeparatorToolbarItem(identifier: .timelineTrackingSeparator, splitView: splitViewController!.splitView, dividerIndex: 1) + + case .markRead: + let title = NSLocalizedString("Mark Read", comment: "Mark Read") + return buildToolbarButton(.markRead, title, AppAssets.readClosedImage, "toggleRead:") + + case .markStar: + let title = NSLocalizedString("Star", comment: "Star") + return buildToolbarButton(.markStar, title, AppAssets.starOpenImage, "toggleStarred:") + + case .nextUnread: + let title = NSLocalizedString("Next Unread", comment: "Next Unread") + return buildToolbarButton(.nextUnread, title, AppAssets.nextUnreadImage, "nextUnread:") + + case .readerView: + let toolbarItem = RSToolbarItem(itemIdentifier: .readerView) + toolbarItem.autovalidates = true + let description = NSLocalizedString("Reader View", comment: "Reader View") + toolbarItem.toolTip = description + toolbarItem.label = description + let button = ArticleExtractorButton() + button.action = #selector(toggleArticleExtractor(_:)) + toolbarItem.view = button + return toolbarItem + + case .share: + let title = NSLocalizedString("Share", comment: "Share") + return buildToolbarButton(.share, title, AppAssets.shareImage, "toolbarShowShareMenu:") + + case .openInBrowser: + let title = NSLocalizedString("Open in Browser", comment: "Open in Browser") + return buildToolbarButton(.openInBrowser, title, AppAssets.openInBrowserImage, "openArticleInBrowser:") + + case .articleThemeMenu: + articleThemeMenuToolbarItem.image = AppAssets.articleTheme + let description = NSLocalizedString("Article Theme", comment: "Article Theme") + articleThemeMenuToolbarItem.toolTip = description + articleThemeMenuToolbarItem.label = description + return articleThemeMenuToolbarItem + + case .search: + let toolbarItem = NSSearchToolbarItem(itemIdentifier: .search) + let description = NSLocalizedString("Search", comment: "Search") + toolbarItem.toolTip = description + toolbarItem.label = description + return toolbarItem + + case .cleanUp: + let title = NSLocalizedString("Clean Up", comment: "Clean Up") + return buildToolbarButton(.cleanUp, title, AppAssets.cleanUpImage, "cleanUp:") + + default: + return nil + } } func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] { - if #available(macOS 11.0, *) { - return [ - .sidebarToggle, - .refresh, - .newSidebarItemMenu, - .sidebarTrackingSeparator, - .markAllAsRead, - .toggleReadArticlesFilter, - .timelineTrackingSeparator, - .flexibleSpace, - .nextUnread, - .markRead, - .markStar, - .readerView, - .openInBrowser, - .share, - .articleThemeMenu, - .search, - .cleanUp - ] - } else { - return [ - .newFeed, - .newFolder, - .refresh, - .flexibleSpace, - .markAllAsRead, - .search, - .flexibleSpace, - .nextUnread, - .markStar, - .markRead, - .readerView, - .openInBrowser, - .share, - .cleanUp - ] - } + return [ + .sidebarToggle, + .refresh, + .newSidebarItemMenu, + .sidebarTrackingSeparator, + .markAllAsRead, + .toggleReadArticlesFilter, + .timelineTrackingSeparator, + .flexibleSpace, + .nextUnread, + .markRead, + .markStar, + .readerView, + .openInBrowser, + .share, + .articleThemeMenu, + .search, + .cleanUp + ] } func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] { - if #available(macOS 11.0, *) { - return [ - .flexibleSpace, - .refresh, - .newSidebarItemMenu, - .sidebarTrackingSeparator, - .markAllAsRead, - .toggleReadArticlesFilter, - .timelineTrackingSeparator, - .markRead, - .markStar, - .nextUnread, - .readerView, - .share, - .openInBrowser, - .flexibleSpace, - .search - ] - } else { - return [ - .newFeed, - .newFolder, - .refresh, - .flexibleSpace, - .markAllAsRead, - .search, - .flexibleSpace, - .nextUnread, - .markStar, - .markRead, - .readerView, - .openInBrowser, - .share - ] - } + return [ + .flexibleSpace, + .refresh, + .newSidebarItemMenu, + .sidebarTrackingSeparator, + .markAllAsRead, + .toggleReadArticlesFilter, + .timelineTrackingSeparator, + .markRead, + .markStar, + .nextUnread, + .readerView, + .share, + .openInBrowser, + .flexibleSpace, + .search + ] } func toolbarWillAddItem(_ notification: Notification) { @@ -955,20 +906,11 @@ extension MainWindowController: NSToolbarDelegate { button.sendAction(on: .leftMouseDown) } - if #available(macOS 11.0, *) { - if item.itemIdentifier == .search, let searchItem = item as? NSSearchToolbarItem { - searchItem.searchField.delegate = self - searchItem.searchField.target = self - searchItem.searchField.action = #selector(runSearch(_:)) - currentSearchField = searchItem.searchField - } - } else { - if item.itemIdentifier == .search, let searchField = item.view as? NSSearchField { - searchField.delegate = self - searchField.target = self - searchField.action = #selector(runSearch(_:)) - currentSearchField = searchField - } + if item.itemIdentifier == .search, let searchItem = item as? NSSearchToolbarItem { + searchItem.searchField.delegate = self + searchItem.searchField.target = self + searchItem.searchField.action = #selector(runSearch(_:)) + currentSearchField = searchItem.searchField } } @@ -977,20 +919,11 @@ extension MainWindowController: NSToolbarDelegate { return } - if #available(macOS 11.0, *) { - if item.itemIdentifier == .search, let searchItem = item as? NSSearchToolbarItem { - searchItem.searchField.delegate = nil - searchItem.searchField.target = nil - searchItem.searchField.action = nil - currentSearchField = nil - } - } else { - if item.itemIdentifier == .search, let searchField = item.view as? NSSearchField { - searchField.delegate = nil - searchField.target = nil - searchField.action = nil - currentSearchField = nil - } + if item.itemIdentifier == .search, let searchItem = item as? NSSearchToolbarItem { + searchItem.searchField.delegate = nil + searchItem.searchField.target = nil + searchItem.searchField.action = nil + currentSearchField = nil } } @@ -1122,7 +1055,7 @@ private extension MainWindowController { menuItem.title = commandName } - if #available(macOS 11.0, *), let toolbarItem = item as? NSToolbarItem, let button = toolbarItem.view as? NSButton { + if let toolbarItem = item as? NSToolbarItem, let button = toolbarItem.view as? NSButton { button.image = markingRead ? AppAssets.readClosedImage : AppAssets.readOpenImage } @@ -1135,77 +1068,34 @@ private extension MainWindowController { } - if #available(macOS 11.0, *) { + guard let toolbarItem = item as? NSToolbarItem, let toolbarButton = toolbarItem.view as? ArticleExtractorButton else { + if let menuItem = item as? NSMenuItem { + menuItem.state = isShowingExtractedArticle ? .on : .off + } + return currentLink != nil + } + + if let webfeed = currentTimelineViewController?.selectedArticles.first?.webFeed { + if webfeed.isFeedProvider { + toolbarButton.isEnabled = false + return false + } else { + toolbarButton.isEnabled = true + } + } - guard let toolbarItem = item as? NSToolbarItem, let toolbarButton = toolbarItem.view as? ArticleExtractorButton else { - if let menuItem = item as? NSMenuItem { - menuItem.state = isShowingExtractedArticle ? .on : .off - } - return currentLink != nil - } - - if let webfeed = currentTimelineViewController?.selectedArticles.first?.webFeed { - if webfeed.isFeedProvider { - toolbarButton.isEnabled = false - return false - } else { - toolbarButton.isEnabled = true - } - } + guard let state = articleExtractor?.state else { + toolbarButton.buttonState = .off + return currentLink != nil + } - guard let state = articleExtractor?.state else { - toolbarButton.buttonState = .off - return currentLink != nil - } - - switch state { - case .processing: - toolbarButton.buttonState = .animated - case .failedToParse: - toolbarButton.buttonState = .error - case .ready, .cancelled, .complete: - toolbarButton.buttonState = isShowingExtractedArticle ? .on : .off - } - - } else { - - guard let toolbarItem = item as? NSToolbarItem, let toolbarButton = toolbarItem.view as? LegacyArticleExtractorButton else { - if let menuItem = item as? NSMenuItem { - menuItem.state = isShowingExtractedArticle ? .on : .off - } - return currentLink != nil - } - - if let webfeed = currentTimelineViewController?.selectedArticles.first?.webFeed { - if webfeed.isFeedProvider { - toolbarButton.isEnabled = false - return false - } else { - toolbarButton.isEnabled = true - } - } - - toolbarButton.state = isShowingExtractedArticle ? .on : .off - - guard let state = articleExtractor?.state else { - toolbarButton.isError = false - toolbarButton.isInProgress = false - toolbarButton.state = .off - return currentLink != nil - } - - switch state { - case .processing: - toolbarButton.isError = false - toolbarButton.isInProgress = true - case .failedToParse: - toolbarButton.isError = true - toolbarButton.isInProgress = false - case .ready, .cancelled, .complete: - toolbarButton.isError = false - toolbarButton.isInProgress = false - } - + switch state { + case .processing: + toolbarButton.buttonState = .animated + case .failedToParse: + toolbarButton.buttonState = .error + case .ready, .cancelled, .complete: + toolbarButton.buttonState = isShowingExtractedArticle ? .on : .off } return true @@ -1255,7 +1145,7 @@ private extension MainWindowController { menuItem.title = commandName } - if #available(macOS 11.0, *), let toolbarItem = item as? NSToolbarItem, let button = toolbarItem.view as? NSButton { + if let toolbarItem = item as? NSToolbarItem, let button = toolbarItem.view as? NSButton { button.image = starring ? AppAssets.starOpenImage : AppAssets.starClosedImage } @@ -1281,7 +1171,7 @@ private extension MainWindowController { guard let isReadFiltered = timelineContainerViewController?.isReadFiltered else { (item as? NSMenuItem)?.title = hideCommand - if #available(macOS 11.0, *), let toolbarItem = item as? NSToolbarItem, let button = toolbarItem.view as? NSButton { + if let toolbarItem = item as? NSToolbarItem, let button = toolbarItem.view as? NSButton { toolbarItem.toolTip = hideCommand button.image = AppAssets.filterInactive } @@ -1290,13 +1180,13 @@ private extension MainWindowController { if isReadFiltered { (item as? NSMenuItem)?.title = showCommand - if #available(macOS 11.0, *), let toolbarItem = item as? NSToolbarItem, let button = toolbarItem.view as? NSButton { + if let toolbarItem = item as? NSToolbarItem, let button = toolbarItem.view as? NSButton { toolbarItem.toolTip = showCommand button.image = AppAssets.filterActive } } else { (item as? NSMenuItem)?.title = hideCommand - if #available(macOS 11.0, *), let toolbarItem = item as? NSToolbarItem, let button = toolbarItem.view as? NSButton { + if let toolbarItem = item as? NSToolbarItem, let button = toolbarItem.view as? NSButton { toolbarItem.toolTip = hideCommand button.image = AppAssets.filterInactive } @@ -1331,49 +1221,39 @@ private extension MainWindowController { guard timelineSourceMode != .search else { let localizedLabel = NSLocalizedString("Search: %@", comment: "Search") window?.title = NSString.localizedStringWithFormat(localizedLabel as NSString, searchString ?? "") as String - if #available(macOS 11.0, *) { - window?.subtitle = "" - } + window?.subtitle = "" return } func setSubtitle(_ count: Int) { let localizedLabel = NSLocalizedString("%d unread", comment: "Unread") let formattedLabel = NSString.localizedStringWithFormat(localizedLabel as NSString, count) - if #available(macOS 11.0, *) { - window?.subtitle = formattedLabel as String - } + window?.subtitle = formattedLabel as String } guard let selectedObjects = selectedObjectsInSidebar(), selectedObjects.count > 0 else { window?.title = appDelegate.appName! - if #available(macOS 11.0, *) { - setSubtitle(appDelegate.unreadCount) - } + setSubtitle(appDelegate.unreadCount) return } guard selectedObjects.count == 1 else { window?.title = NSLocalizedString("Multiple", comment: "Multiple") - if #available(macOS 11.0, *) { - let unreadCount = selectedObjects.reduce(0, { result, selectedObject in - if let unreadCountProvider = selectedObject as? UnreadCountProvider { - return result + unreadCountProvider.unreadCount - } else { - return result - } - }) - setSubtitle(unreadCount) - } + let unreadCount = selectedObjects.reduce(0, { result, selectedObject in + if let unreadCountProvider = selectedObject as? UnreadCountProvider { + return result + unreadCountProvider.unreadCount + } else { + return result + } + }) + setSubtitle(unreadCount) return } if let displayNameProvider = currentFeedOrFolder as? DisplayNameProvider { window?.title = displayNameProvider.nameForDisplay - if #available(macOS 11.0, *) { - if let unreadCountProvider = currentFeedOrFolder as? UnreadCountProvider { - setSubtitle(unreadCountProvider.unreadCount) - } + if let unreadCountProvider = currentFeedOrFolder as? UnreadCountProvider { + setSubtitle(unreadCountProvider.unreadCount) } } } diff --git a/Mac/MainWindow/Sidebar/Cell/SidebarCellAppearance.swift b/Mac/MainWindow/Sidebar/Cell/SidebarCellAppearance.swift index 7a082b434..c13996732 100644 --- a/Mac/MainWindow/Sidebar/Cell/SidebarCellAppearance.swift +++ b/Mac/MainWindow/Sidebar/Cell/SidebarCellAppearance.swift @@ -23,11 +23,7 @@ struct SidebarCellAppearance: Equatable { textFieldFontSize = 11 case .large: imageSize = CGSize(width: 22, height: 22) - if #available(macOS 11.0, *) { - textFieldFontSize = 15 - } else { - textFieldFontSize = 13 - } + textFieldFontSize = 15 default: imageSize = CGSize(width: 19, height: 19) textFieldFontSize = 13 diff --git a/Mac/MainWindow/Timeline/Cell/TimelineCellAppearance.swift b/Mac/MainWindow/Timeline/Cell/TimelineCellAppearance.swift index b288ff911..620041bd1 100644 --- a/Mac/MainWindow/Timeline/Cell/TimelineCellAppearance.swift +++ b/Mac/MainWindow/Timeline/Cell/TimelineCellAppearance.swift @@ -56,11 +56,7 @@ struct TimelineCellAppearance: Equatable { self.showIcon = showIcon - if #available(macOS 11.0, *) { - cellPadding = NSEdgeInsets(top: 8.0, left: 4.0, bottom: 10.0, right: 4.0) - } else { - cellPadding = NSEdgeInsets(top: 8.0, left: 18.0, bottom: 10.0, right: 18.0) - } + cellPadding = NSEdgeInsets(top: 8.0, left: 4.0, bottom: 10.0, right: 4.0) let margin = self.cellPadding.left + self.unreadCircleDimension + self.unreadCircleMarginRight self.boxLeftMargin = margin diff --git a/Mac/MainWindow/Timeline/TimelineTableRowView.swift b/Mac/MainWindow/Timeline/TimelineTableRowView.swift index bf42f4edd..54d87479c 100644 --- a/Mac/MainWindow/Timeline/TimelineTableRowView.swift +++ b/Mac/MainWindow/Timeline/TimelineTableRowView.swift @@ -59,21 +59,12 @@ class TimelineTableRowView : NSTableRowView { separator!.wantsLayer = true separator!.layer?.backgroundColor = AppAssets.timelineSeparatorColor.cgColor addSubview(separator!) - if #available(macOS 11.0, *) { - NSLayoutConstraint.activate([ - separator!.leadingAnchor.constraint(equalTo: cellView.leadingAnchor, constant: 20), - separator!.trailingAnchor.constraint(equalTo: cellView.trailingAnchor, constant: -4), - separator!.heightAnchor.constraint(equalToConstant: 1), - separator!.bottomAnchor.constraint(equalTo: bottomAnchor, constant: 0) - ]) - } else { - NSLayoutConstraint.activate([ - separator!.leadingAnchor.constraint(equalTo: cellView.leadingAnchor, constant: 34), - separator!.trailingAnchor.constraint(equalTo: cellView.trailingAnchor, constant: -28), - separator!.heightAnchor.constraint(equalToConstant: 1), - separator!.bottomAnchor.constraint(equalTo: bottomAnchor, constant: 0) - ]) - } + NSLayoutConstraint.activate([ + separator!.leadingAnchor.constraint(equalTo: cellView.leadingAnchor, constant: 20), + separator!.trailingAnchor.constraint(equalTo: cellView.trailingAnchor, constant: -4), + separator!.heightAnchor.constraint(equalToConstant: 1), + separator!.bottomAnchor.constraint(equalTo: bottomAnchor, constant: 0) + ]) } } diff --git a/Mac/MainWindow/Timeline/TimelineViewController.swift b/Mac/MainWindow/Timeline/TimelineViewController.swift index 1467649e4..5c73f40bf 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController.swift @@ -207,10 +207,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr tableView.doubleAction = #selector(openArticleInBrowser(_:)) tableView.setDraggingSourceOperationMask(.copy, forLocal: false) tableView.keyboardDelegate = keyboardDelegate - - if #available(macOS 11.0, *) { - tableView.style = .inset - } + tableView.style = .inset if !didRegisterForNotifications { NotificationCenter.default.addObserver(self, selector: #selector(statusesDidChange(_:)), name: .StatusesDidChange, object: nil) diff --git a/Mac/Preferences/Accounts/AccountsFeedWranglerWindowController.swift b/Mac/Preferences/Accounts/AccountsFeedWranglerWindowController.swift index d7d185c9d..e42301492 100644 --- a/Mac/Preferences/Accounts/AccountsFeedWranglerWindowController.swift +++ b/Mac/Preferences/Accounts/AccountsFeedWranglerWindowController.swift @@ -128,10 +128,8 @@ class AccountsFeedWranglerWindowController: NSWindowController { // MARK: Autofill func enableAutofill() { - if #available(macOS 11, *) { - usernameTextField.contentType = .username - passwordTextField.contentType = .password - } + usernameTextField.contentType = .username + passwordTextField.contentType = .password } } diff --git a/Mac/Preferences/Accounts/AccountsFeedbinWindowController.swift b/Mac/Preferences/Accounts/AccountsFeedbinWindowController.swift index 444e152d0..3a4112ca4 100644 --- a/Mac/Preferences/Accounts/AccountsFeedbinWindowController.swift +++ b/Mac/Preferences/Accounts/AccountsFeedbinWindowController.swift @@ -133,10 +133,8 @@ class AccountsFeedbinWindowController: NSWindowController { // MARK: Autofill func enableAutofill() { - if #available(macOS 11, *) { - usernameTextField.contentType = .username - passwordTextField.contentType = .password - } + usernameTextField.contentType = .username + passwordTextField.contentType = .password } } diff --git a/Mac/Preferences/Accounts/AccountsNewsBlurWindowController.swift b/Mac/Preferences/Accounts/AccountsNewsBlurWindowController.swift index 00f47778e..9c70fceb5 100644 --- a/Mac/Preferences/Accounts/AccountsNewsBlurWindowController.swift +++ b/Mac/Preferences/Accounts/AccountsNewsBlurWindowController.swift @@ -129,10 +129,8 @@ class AccountsNewsBlurWindowController: NSWindowController { // MARK: Autofill func enableAutofill() { - if #available(macOS 11, *) { - usernameTextField.contentType = .username - passwordTextField.contentType = .password - } + usernameTextField.contentType = .username + passwordTextField.contentType = .password } } diff --git a/Mac/Preferences/Accounts/AccountsReaderAPIWindowController.swift b/Mac/Preferences/Accounts/AccountsReaderAPIWindowController.swift index b00d4646d..0c4d3c569 100644 --- a/Mac/Preferences/Accounts/AccountsReaderAPIWindowController.swift +++ b/Mac/Preferences/Accounts/AccountsReaderAPIWindowController.swift @@ -197,10 +197,8 @@ class AccountsReaderAPIWindowController: NSWindowController { // MARK: Autofill func enableAutofill() { - if #available(macOS 11, *) { - usernameTextField.contentType = .username - passwordTextField.contentType = .password - } + usernameTextField.contentType = .username + passwordTextField.contentType = .password } } diff --git a/Mac/Preferences/Accounts/AddAccountsView.swift b/Mac/Preferences/Accounts/AddAccountsView.swift index 6fc31957d..fb8fd6687 100644 --- a/Mac/Preferences/Accounts/AddAccountsView.swift +++ b/Mac/Preferences/Accounts/AddAccountsView.swift @@ -102,45 +102,25 @@ struct AddAccountsView: View { HStack(spacing: 12) { Spacer() - if #available(OSX 11.0, *) { - Button(action: { - parent?.dismiss(nil) - }, label: { - Text("Cancel") - .frame(width: 76) - }) - .help("Cancel") - .keyboardShortcut(.cancelAction) - - } else { - Button(action: { - parent?.dismiss(nil) - }, label: { - Text("Cancel") - .frame(width: 76) - }) - .accessibility(label: Text("Add Account")) - } - if #available(OSX 11.0, *) { - Button(action: { - addAccountDelegate?.presentSheetForAccount(selectedAccount) - parent?.dismiss(nil) - }, label: { - Text("Continue") - .frame(width: 76) - }) - .help("Add Account") - .keyboardShortcut(.defaultAction) - - } else { - Button(action: { - addAccountDelegate?.presentSheetForAccount(selectedAccount) - parent?.dismiss(nil) - }, label: { - Text("Continue") - .frame(width: 76) - }) - } + + Button(action: { + parent?.dismiss(nil) + }, label: { + Text("Cancel") + .frame(width: 76) + }) + .help("Cancel") + .keyboardShortcut(.cancelAction) + + Button(action: { + addAccountDelegate?.presentSheetForAccount(selectedAccount) + parent?.dismiss(nil) + }, label: { + Text("Continue") + .frame(width: 76) + }) + .help("Add Account") + .keyboardShortcut(.defaultAction) } .padding(.top, 12) .padding(.bottom, 4) diff --git a/Mac/Preferences/ExtensionPoints/EnableExtensionPointView.swift b/Mac/Preferences/ExtensionPoints/EnableExtensionPointView.swift index c8c0581fd..09b4ec3b3 100644 --- a/Mac/Preferences/ExtensionPoints/EnableExtensionPointView.swift +++ b/Mac/Preferences/ExtensionPoints/EnableExtensionPointView.swift @@ -34,46 +34,25 @@ struct EnableExtensionPointView: View { HStack(spacing: 12) { Spacer() - if #available(OSX 11.0, *) { - Button(action: { - parent?.dismiss(nil) - }, label: { - Text("Cancel") - .frame(width: 80) - }) - .help("Cancel") - .keyboardShortcut(.cancelAction) - - } else { - Button(action: { - parent?.dismiss(nil) - }, label: { - Text("Cancel") - .frame(width: 80) - }) - .accessibility(label: Text("Add Extension")) - } - if #available(OSX 11.0, *) { - Button(action: { - enabler?.enable(typeFromName(extensionPointTypeName)) - parent?.dismiss(nil) - }, label: { - Text("Continue") - .frame(width: 80) - }) - .help("Add Extension") - .keyboardShortcut(.defaultAction) - .disabled(disableContinue()) - } else { - Button(action: { - enabler?.enable(typeFromName(extensionPointTypeName)) - parent?.dismiss(nil) - }, label: { - Text("Continue") - .frame(width: 80) - }) - .disabled(disableContinue()) - } + Button(action: { + parent?.dismiss(nil) + }, label: { + Text("Cancel") + .frame(width: 80) + }) + .help("Cancel") + .keyboardShortcut(.cancelAction) + + Button(action: { + enabler?.enable(typeFromName(extensionPointTypeName)) + parent?.dismiss(nil) + }, label: { + Text("Continue") + .frame(width: 80) + }) + .help("Add Extension") + .keyboardShortcut(.defaultAction) + .disabled(disableContinue()) } .padding(.top, 12) .padding(.bottom, 4)