feat: added a notification to the CPU usage (#913)

This commit is contained in:
Serhiy Mytrovtsiy
2022-07-04 18:11:52 +02:00
parent 576bfdd5e1
commit bd2b25bf52
3 changed files with 76 additions and 0 deletions

View File

@@ -20,6 +20,7 @@ internal class Settings: NSStackView, Settings_v {
private var updateIntervalValue: Int = 1
private var updateTopIntervalValue: Int = 1
private var numberOfProcesses: Int = 8
private var notificationLevel: String = "Disabled"
private let title: String
private var hasHyperthreadingCores = false
@@ -42,6 +43,7 @@ internal class Settings: NSStackView, Settings_v {
self.updateIntervalValue = Store.shared.int(key: "\(self.title)_updateInterval", defaultValue: self.updateIntervalValue)
self.updateTopIntervalValue = Store.shared.int(key: "\(self.title)_updateTopInterval", defaultValue: self.updateTopIntervalValue)
self.numberOfProcesses = Store.shared.int(key: "\(self.title)_processes", defaultValue: self.numberOfProcesses)
self.notificationLevel = Store.shared.string(key: "\(self.title)_notificationLevel", defaultValue: self.notificationLevel)
if !self.usagePerCoreState {
self.hyperthreadState = false
}
@@ -135,6 +137,13 @@ internal class Settings: NSStackView, Settings_v {
items: NumbersOfProcesses.map{ "\($0)" },
selected: "\(self.numberOfProcesses)"
))
self.addArrangedSubview(selectSettingsRow(
title: localizedString("Notification level"),
action: #selector(changeNotificationLevel),
items: notificationLevels,
selected: self.notificationLevel == "disabled" ? self.notificationLevel : "\(Int((Double(self.notificationLevel) ?? 0)*100))%"
))
}
@objc private func changeUpdateInterval(_ sender: NSMenuItem) {
@@ -225,4 +234,14 @@ internal class Settings: NSStackView, Settings_v {
Store.shared.set(key: "\(self.title)_splitValue", value: self.splitValueState)
self.callback()
}
@objc func changeNotificationLevel(_ sender: NSMenuItem) {
guard let key = sender.representedObject as? String else { return }
if key == "Disabled" {
Store.shared.set(key: "\(self.title)_notificationLevel", value: key)
} else if let value = Double(key.replacingOccurrences(of: "%", with: "")) {
Store.shared.set(key: "\(self.title)_notificationLevel", value: "\(value/100)")
}
}
}