mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
fix battery widget; fix widget change; fix battery reader;
This commit is contained in:
@@ -97,6 +97,10 @@ extension Module {
|
||||
widget.shortName = String(self.name.prefix(3)).uppercased()
|
||||
widget.Init()
|
||||
|
||||
self.readers.forEach { reader in
|
||||
reader.read()
|
||||
}
|
||||
|
||||
self.widget.view = widget as! NSView
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class NetworkReader: Reader {
|
||||
self.read()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func read() {
|
||||
if !self.enabled && self.initialized { return }
|
||||
self.initialized = true
|
||||
@@ -44,13 +44,14 @@ class NetworkReader: Reader {
|
||||
continue
|
||||
}
|
||||
pointer = pointer!.pointee.ifa_next
|
||||
upload = info[0]
|
||||
download = info[1]
|
||||
upload += info[0]
|
||||
download += info[1]
|
||||
}
|
||||
freeifaddrs(interfaceAddresses)
|
||||
|
||||
let lastUpload = self.uploadValue
|
||||
let lastDownload = self.downloadValue
|
||||
|
||||
if lastUpload != 0 && lastDownload != 0 {
|
||||
DispatchQueue.main.async(execute: {
|
||||
self.callback([Double(download - lastDownload), Double(upload - lastUpload)])
|
||||
|
||||
@@ -47,8 +47,8 @@ class BatteryPercentageWidget: BatteryWidget {
|
||||
override func update() {
|
||||
if self.value == 0 { return }
|
||||
|
||||
if percentageValue.isHidden {
|
||||
percentageValue.isHidden = false
|
||||
if self.percentageValue.isHidden {
|
||||
self.percentageValue.isHidden = false
|
||||
}
|
||||
self.percentageValue.stringValue = "\(Int(self.value * 100))%"
|
||||
|
||||
|
||||
@@ -34,17 +34,25 @@ class BatteryTimeWidget: BatteryWidget {
|
||||
timeValue.alignment = .right
|
||||
timeValue.font = NSFont.systemFont(ofSize: 11, weight: .regular)
|
||||
timeValue.stringValue = (self.time*60).printSecondsToHoursMinutesSeconds()
|
||||
if self.time == 0 {
|
||||
timeValue.isHidden = true
|
||||
}
|
||||
|
||||
self.addSubview(timeValue)
|
||||
}
|
||||
|
||||
override func update() {
|
||||
if self.time <= 0 && self.size == self.batterySize + timeWidth {
|
||||
if self.value == 0 { return }
|
||||
|
||||
if self.timeValue.isHidden {
|
||||
self.timeValue.isHidden = false
|
||||
}
|
||||
self.timeValue.stringValue = (self.time*60).printSecondsToHoursMinutesSeconds()
|
||||
|
||||
if self.time == 0 && self.size == self.batterySize + timeWidth {
|
||||
self.changeWidth(width: 0)
|
||||
} else if self.time >= 0 || self.size != self.batterySize + timeWidth {
|
||||
} else if self.time > 0 && self.size != self.batterySize + timeWidth {
|
||||
self.changeWidth(width: timeWidth)
|
||||
}
|
||||
|
||||
self.timeValue.stringValue = (self.time*60).printSecondsToHoursMinutesSeconds()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public struct Units {
|
||||
public func getReadableSpeed() -> String {
|
||||
switch bytes {
|
||||
case 0..<1_024:
|
||||
return "0 KB"
|
||||
return "0 KB/s"
|
||||
case 1_024..<(1_024 * 1_024):
|
||||
return String(format: "%.0f KB/s", kilobytes)
|
||||
case 1_024..<(1_024 * 1_024 * 100):
|
||||
@@ -124,7 +124,7 @@ public struct Units {
|
||||
public func getReadableMemory() -> String {
|
||||
switch bytes {
|
||||
case 0..<1_024:
|
||||
return "0 KB"
|
||||
return "0 KB/s"
|
||||
case 1_024..<(1_024 * 1_024):
|
||||
return String(format: "%.0f KB", kilobytes)
|
||||
case 1_024..<(1_024 * 1_024 * 1_024):
|
||||
|
||||
Reference in New Issue
Block a user