diff --git a/Kit/helpers.swift b/Kit/helpers.swift index e8a6405a..958c9e6a 100644 --- a/Kit/helpers.swift +++ b/Kit/helpers.swift @@ -563,29 +563,6 @@ public func removeNotification(_ id: String) { center.removeDeliveredNotifications(withIdentifiers: [id]) } -public func showNSNotification(title: String, subtitle: String? = nil, body: String? = nil, userInfo: [AnyHashable: Any] = [:]) -> String { - let notification = NSUserNotification() - let id = UUID().uuidString - - notification.identifier = id - notification.title = title - notification.subtitle = subtitle - notification.informativeText = body - notification.soundName = NSUserNotificationDefaultSoundName - notification.hasActionButton = false - - NSUserNotificationCenter.default.deliver(notification) - - return id -} - -public func removeNSNotification(_ id: String) { - let notificationCenter = NSUserNotificationCenter.default - if let notification = notificationCenter.deliveredNotifications.first(where: { $0.identifier == id }) { - notificationCenter.removeScheduledNotification(notification) - } -} - public struct TopProcess { public var pid: Int public var command: String diff --git a/Kit/module/settings.swift b/Kit/module/settings.swift index 69ad6465..1e983e5b 100644 --- a/Kit/module/settings.swift +++ b/Kit/module/settings.swift @@ -223,11 +223,7 @@ class WidgetSelectorView: NSStackView { private var background: NSVisualEffectView = { let view = NSVisualEffectView(frame: NSRect.zero) view.blendingMode = .withinWindow - if #available(macOS 10.14, *) { - view.material = .contentBackground - } else { - view.material = .popover - } + view.material = .contentBackground view.state = .active view.wantsLayer = true view.layer?.cornerRadius = 5 diff --git a/Modules/Battery/main.swift b/Modules/Battery/main.swift index 7d6c5cc2..052d2408 100644 --- a/Modules/Battery/main.swift +++ b/Modules/Battery/main.swift @@ -105,11 +105,7 @@ public class Battery: Module { guard self.isAvailable() else { return } if let id = self.notificationID { - if #available(macOS 10.14, *) { - removeNotification(id) - } else { - removeNSNotification(id) - } + removeNotification(id) } } @@ -163,11 +159,7 @@ public class Battery: Module { if (value.level > notificationLevel || value.powerSource != "Battery Power") && self.lowLevelNotificationState { if value.level > notificationLevel { if let id = self.notificationID { - if #available(macOS 10.14, *) { - removeNotification(id) - } else { - removeNSNotification(id) - } + removeNotification(id) self.notificationID = nil } self.lowLevelNotificationState = false @@ -180,24 +172,11 @@ public class Battery: Module { } if value.level <= notificationLevel && !self.lowLevelNotificationState { - let title = localizedString("Low battery") var subtitle = localizedString("Battery remaining", "\(Int(value.level*100))") if value.timeToEmpty > 0 { subtitle += " (\(Double(value.timeToEmpty*60).printSecondsToHoursMinutesSeconds()))" } - - if #available(macOS 10.14, *) { - self.notificationID = showNotification( - title: title, - subtitle: subtitle - ) - } else { - self.notificationID = showNSNotification( - title: title, - subtitle: subtitle - ) - } - + self.notificationID = showNotification(title: localizedString("Low battery"), subtitle: subtitle) self.lowLevelNotificationState = true } } @@ -215,11 +194,7 @@ public class Battery: Module { if (value.level < notificationLevel || value.powerSource == "Battery Power") && self.highLevelNotificationState { if value.level < notificationLevel { if let id = self.notificationID { - if #available(macOS 10.14, *) { - removeNotification(id) - } else { - removeNSNotification(id) - } + removeNotification(id) self.notificationID = nil } self.highLevelNotificationState = false @@ -232,24 +207,11 @@ public class Battery: Module { } if value.level >= notificationLevel && !self.highLevelNotificationState { - let title = localizedString("High battery") var subtitle = localizedString("Battery remaining to full charge", "\(Int((1-value.level)*100))") if value.timeToCharge > 0 { subtitle += " (\(Double(value.timeToCharge*60).printSecondsToHoursMinutesSeconds()))" } - - if #available(macOS 10.14, *) { - self.notificationID = showNotification( - title: title, - subtitle: subtitle - ) - } else { - self.notificationID = showNSNotification( - title: title, - subtitle: subtitle - ) - } - + self.notificationID = showNotification(title: localizedString("High battery"), subtitle: subtitle) self.highLevelNotificationState = true } } diff --git a/Modules/CPU/main.swift b/Modules/CPU/main.swift index f3d08c89..80af0b2a 100644 --- a/Modules/CPU/main.swift +++ b/Modules/CPU/main.swift @@ -218,24 +218,14 @@ public class CPU: Module { guard self.notificationLevel != "Disabled", let level = Double(self.notificationLevel) else { return } if let id = self.notificationID, value < level && self.notificationLevelState { - if #available(macOS 10.14, *) { - removeNotification(id) - } else { - removeNSNotification(id) - } - + removeNotification(id) self.notificationID = nil self.notificationLevelState = false } else if value >= level && !self.notificationLevelState { - let title = localizedString("CPU usage threshold") - let subtitle = localizedString("CPU usage is", "\(Int((value)*100))%") - - if #available(macOS 10.14, *) { - self.notificationID = showNotification(title: title, subtitle: subtitle) - } else { - self.notificationID = showNSNotification(title: title, subtitle: subtitle) - } - + self.notificationID = showNotification( + title: localizedString("CPU usage threshold"), + subtitle: localizedString("CPU usage is", "\(Int((value)*100))%") + ) self.notificationLevelState = true } } diff --git a/Modules/Disk/main.swift b/Modules/Disk/main.swift index 81e6e5f3..5f7ec8c3 100644 --- a/Modules/Disk/main.swift +++ b/Modules/Disk/main.swift @@ -259,24 +259,14 @@ public class Disk: Module { guard self.notificationLevel != "Disabled", let level = Double(self.notificationLevel) else { return } if let id = self.notificationID, value < level && self.notificationLevelState { - if #available(macOS 10.14, *) { - removeNotification(id) - } else { - removeNSNotification(id) - } - + removeNotification(id) self.notificationID = nil self.notificationLevelState = false } else if value >= level && !self.notificationLevelState { - let title = localizedString("Disk utilization threshold") - let subtitle = localizedString("Disk utilization is", "\(Int((value)*100))%") - - if #available(macOS 10.14, *) { - self.notificationID = showNotification(title: title, subtitle: subtitle) - } else { - self.notificationID = showNSNotification(title: title, subtitle: subtitle) - } - + self.notificationID = showNotification( + title: localizedString("Disk utilization threshold"), + subtitle: localizedString("Disk utilization is", "\(Int((value)*100))%") + ) self.notificationLevelState = true } } diff --git a/Modules/GPU/main.swift b/Modules/GPU/main.swift index 56b0da40..2bdc0f3f 100644 --- a/Modules/GPU/main.swift +++ b/Modules/GPU/main.swift @@ -160,24 +160,14 @@ public class GPU: Module { guard self.notificationLevel != "Disabled", let level = Double(self.notificationLevel) else { return } if let id = self.notificationID, value < level && self.notificationLevelState { - if #available(macOS 10.14, *) { - removeNotification(id) - } else { - removeNSNotification(id) - } - + removeNotification(id) self.notificationID = nil self.notificationLevelState = false } else if value >= level && !self.notificationLevelState { - let title = localizedString("GPU usage threshold") - let subtitle = localizedString("GPU usage is", "\(Int((value)*100))%") - - if #available(macOS 10.14, *) { - self.notificationID = showNotification(title: title, subtitle: subtitle) - } else { - self.notificationID = showNSNotification(title: title, subtitle: subtitle) - } - + self.notificationID = showNotification( + title: localizedString("GPU usage threshold"), + subtitle: localizedString("GPU usage is", "\(Int((value)*100))%") + ) self.notificationLevelState = true } } diff --git a/Modules/RAM/main.swift b/Modules/RAM/main.swift index 46a950a1..04d79349 100644 --- a/Modules/RAM/main.swift +++ b/Modules/RAM/main.swift @@ -194,24 +194,14 @@ public class RAM: Module { guard self.notificationLevel != "Disabled", let level = Double(self.notificationLevel) else { return } if let id = self.notificationID, value < level && self.notificationLevelState { - if #available(macOS 10.14, *) { - removeNotification(id) - } else { - removeNSNotification(id) - } - + removeNotification(id) self.notificationID = nil self.notificationLevelState = false } else if value >= level && !self.notificationLevelState { - let title = localizedString("RAM utilization threshold") - let subtitle = localizedString("RAM utilization is", "\(Int((value)*100))%") - - if #available(macOS 10.14, *) { - self.notificationID = showNotification(title: title, subtitle: subtitle) - } else { - self.notificationID = showNSNotification(title: title, subtitle: subtitle) - } - + self.notificationID = showNotification( + title: localizedString("RAM utilization threshold"), + subtitle: localizedString("RAM utilization is", "\(Int((value)*100))%") + ) self.notificationLevelState = true } } diff --git a/Stats/Views/Settings.swift b/Stats/Views/Settings.swift index 52714974..b713374c 100644 --- a/Stats/Views/Settings.swift +++ b/Stats/Views/Settings.swift @@ -237,11 +237,7 @@ private class MainView: NSView { let foreground = NSVisualEffectView(frame: NSRect(x: 0, y: 0, width: frame.width, height: frame.height)) foreground.blendingMode = .withinWindow - if #available(macOS 10.14, *) { - foreground.material = .windowBackground - } else { - foreground.material = .popover - } + foreground.material = .windowBackground foreground.state = .active super.init(frame: NSRect.zero) @@ -577,23 +573,14 @@ private class MenuItem: NSView { NotificationCenter.default.post(name: .openModuleSettings, object: nil, userInfo: ["module": self.title]) - if #available(macOS 10.14, *) { - self.layer?.backgroundColor = NSColor.selectedContentBackgroundColor.cgColor - } else { - self.layer?.backgroundColor = NSColor.systemBlue.cgColor - } - - if #available(macOS 10.14, *) { - self.imageView?.contentTintColor = .white - } + self.layer?.backgroundColor = NSColor.selectedContentBackgroundColor.cgColor + self.imageView?.contentTintColor = .white self.titleView?.textColor = .white } public func reset() { self.layer?.backgroundColor = .clear - if #available(macOS 10.14, *) { - self.imageView?.contentTintColor = .labelColor - } + self.imageView?.contentTintColor = .labelColor self.titleView?.textColor = .labelColor self.active = false } diff --git a/Stats/helpers.swift b/Stats/helpers.swift index 941cb985..14b942b6 100644 --- a/Stats/helpers.swift +++ b/Stats/helpers.swift @@ -73,23 +73,9 @@ extension AppDelegate { let title: String = localizedString("Successfully updated") let subtitle: String = localizedString("Stats was updated to v", currentVersion) - if #available(macOS 10.14, *) { - let id = showNotification( - title: title, - subtitle: subtitle, - delegate: self - ) - DispatchQueue.main.asyncAfter(deadline: .now() + 10) { - removeNotification(id) - } - } else { - let id = showNSNotification( - title: title, - subtitle: subtitle - ) - DispatchQueue.main.asyncAfter(deadline: .now() + 10) { - removeNSNotification(id) - } + let id = showNotification(title: title, subtitle: subtitle, delegate: self) + DispatchQueue.main.asyncAfter(deadline: .now() + 10) { + removeNotification(id) } } @@ -211,25 +197,12 @@ extension AppDelegate { private func showUpdateNotification(version: version_s) { debug("show update notification") - - let title = localizedString("New version available") - let subtitle = localizedString("Click to install the new version of Stats") - let userInfo = ["url": version.url] - - if #available(macOS 10.14, *) { - _ = showNotification( - title: title, - subtitle: subtitle, - userInfo: userInfo, - delegate: self - ) - } else { - _ = showNSNotification( - title: title, - subtitle: subtitle, - userInfo: userInfo - ) - } + _ = showNotification( + title: localizedString("New version available"), + subtitle: localizedString("Click to install the new version of Stats"), + userInfo: ["url": version.url], + delegate: self + ) } private func showUpdateWindow(version: version_s) {