mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 15:14:33 +00:00
Merge pull request #17 from Ebullioscopic/ui/frutiger-aero
Fix: Double conversion network error
This commit is contained in:
commit
96e7f46460
6 changed files with 55 additions and 22 deletions
|
|
@ -90,8 +90,8 @@ struct NotchStatsView: View {
|
||||||
if showNetworkGraph {
|
if showNetworkGraph {
|
||||||
graphs.append(DualGraphData(
|
graphs.append(DualGraphData(
|
||||||
title: "Network",
|
title: "Network",
|
||||||
positiveValue: String(format: "↓%.1f MB/s", statsManager.networkDownload),
|
positiveValue: "↓" + statsManager.networkDownloadString,
|
||||||
negativeValue: String(format: "↑%.1f MB/s", statsManager.networkUpload),
|
negativeValue: "↑" + statsManager.networkUploadString,
|
||||||
positiveData: statsManager.networkDownloadHistory,
|
positiveData: statsManager.networkDownloadHistory,
|
||||||
negativeData: statsManager.networkUploadHistory,
|
negativeData: statsManager.networkUploadHistory,
|
||||||
positiveColor: .orange,
|
positiveColor: .orange,
|
||||||
|
|
@ -104,8 +104,8 @@ struct NotchStatsView: View {
|
||||||
if showDiskGraph {
|
if showDiskGraph {
|
||||||
graphs.append(DualGraphData(
|
graphs.append(DualGraphData(
|
||||||
title: "Disk",
|
title: "Disk",
|
||||||
positiveValue: String(format: "R %.1f MB/s", statsManager.diskRead),
|
positiveValue: "R " + statsManager.diskReadString,
|
||||||
negativeValue: String(format: "W %.1f MB/s", statsManager.diskWrite),
|
negativeValue: "W " + statsManager.diskWriteString,
|
||||||
positiveData: statsManager.diskReadHistory,
|
positiveData: statsManager.diskReadHistory,
|
||||||
negativeData: statsManager.diskWriteHistory,
|
negativeData: statsManager.diskWriteHistory,
|
||||||
positiveColor: .cyan,
|
positiveColor: .cyan,
|
||||||
|
|
|
||||||
0
DynamicIsland/components/Stats/DualTimelineGraph.swift
Normal file
0
DynamicIsland/components/Stats/DualTimelineGraph.swift
Normal file
|
|
@ -64,7 +64,7 @@ class StatsPanel: NSPanel {
|
||||||
self.contentView = hostingView
|
self.contentView = hostingView
|
||||||
|
|
||||||
// Set initial size
|
// Set initial size
|
||||||
let preferredSize = CGSize(width: 600, height: 500)
|
let preferredSize = CGSize(width: 600, height: 400)
|
||||||
hostingView.setFrameSize(preferredSize)
|
hostingView.setFrameSize(preferredSize)
|
||||||
setContentSize(preferredSize)
|
setContentSize(preferredSize)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,7 @@ struct StatsPanelView: View {
|
||||||
.padding(16)
|
.padding(16)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.frame(width: 600, height: 500)
|
.frame(width: 650, height: 300)
|
||||||
.background(VisualEffectView(material: .hudWindow, blendingMode: .behindWindow))
|
.background(VisualEffectView(material: .hudWindow, blendingMode: .behindWindow))
|
||||||
.cornerRadius(12)
|
.cornerRadius(12)
|
||||||
.shadow(color: .black.opacity(0.4), radius: 20, x: 0, y: 10)
|
.shadow(color: .black.opacity(0.4), radius: 20, x: 0, y: 10)
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,15 @@ class StatsManager: ObservableObject {
|
||||||
func startMonitoring() {
|
func startMonitoring() {
|
||||||
guard !isMonitoring else { return }
|
guard !isMonitoring else { return }
|
||||||
|
|
||||||
|
// Reset baseline for accurate measurement
|
||||||
|
let initialStats = getNetworkStats()
|
||||||
|
previousNetworkStats = initialStats
|
||||||
|
|
||||||
|
let initialDiskStats = getDiskStats()
|
||||||
|
previousDiskStats = initialDiskStats
|
||||||
|
|
||||||
|
previousTimestamp = Date()
|
||||||
|
|
||||||
isMonitoring = true
|
isMonitoring = true
|
||||||
lastUpdated = Date()
|
lastUpdated = Date()
|
||||||
|
|
||||||
|
|
@ -108,19 +117,35 @@ class StatsManager: ObservableObject {
|
||||||
let currentTime = Date()
|
let currentTime = Date()
|
||||||
let timeInterval = currentTime.timeIntervalSince(previousTimestamp)
|
let timeInterval = currentTime.timeIntervalSince(previousTimestamp)
|
||||||
|
|
||||||
let bytesDownloaded = currentNetworkStats.bytesIn - previousNetworkStats.bytesIn
|
var downloadSpeed: Double = 0.0
|
||||||
let bytesUploaded = currentNetworkStats.bytesOut - previousNetworkStats.bytesOut
|
var uploadSpeed: Double = 0.0
|
||||||
|
|
||||||
let downloadSpeed = timeInterval > 0 ? Double(bytesDownloaded) / timeInterval / 1_048_576 : 0.0 // Convert to MB/s
|
// Only calculate speeds if we have a reasonable time interval and previous data
|
||||||
let uploadSpeed = timeInterval > 0 ? Double(bytesUploaded) / timeInterval / 1_048_576 : 0.0 // Convert to MB/s
|
if timeInterval > 0.1 && previousNetworkStats.bytesIn > 0 && previousNetworkStats.bytesOut > 0 {
|
||||||
|
let bytesDownloaded = currentNetworkStats.bytesIn > previousNetworkStats.bytesIn ?
|
||||||
|
currentNetworkStats.bytesIn - previousNetworkStats.bytesIn : 0
|
||||||
|
let bytesUploaded = currentNetworkStats.bytesOut > previousNetworkStats.bytesOut ?
|
||||||
|
currentNetworkStats.bytesOut - previousNetworkStats.bytesOut : 0
|
||||||
|
|
||||||
|
downloadSpeed = Double(bytesDownloaded) / timeInterval / 1_048_576 // Convert to MB/s
|
||||||
|
uploadSpeed = Double(bytesUploaded) / timeInterval / 1_048_576 // Convert to MB/s
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate disk speeds
|
// Calculate disk speeds
|
||||||
let currentDiskStats = getDiskStats()
|
let currentDiskStats = getDiskStats()
|
||||||
let bytesRead = currentDiskStats.bytesRead - previousDiskStats.bytesRead
|
var readSpeed: Double = 0.0
|
||||||
let bytesWritten = currentDiskStats.bytesWritten - previousDiskStats.bytesWritten
|
var writeSpeed: Double = 0.0
|
||||||
|
|
||||||
let readSpeed = timeInterval > 0 ? Double(bytesRead) / timeInterval / 1_048_576 : 0.0 // Convert to MB/s
|
// Only calculate speeds if we have a reasonable time interval and previous data
|
||||||
let writeSpeed = timeInterval > 0 ? Double(bytesWritten) / timeInterval / 1_048_576 : 0.0 // Convert to MB/s
|
if timeInterval > 0.1 && previousDiskStats.bytesRead > 0 && previousDiskStats.bytesWritten > 0 {
|
||||||
|
let bytesRead = currentDiskStats.bytesRead > previousDiskStats.bytesRead ?
|
||||||
|
currentDiskStats.bytesRead - previousDiskStats.bytesRead : 0
|
||||||
|
let bytesWritten = currentDiskStats.bytesWritten > previousDiskStats.bytesWritten ?
|
||||||
|
currentDiskStats.bytesWritten - previousDiskStats.bytesWritten : 0
|
||||||
|
|
||||||
|
readSpeed = Double(bytesRead) / timeInterval / 1_048_576 // Convert to MB/s
|
||||||
|
writeSpeed = Double(bytesWritten) / timeInterval / 1_048_576 // Convert to MB/s
|
||||||
|
}
|
||||||
|
|
||||||
// Update current values
|
// Update current values
|
||||||
cpuUsage = newCpuUsage
|
cpuUsage = newCpuUsage
|
||||||
|
|
@ -136,8 +161,8 @@ class StatsManager: ObservableObject {
|
||||||
updateHistory(value: newCpuUsage, history: &cpuHistory)
|
updateHistory(value: newCpuUsage, history: &cpuHistory)
|
||||||
updateHistory(value: newMemoryUsage, history: &memoryHistory)
|
updateHistory(value: newMemoryUsage, history: &memoryHistory)
|
||||||
updateHistory(value: newGpuUsage, history: &gpuHistory)
|
updateHistory(value: newGpuUsage, history: &gpuHistory)
|
||||||
updateHistory(value: networkDownload, history: &networkDownloadHistory)
|
updateHistory(value: downloadSpeed, history: &networkDownloadHistory)
|
||||||
updateHistory(value: networkUpload, history: &networkUploadHistory)
|
updateHistory(value: uploadSpeed, history: &networkUploadHistory)
|
||||||
updateHistory(value: readSpeed, history: &diskReadHistory)
|
updateHistory(value: readSpeed, history: &diskReadHistory)
|
||||||
updateHistory(value: writeSpeed, history: &diskWriteHistory)
|
updateHistory(value: writeSpeed, history: &diskWriteHistory)
|
||||||
|
|
||||||
|
|
@ -243,14 +268,22 @@ class StatsManager: ObservableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
let name = String(cString: interface.ifa_name)
|
let name = String(cString: interface.ifa_name)
|
||||||
// Skip loopback and non-active interfaces
|
// Skip loopback and virtual interfaces, but include en0, en1, etc. and Wi-Fi interfaces
|
||||||
guard !name.hasPrefix("lo") && !name.hasPrefix("gif") && !name.hasPrefix("stf") else {
|
guard !name.hasPrefix("lo") &&
|
||||||
|
!name.hasPrefix("gif") &&
|
||||||
|
!name.hasPrefix("stf") &&
|
||||||
|
!name.hasPrefix("bridge") &&
|
||||||
|
!name.hasPrefix("utun") &&
|
||||||
|
!name.hasPrefix("awdl") else {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if let data = interface.ifa_data?.assumingMemoryBound(to: if_data.self) {
|
// Only count active interfaces (en0, en1, etc.)
|
||||||
totalBytesIn += UInt64(data.pointee.ifi_ibytes)
|
if name.hasPrefix("en") || name.contains("Wi-Fi") {
|
||||||
totalBytesOut += UInt64(data.pointee.ifi_obytes)
|
if let data = interface.ifa_data?.assumingMemoryBound(to: if_data.self) {
|
||||||
|
totalBytesIn += UInt64(data.pointee.ifi_ibytes)
|
||||||
|
totalBytesOut += UInt64(data.pointee.ifi_obytes)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue