🔥 Removes unused #available checks

This commit is contained in:
Stuart Breckenridge
2025-06-20 19:48:15 +08:00
parent 00b8affe5f
commit cabaa32be5
14 changed files with 80 additions and 210 deletions

View File

@@ -50,7 +50,7 @@ struct AppAssets {
static let nnwFeedIcon = RSImage(named: "nnwFeedIcon")!
@available(macOS 11.0, *)
static var addNewSidebarItemImage: RSImage = {
return NSImage(systemSymbolName: "plus", accessibilityDescription: nil)!
}()
@@ -67,12 +67,12 @@ struct AppAssets {
return RSImage(named: "articleExtractorOn")!
}()
@available(macOS 11.0, *)
static var articleTheme: RSImage = {
return NSImage(systemSymbolName: "doc.richtext", accessibilityDescription: nil)!
}()
@available(macOS 11.0, *)
static var cleanUpImage: RSImage = {
return NSImage(systemSymbolName: "wind", accessibilityDescription: nil)!
}()
@@ -90,19 +90,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 = {
@@ -146,64 +138,48 @@ struct AppAssets {
}()
static var mainFolderImage: IconImage {
if #available(macOS 11.0, *) {
let image = NSImage(systemSymbolName: "folder", accessibilityDescription: nil)!
let preferredColor = NSColor(named: "AccentColor")!
return IconImage(image, isSymbol: true, isBackgroundSuppressed: true, preferredColor: preferredColor.cgColor)
} else {
return IconImage(RSImage(named: NSImage.folderName)!)
}
let image = NSImage(systemSymbolName: "folder", accessibilityDescription: nil)!
let preferredColor = NSColor(named: "AccentColor")!
return IconImage(image, isSymbol: true, isBackgroundSuppressed: true, preferredColor: preferredColor.cgColor)
}
static var markAllAsReadImage: RSImage = {
return RSImage(named: "markAllAsRead")!
}()
@available(macOS 11.0, *)
static var nextUnreadImage: RSImage = {
return NSImage(systemSymbolName: "chevron.down.circle", accessibilityDescription: nil)!
}()
@available(macOS 11.0, *)
static var openInBrowserImage: RSImage = {
return NSImage(systemSymbolName: "safari", accessibilityDescription: nil)!
}()
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 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, *)
static var readClosedImage: RSImage = {
return NSImage(systemSymbolName: "largecircle.fill.circle", accessibilityDescription: nil)!
}()
@available(macOS 11.0, *)
static var readOpenImage: RSImage = {
return NSImage(systemSymbolName: "circle", accessibilityDescription: nil)!
}()
@available(macOS 11.0, *)
static var refreshImage: RSImage = {
return NSImage(systemSymbolName: "arrow.clockwise", accessibilityDescription: nil)!
}()
@@ -212,34 +188,30 @@ struct AppAssets {
return IconImage(RSImage(named: NSImage.smartBadgeTemplateName)!, isSymbol: true, isBackgroundSuppressed: true)
}()
@available(macOS 11.0, *)
static var shareImage: RSImage = {
return NSImage(systemSymbolName: "square.and.arrow.up", accessibilityDescription: nil)!
}()
@available(macOS 11.0, *)
static var sidebarToggleImage: RSImage = {
return NSImage(systemSymbolName: "sidebar.left", accessibilityDescription: nil)!
}()
@available(macOS 11.0, *)
static var starClosedImage: RSImage = {
return NSImage(systemSymbolName: "star.fill", accessibilityDescription: nil)!
}()
@available(macOS 11.0, *)
static var starOpenImage: RSImage = {
return NSImage(systemSymbolName: "star", accessibilityDescription: nil)!
}()
static var starredFeedImage: IconImage = {
if #available(macOS 11.0, *) {
let image = NSImage(systemSymbolName: "star.fill", accessibilityDescription: nil)!
let preferredColor = NSColor(named: "StarColor")!
return IconImage(image, isSymbol: true, isBackgroundSuppressed: true, preferredColor: preferredColor.cgColor)
} else {
return IconImage(RSImage(named: NSImage.smartBadgeTemplateName)!, isBackgroundSuppressed: true)
}
let image = NSImage(systemSymbolName: "star.fill", accessibilityDescription: nil)!
let preferredColor = NSColor(named: "StarColor")!
return IconImage(image, isSymbol: true, isBackgroundSuppressed: true, preferredColor: preferredColor.cgColor)
}()
static var timelineSeparatorColor: NSColor = {
@@ -255,61 +227,35 @@ struct AppAssets {
}()
static var todayFeedImage: IconImage = {
if #available(macOS 11.0, *) {
let image = NSImage(systemSymbolName: "sun.max.fill", accessibilityDescription: nil)!
let preferredColor = NSColor.orange
return IconImage(image, isSymbol: true, isBackgroundSuppressed: true, preferredColor: preferredColor.cgColor)
} else {
return IconImage(RSImage(named: NSImage.smartBadgeTemplateName)!, isBackgroundSuppressed: true)
}
let image = NSImage(systemSymbolName: "sun.max.fill", accessibilityDescription: nil)!
let preferredColor = NSColor.orange
return IconImage(image, isSymbol: true, isBackgroundSuppressed: 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")!
return IconImage(image, isSymbol: true, isBackgroundSuppressed: true, preferredColor: preferredColor.cgColor)
} else {
return IconImage(RSImage(named: NSImage.smartBadgeTemplateName)!, isBackgroundSuppressed: true)
}
let image = NSImage(systemSymbolName: "largecircle.fill.circle", accessibilityDescription: nil)!
let preferredColor = NSColor(named: "AccentColor")!
return IconImage(image, isSymbol: true, isBackgroundSuppressed: 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 = {

View File

@@ -798,30 +798,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("Authors 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

View File

@@ -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
}
}

View File

@@ -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)
}

View File

@@ -29,6 +29,7 @@ class FolderTreeMenu {
}
let menuItem = NSMenuItem(title: account.nameForDisplay, action: nil, keyEquivalent: "")
menuItem.image = AppAssets.image(for: <#T##AccountType#>)
menuItem.representedObject = childNode.representedObject
if account.behaviors.contains(.disallowFeedInRootFolder) {

View File

@@ -120,19 +120,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
@@ -346,9 +333,6 @@ 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"
}
webView.evaluateJavaScript(javascriptString) { (info, error) in
guard let info = info as? [String: Any] else {

View File

@@ -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

View File

@@ -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

View File

@@ -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)
])
}
}

View File

@@ -208,9 +208,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
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)

View File

@@ -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
}
}

View File

@@ -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
}
}

View File

@@ -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
}
}

View File

@@ -102,45 +102,23 @@ 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)