mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: moved from custom byte formatter to the internal
This commit is contained in:
@@ -190,21 +190,16 @@ public struct Units {
|
||||
}
|
||||
}
|
||||
|
||||
public func getReadableMemory(to round: Int = 1) -> String {
|
||||
switch bytes {
|
||||
case 0..<1_000:
|
||||
return "0 KB"
|
||||
case 1_000..<(1_000 * 1_000):
|
||||
return String(format: "%.0f KB", kilobytes)
|
||||
case 1_000..<(1_000 * 1_000 * 1_000):
|
||||
return String(format: "%.0f MB", megabytes)
|
||||
case 1_000..<(1_000 * 1_000 * 1_000 * 1_000):
|
||||
return String(format: "%.1f GB", gigabytes)
|
||||
case (1_000 * 1_000 * 1_000 * 1_000)...Int64.max:
|
||||
return String(format: "%.1f TB", terabytes)
|
||||
default:
|
||||
return String(format: "%.0f KB", kilobytes)
|
||||
}
|
||||
public func getReadableMemory(style: ByteCountFormatter.CountStyle = .file) -> String {
|
||||
let formatter: ByteCountFormatter = ByteCountFormatter()
|
||||
formatter.countStyle = style
|
||||
formatter.includesUnit = true
|
||||
formatter.isAdaptive = true
|
||||
|
||||
var value = formatter.string(fromByteCount: Int64(bytes))
|
||||
value = value.replacingOccurrences(of: ",", with: ".")
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
public func toUnit(_ unit: SizeUnit) -> Double {
|
||||
|
||||
@@ -241,14 +241,14 @@ internal class Popup: PopupWrapper {
|
||||
public func loadCallback(_ value: RAM_Usage) {
|
||||
DispatchQueue.main.async(execute: {
|
||||
if (self.window?.isVisible ?? false) || !self.initialized {
|
||||
self.appField?.stringValue = Units(bytes: Int64(value.app)).getReadableMemory()
|
||||
self.inactiveField?.stringValue = Units(bytes: Int64(value.inactive)).getReadableMemory()
|
||||
self.wiredField?.stringValue = Units(bytes: Int64(value.wired)).getReadableMemory()
|
||||
self.compressedField?.stringValue = Units(bytes: Int64(value.compressed)).getReadableMemory()
|
||||
self.swapField?.stringValue = Units(bytes: Int64(value.swap.used)).getReadableMemory()
|
||||
self.appField?.stringValue = Units(bytes: Int64(value.app)).getReadableMemory(style: .memory)
|
||||
self.inactiveField?.stringValue = Units(bytes: Int64(value.inactive)).getReadableMemory(style: .memory)
|
||||
self.wiredField?.stringValue = Units(bytes: Int64(value.wired)).getReadableMemory(style: .memory)
|
||||
self.compressedField?.stringValue = Units(bytes: Int64(value.compressed)).getReadableMemory(style: .memory)
|
||||
self.swapField?.stringValue = Units(bytes: Int64(value.swap.used)).getReadableMemory(style: .memory)
|
||||
|
||||
self.usedField?.stringValue = Units(bytes: Int64(value.used)).getReadableMemory()
|
||||
self.freeField?.stringValue = Units(bytes: Int64(value.free)).getReadableMemory()
|
||||
self.usedField?.stringValue = Units(bytes: Int64(value.used)).getReadableMemory(style: .memory)
|
||||
self.freeField?.stringValue = Units(bytes: Int64(value.free)).getReadableMemory(style: .memory)
|
||||
|
||||
self.circle?.setValue(value.usage)
|
||||
self.circle?.setSegments([
|
||||
|
||||
Reference in New Issue
Block a user