From 03e37cfc4a1fe55877d77807665912db773379e2 Mon Sep 17 00:00:00 2001 From: Serhiy Mytrovtsiy Date: Thu, 16 Feb 2023 19:44:10 +0100 Subject: [PATCH] feat: removed macOS 10.14* checks --- Kit/Widgets/BarChart.swift | 6 +++--- Kit/Widgets/LineChart.swift | 6 +++--- Kit/Widgets/Mini.swift | 6 +++--- Kit/extensions.swift | 21 ++++++------------- Kit/helpers.swift | 6 +----- Kit/module/popup.swift | 8 ++----- Kit/plugins/Charts.swift | 6 +++--- Kit/types.swift | 12 +---------- Modules/Disk/popup.swift | 2 +- Modules/Net/popup.swift | 8 ++----- Stats/AppDelegate.swift | 1 - Stats/Views/Settings.swift | 4 +--- Stats/helpers.swift | 42 +++++++++++++++++-------------------- 13 files changed, 45 insertions(+), 83 deletions(-) diff --git a/Kit/Widgets/BarChart.swift b/Kit/Widgets/BarChart.swift index aeb45b92..75c309d7 100644 --- a/Kit/Widgets/BarChart.swift +++ b/Kit/Widgets/BarChart.swift @@ -170,17 +170,17 @@ public class BarChart: WidgetWrapper { if partitionValue.color == nil { switch self.colorState { - case .systemAccent: controlAccentColor.set() + case .systemAccent: NSColor.controlAccentColor.set() case .utilization: partitionValue.value.usageColor(zones: self.colorZones, reversed: self.title == "Battery").set() case .pressure: self.pressureLevel.pressureColor().set() - case .cluster: (partitionValue.value.clusterColor(i) ?? controlAccentColor).set() + case .cluster: (partitionValue.value.clusterColor(i) ?? .controlAccentColor).set() case .monochrome: if self.boxState { (isDarkMode ? NSColor.black : NSColor.white).set() } else { (isDarkMode ? NSColor.white : NSColor.black).set() } - default: (self.colorState.additional as? NSColor ?? controlAccentColor).set() + default: (self.colorState.additional as? NSColor ?? .controlAccentColor).set() } } else { partitionValue.color?.set() diff --git a/Kit/Widgets/LineChart.swift b/Kit/Widgets/LineChart.swift index 1cacbb89..fbd26569 100644 --- a/Kit/Widgets/LineChart.swift +++ b/Kit/Widgets/LineChart.swift @@ -134,9 +134,9 @@ public class LineChart: WidgetWrapper { let offset = lineWidth / 2 var boxSize: CGSize = CGSize(width: self.width - (Constants.Widget.margin.x*2), height: self.frame.size.height) - var color: NSColor = controlAccentColor + var color: NSColor = .controlAccentColor switch self.colorState { - case .systemAccent: color = controlAccentColor + case .systemAccent: color = .controlAccentColor case .utilization: color = value.usageColor() case .pressure: color = self.pressureLevel.pressureColor() case .monochrome: @@ -145,7 +145,7 @@ public class LineChart: WidgetWrapper { } else { color = (isDarkMode ? NSColor.white : NSColor.black) } - default: color = self.colorState.additional as? NSColor ?? controlAccentColor + default: color = self.colorState.additional as? NSColor ?? .controlAccentColor } if self.labelState { diff --git a/Kit/Widgets/Mini.swift b/Kit/Widgets/Mini.swift index 070ad3ba..badd56da 100644 --- a/Kit/Widgets/Mini.swift +++ b/Kit/Widgets/Mini.swift @@ -119,13 +119,13 @@ public class Mini: WidgetWrapper { origin.y = 1 } - var color: NSColor = controlAccentColor + var color: NSColor = .controlAccentColor switch self.colorState { - case .systemAccent: color = controlAccentColor + case .systemAccent: color = .controlAccentColor case .utilization: color = value.usageColor(zones: self.colorZones, reversed: self.title == "BAT") case .pressure: color = self.pressureLevel.pressureColor() case .monochrome: color = (isDarkMode ? NSColor.white : NSColor.black) - default: color = self.colorState.additional as? NSColor ?? controlAccentColor + default: color = self.colorState.additional as? NSColor ?? .controlAccentColor } let stringAttributes = [ diff --git a/Kit/extensions.swift b/Kit/extensions.swift index 1168e2ec..6370dbe9 100644 --- a/Kit/extensions.swift +++ b/Kit/extensions.swift @@ -121,7 +121,7 @@ public extension DispatchSource.MemoryPressureEvent { case .critical: return NSColor.systemRed default: - return controlAccentColor + return .controlAccentColor } } } @@ -247,20 +247,11 @@ public extension Double { public extension NSView { var isDarkMode: Bool { - if #available(OSX 10.14, *) { - switch effectiveAppearance.name { - case .darkAqua, .vibrantDark, .accessibilityHighContrastDarkAqua, .accessibilityHighContrastVibrantDark: - return true - default: - return false - } - } else { - switch effectiveAppearance.name { - case .vibrantDark: - return true - default: - return false - } + switch effectiveAppearance.name { + case .darkAqua, .vibrantDark, .accessibilityHighContrastDarkAqua, .accessibilityHighContrastVibrantDark: + return true + default: + return false } } diff --git a/Kit/helpers.swift b/Kit/helpers.swift index 3ee67242..dc9a40ef 100644 --- a/Kit/helpers.swift +++ b/Kit/helpers.swift @@ -531,7 +531,6 @@ public func isNewestVersion(currentVersion: String, latestVersion: String) -> Bo return false } -@available(macOS 10.14, *) public func showNotification(title: String, subtitle: String? = nil, userInfo: [AnyHashable: Any] = [:], delegate: UNUserNotificationCenterDelegate? = nil) -> String { let id = UUID().uuidString @@ -557,7 +556,6 @@ public func showNotification(title: String, subtitle: String? = nil, userInfo: [ return id } -@available(macOS 10.14, *) public func removeNotification(_ id: String) { let center = UNUserNotificationCenter.current() center.removeDeliveredNotifications(withIdentifiers: [id]) @@ -786,9 +784,7 @@ public class ProcessView: NSStackView { self.killView.translatesAutoresizingMaskIntoConstraints = false self.killView.imageScaling = .scaleNone self.killView.image = Bundle(for: type(of: self)).image(forResource: "cancel")! - if #available(OSX 10.14, *) { - self.killView.contentTintColor = .lightGray - } + self.killView.contentTintColor = .lightGray self.killView.isBordered = false self.killView.action = #selector(self.kill) self.killView.target = self diff --git a/Kit/module/popup.swift b/Kit/module/popup.swift index 18c57e30..650bc1b7 100644 --- a/Kit/module/popup.swift +++ b/Kit/module/popup.swift @@ -290,9 +290,7 @@ internal class HeaderView: NSStackView { activity.translatesAutoresizingMaskIntoConstraints = false activity.imageScaling = .scaleNone activity.image = Bundle(for: type(of: self)).image(forResource: "chart")! - if #available(OSX 10.14, *) { - activity.contentTintColor = .lightGray - } + activity.contentTintColor = .lightGray activity.isBordered = false activity.action = #selector(openActivityMonitor) activity.target = self @@ -320,9 +318,7 @@ internal class HeaderView: NSStackView { settings.translatesAutoresizingMaskIntoConstraints = false settings.imageScaling = .scaleNone settings.image = Bundle(for: type(of: self)).image(forResource: "settings")! - if #available(OSX 10.14, *) { - settings.contentTintColor = .lightGray - } + settings.contentTintColor = .lightGray settings.isBordered = false settings.action = #selector(openSettings) settings.target = self diff --git a/Kit/plugins/Charts.swift b/Kit/plugins/Charts.swift index 560f25b7..d675f156 100644 --- a/Kit/plugins/Charts.swift +++ b/Kit/plugins/Charts.swift @@ -74,7 +74,7 @@ public class LineChartView: NSView { public var points: [Double] public var shadowPoints: [Double] = [] public var transparent: Bool = true - public var color: NSColor = controlAccentColor + public var color: NSColor = .controlAccentColor public var suffix: String = "%" public var scale: Scale @@ -699,7 +699,7 @@ public class BarChartView: NSView { public init(frame: NSRect, num: Int) { super.init(frame: frame) - self.values = Array(repeating: ColorValue(0, color: controlAccentColor), count: num) + self.values = Array(repeating: ColorValue(0, color: .controlAccentColor), count: num) } required init?(coder: NSCoder) { @@ -724,7 +724,7 @@ public class BarChartView: NSView { partition.close() let value = self.values[i] - let color = value.color ?? controlAccentColor + let color = value.color ?? .controlAccentColor let activeBlockNum = Int(round(value.value*Double(blocks))) var y: CGFloat = spacing diff --git a/Kit/types.swift b/Kit/types.swift index 226bfbc9..4e2c2ac4 100644 --- a/Kit/types.swift +++ b/Kit/types.swift @@ -138,7 +138,7 @@ extension Color: CaseIterable { public static var separator1: Color { return Color(key: "separator_1", value: "separator_1", additional: NSColor.black) } - public static var systemAccent: Color { return Color(key: "system", value: "System accent", additional: controlAccentColor) } + public static var systemAccent: Color { return Color(key: "system", value: "System accent", additional: NSColor.controlAccentColor) } public static var monochrome: Color { return Color(key: "monochrome", value: "Monochrome accent", additional: NSColor.textColor) } public static var separator2: Color { return Color(key: "separator_2", value: "separator_2", additional: NSColor.black) } @@ -197,16 +197,6 @@ extension Color: CaseIterable { } } -public var controlAccentColor: NSColor { - get { - if #available(OSX 10.14, *) { - return NSColor.controlAccentColor - } else { - return NSColor.systemBlue - } - } -} - public class MonochromeColor { static public let base: NSColor = NSColor.textColor static public let red: NSColor = NSColor(red: (145), green: (145), blue: (145), alpha: 1) diff --git a/Modules/Disk/popup.swift b/Modules/Disk/popup.swift index 67835dea..0e3c24c5 100644 --- a/Modules/Disk/popup.swift +++ b/Modules/Disk/popup.swift @@ -308,7 +308,7 @@ internal class BarView: NSView { let width: CGFloat = (view.frame.width * (percentage < 0 ? 0 : percentage)) / 1 self.usedBarSpace = NSView(frame: NSRect(x: 0, y: 0, width: width, height: view.frame.height)) self.usedBarSpace?.wantsLayer = true - self.usedBarSpace?.layer?.backgroundColor = controlAccentColor.cgColor + self.usedBarSpace?.layer?.backgroundColor = NSColor.controlAccentColor.cgColor view.addSubview(self.usedBarSpace!) self.addSubview(view) diff --git a/Modules/Net/popup.swift b/Modules/Net/popup.swift index 29d8905d..460d9ad8 100644 --- a/Modules/Net/popup.swift +++ b/Modules/Net/popup.swift @@ -194,9 +194,7 @@ internal class Popup: NSStackView, Popup_p { button.bezelStyle = .regularSquare button.isBordered = false button.imageScaling = NSImageScaling.scaleAxesIndependently - if #available(OSX 10.14, *) { - button.contentTintColor = .lightGray - } + button.contentTintColor = .lightGray button.action = #selector(self.resetTotalNetworkUsage) button.target = self button.toolTip = localizedString("Reset") @@ -249,9 +247,7 @@ internal class Popup: NSStackView, Popup_p { button.bezelStyle = .regularSquare button.isBordered = false button.imageScaling = NSImageScaling.scaleAxesIndependently - if #available(OSX 10.14, *) { - button.contentTintColor = .lightGray - } + button.contentTintColor = .lightGray button.action = #selector(self.refreshPublicIP) button.target = self button.toolTip = localizedString("Refresh") diff --git a/Stats/AppDelegate.swift b/Stats/AppDelegate.swift index e2b6e681..884b590b 100755 --- a/Stats/AppDelegate.swift +++ b/Stats/AppDelegate.swift @@ -93,7 +93,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele return true } - @available(macOS 10.14, *) func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { diff --git a/Stats/Views/Settings.swift b/Stats/Views/Settings.swift index cede0b28..5b4b36d8 100644 --- a/Stats/Views/Settings.swift +++ b/Stats/Views/Settings.swift @@ -411,9 +411,7 @@ private class SidebarView: NSStackView { button.translatesAutoresizingMaskIntoConstraints = false button.imageScaling = .scaleNone button.image = image - if #available(OSX 10.14, *) { - button.contentTintColor = .secondaryLabelColor - } + button.contentTintColor = .secondaryLabelColor button.isBordered = false button.action = action button.target = self diff --git a/Stats/helpers.swift b/Stats/helpers.swift index 14b942b6..fb39ed00 100644 --- a/Stats/helpers.swift +++ b/Stats/helpers.swift @@ -167,30 +167,26 @@ extension AppDelegate { debug("show update view because new version of app found: \(version.latest)") - if #available(OSX 10.14, *) { - let center = UNUserNotificationCenter.current() - center.getNotificationSettings { settings in - switch settings.authorizationStatus { - case .authorized, .provisional: - self.showUpdateNotification(version: version) - case .denied: - self.showUpdateWindow(version: version) - case .notDetermined: - center.requestAuthorization(options: [.sound, .alert, .badge], completionHandler: { (_, error) in - if error == nil { - NSApplication.shared.registerForRemoteNotifications() - self.showUpdateNotification(version: version) - } else { - self.showUpdateWindow(version: version) - } - }) - @unknown default: - self.showUpdateWindow(version: version) - error_msg("unknown notification setting") - } + let center = UNUserNotificationCenter.current() + center.getNotificationSettings { settings in + switch settings.authorizationStatus { + case .authorized, .provisional: + self.showUpdateNotification(version: version) + case .denied: + self.showUpdateWindow(version: version) + case .notDetermined: + center.requestAuthorization(options: [.sound, .alert, .badge], completionHandler: { (_, error) in + if error == nil { + NSApplication.shared.registerForRemoteNotifications() + self.showUpdateNotification(version: version) + } else { + self.showUpdateWindow(version: version) + } + }) + @unknown default: + self.showUpdateWindow(version: version) + error_msg("unknown notification setting") } - } else { - self.showUpdateWindow(version: version) } } }