feat: removed check for macOS 10.14

This commit is contained in:
Serhiy Mytrovtsiy
2023-01-31 18:27:43 +01:00
parent 36d4aa5a88
commit 6c991de101
9 changed files with 39 additions and 184 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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