fix: improved network threshold logic (#1211)

This commit is contained in:
Serhiy Mytrovtsiy
2022-12-12 18:51:16 +01:00
parent c7082db26d
commit 51ebe2907e

View File

@@ -110,9 +110,7 @@ public class Network: Module {
private let usageReseter = NSBackgroundActivityScheduler(identifier: "eu.exelban.Stats.Network.Usage") private let usageReseter = NSBackgroundActivityScheduler(identifier: "eu.exelban.Stats.Network.Usage")
private var widgetActivationThreshold: Int { private var widgetActivationThreshold: Int {
get { Store.shared.int(key: "\(self.config.name)_widgetActivationThreshold", defaultValue: 0) * 1_024
return Store.shared.int(key: "\(self.config.name)_widgetActivationThreshold", defaultValue: 0)
}
} }
public init() { public init() {
@@ -198,13 +196,11 @@ public class Network: Module {
self.popupView.usageCallback(value) self.popupView.usageCallback(value)
var upload = value.bandwidth.upload var upload: Int64 = 0
var download = value.bandwidth.download var download: Int64 = 0
let activationValue = Units(bytes: min(upload, download)).kilobytes if value.bandwidth.upload >= self.widgetActivationThreshold || value.bandwidth.download >= self.widgetActivationThreshold {
upload = value.bandwidth.upload
if Double(self.widgetActivationThreshold) > activationValue { download = value.bandwidth.download
upload = 0
download = 0
} }
self.menuBar.widgets.filter{ $0.isActive }.forEach { (w: Widget) in self.menuBar.widgets.filter{ $0.isActive }.forEach { (w: Widget) in