Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
493e80e9fe | ||
|
|
e7387a3ac4 |
@@ -11,5 +11,15 @@ struct MacMonitorApp: App {
|
|||||||
.windowStyle(.titleBar)
|
.windowStyle(.titleBar)
|
||||||
.windowToolbarStyle(.unified)
|
.windowToolbarStyle(.unified)
|
||||||
.defaultSize(width: 960, height: 640)
|
.defaultSize(width: 960, height: 640)
|
||||||
|
|
||||||
|
MenuBarExtra {
|
||||||
|
QuickGlancePopoverView(store: store)
|
||||||
|
} label: {
|
||||||
|
MenuBarStatusView(
|
||||||
|
cpuLoad: store.cpuLoad.totalLoad,
|
||||||
|
memoryPercent: store.memory.utilizationPercentage
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.menuBarExtraStyle(.window)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -252,6 +252,13 @@ public final class SystemTelemetryStore {
|
|||||||
public private(set) var batteryHealth = BatteryHealthMetrics()
|
public private(set) var batteryHealth = BatteryHealthMetrics()
|
||||||
public private(set) var peripherals: [PeripheralDeviceItem] = []
|
public private(set) var peripherals: [PeripheralDeviceItem] = []
|
||||||
public private(set) var audioDevices: [AudioDeviceItem] = []
|
public private(set) var audioDevices: [AudioDeviceItem] = []
|
||||||
|
public private(set) var displays: [MMDisplayInfo] = []
|
||||||
|
|
||||||
|
/// Historical Telemetry Store
|
||||||
|
public let historyStore = TelemetryHistoryStore.shared
|
||||||
|
|
||||||
|
/// Display Manager helper
|
||||||
|
public let displayManager = MMDisplayManager.shared()
|
||||||
|
|
||||||
/// Process detail inspection helper
|
/// Process detail inspection helper
|
||||||
public let processInspector = MMProcessDetailInspector()
|
public let processInspector = MMProcessDetailInspector()
|
||||||
@@ -653,6 +660,28 @@ public final class SystemTelemetryStore {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 18. Display Hardware
|
||||||
|
self.displays = self.displayManager.activeDisplays()
|
||||||
|
|
||||||
|
// 19. Record to Historical Ring Buffers
|
||||||
|
let totalDownBps = self.networkBandwidth.reduce(0.0) { $0 + $1.downloadBps }
|
||||||
|
let totalUpBps = self.networkBandwidth.reduce(0.0) { $0 + $1.uploadBps }
|
||||||
|
let totalDiskReadBps = self.diskIO.reduce(0.0) { $0 + $1.readBps }
|
||||||
|
let totalDiskWriteBps = self.diskIO.reduce(0.0) { $0 + $1.writeBps }
|
||||||
|
|
||||||
|
let snapshotRecord = TelemetrySnapshotRecord(
|
||||||
|
cpuLoad: self.cpuLoad.totalLoad,
|
||||||
|
memoryUsedPercent: self.memory.utilizationPercentage,
|
||||||
|
networkInBps: totalDownBps,
|
||||||
|
networkOutBps: totalUpBps,
|
||||||
|
diskReadBps: totalDiskReadBps,
|
||||||
|
diskWriteBps: totalDiskWriteBps,
|
||||||
|
cpuTemp: self.cpuThermal.packageTemperature,
|
||||||
|
systemPowerWatts: self.power.systemTotalWatts,
|
||||||
|
timestamp: self.lastUpdateTimestamp
|
||||||
|
)
|
||||||
|
self.historyStore.record(snapshot: snapshotRecord)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func terminateProcess(pid: pid_t, force: Bool) -> Bool {
|
public func terminateProcess(pid: pid_t, force: Bool) -> Bool {
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ public struct ContentView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Section("Hardware & Devices") {
|
Section("Hardware & Devices") {
|
||||||
|
Label("Displays & Brightness", systemImage: "sun.max")
|
||||||
|
.tag("Displays")
|
||||||
Label("Process Explorer", systemImage: "list.bullet.rectangle")
|
Label("Process Explorer", systemImage: "list.bullet.rectangle")
|
||||||
.tag("Processes")
|
.tag("Processes")
|
||||||
Label("Graphics (GPU)", systemImage: "display")
|
Label("Graphics (GPU)", systemImage: "display")
|
||||||
@@ -70,6 +72,8 @@ public struct ContentView: View {
|
|||||||
.tag("Peripherals")
|
.tag("Peripherals")
|
||||||
Label("Audio Devices", systemImage: "speaker.wave.3.fill")
|
Label("Audio Devices", systemImage: "speaker.wave.3.fill")
|
||||||
.tag("Audio")
|
.tag("Audio")
|
||||||
|
Label("Historical Trends", systemImage: "chart.line.uptrend.xyaxis")
|
||||||
|
.tag("Trends")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.listStyle(.sidebar)
|
.listStyle(.sidebar)
|
||||||
@@ -119,8 +123,12 @@ public struct ContentView: View {
|
|||||||
powerCard
|
powerCard
|
||||||
case "Peripherals":
|
case "Peripherals":
|
||||||
peripheralsCard
|
peripheralsCard
|
||||||
|
case "Displays":
|
||||||
|
displaysCard
|
||||||
case "Audio":
|
case "Audio":
|
||||||
audioDevicesCard
|
audioDevicesCard
|
||||||
|
case "Trends":
|
||||||
|
historicalTrendsView
|
||||||
default:
|
default:
|
||||||
dashboardView
|
dashboardView
|
||||||
}
|
}
|
||||||
@@ -153,6 +161,7 @@ public struct ContentView: View {
|
|||||||
gpuTelemetryCard
|
gpuTelemetryCard
|
||||||
batteryHealthCard
|
batteryHealthCard
|
||||||
}
|
}
|
||||||
|
displaysCard
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -990,6 +999,146 @@ public struct ContentView: View {
|
|||||||
.overlay(RoundedRectangle(cornerRadius: 12).stroke(.separator, lineWidth: 1))
|
.overlay(RoundedRectangle(cornerRadius: 12).stroke(.separator, lineWidth: 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Displays Card
|
||||||
|
private var displaysCard: some View {
|
||||||
|
VStack(alignment: .leading, spacing: 14) {
|
||||||
|
HStack {
|
||||||
|
Label("Connected Displays & Brightness", systemImage: "sun.max")
|
||||||
|
.font(.headline)
|
||||||
|
Spacer()
|
||||||
|
Text("\(store.displays.count) Display\(store.displays.count == 1 ? "" : "s")")
|
||||||
|
.font(.caption.bold())
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
|
||||||
|
if store.displays.isEmpty {
|
||||||
|
Text("No active displays detected.")
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
} else {
|
||||||
|
ForEach(store.displays, id: \.displayID) { display in
|
||||||
|
VStack(alignment: .leading, spacing: 8) {
|
||||||
|
HStack {
|
||||||
|
Image(systemName: display.isBuiltin ? "laptopcomputer" : "display")
|
||||||
|
.foregroundStyle(.blue)
|
||||||
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
|
HStack {
|
||||||
|
Text(display.name)
|
||||||
|
.font(.subheadline.bold())
|
||||||
|
if display.isMain {
|
||||||
|
Text("MAIN")
|
||||||
|
.font(.caption2.bold())
|
||||||
|
.padding(.horizontal, 6)
|
||||||
|
.padding(.vertical, 2)
|
||||||
|
.background(Color.blue.opacity(0.15), in: Capsule())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Text("\(display.width) × \(display.height) @ \(Int(display.refreshRate))Hz")
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
|
if display.brightness >= 0 {
|
||||||
|
Text("\(Int(display.brightness * 100))%")
|
||||||
|
.font(.subheadline.bold().monospacedDigit())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if display.brightness >= 0 {
|
||||||
|
Slider(
|
||||||
|
value: Binding(
|
||||||
|
get: { Double(display.brightness) },
|
||||||
|
set: { newBrightness in
|
||||||
|
_ = store.displayManager.setBrightness(Float(newBrightness), forDisplay: display.displayID)
|
||||||
|
store.triggerManualSample()
|
||||||
|
}
|
||||||
|
),
|
||||||
|
in: 0.0...1.0
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Text("Hardware brightness control not supported for this monitor.")
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(12)
|
||||||
|
.background(.quaternary.opacity(0.5), in: RoundedRectangle(cornerRadius: 8))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(16)
|
||||||
|
.background(.background, in: RoundedRectangle(cornerRadius: 12))
|
||||||
|
.overlay(RoundedRectangle(cornerRadius: 12).stroke(.separator, lineWidth: 1))
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Historical Trends View
|
||||||
|
private var historicalTrendsView: some View {
|
||||||
|
VStack(alignment: .leading, spacing: 16) {
|
||||||
|
TelemetryTrendChartView(
|
||||||
|
title: "CPU Utilization History",
|
||||||
|
unit: "%",
|
||||||
|
color: .blue,
|
||||||
|
samples: store.historyStore.cpuHistory.samples,
|
||||||
|
maxY: 100.0
|
||||||
|
)
|
||||||
|
|
||||||
|
TelemetryTrendChartView(
|
||||||
|
title: "Memory Utilization History",
|
||||||
|
unit: "%",
|
||||||
|
color: .purple,
|
||||||
|
samples: store.historyStore.memoryHistory.samples,
|
||||||
|
maxY: 100.0
|
||||||
|
)
|
||||||
|
|
||||||
|
TelemetryTrendChartView(
|
||||||
|
title: "CPU Temperature History",
|
||||||
|
unit: "°C",
|
||||||
|
color: .orange,
|
||||||
|
samples: store.historyStore.cpuTempHistory.samples,
|
||||||
|
maxY: 110.0
|
||||||
|
)
|
||||||
|
|
||||||
|
TelemetryTrendChartView(
|
||||||
|
title: "System Power Draw History",
|
||||||
|
unit: "W",
|
||||||
|
color: .yellow,
|
||||||
|
samples: store.historyStore.powerHistory.samples
|
||||||
|
)
|
||||||
|
|
||||||
|
HStack(spacing: 16) {
|
||||||
|
TelemetryTrendChartView(
|
||||||
|
title: "Network Download Rate",
|
||||||
|
unit: "B/s",
|
||||||
|
color: .green,
|
||||||
|
samples: store.historyStore.networkInHistory.samples
|
||||||
|
)
|
||||||
|
|
||||||
|
TelemetryTrendChartView(
|
||||||
|
title: "Network Upload Rate",
|
||||||
|
unit: "B/s",
|
||||||
|
color: .teal,
|
||||||
|
samples: store.historyStore.networkOutHistory.samples
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
HStack(spacing: 16) {
|
||||||
|
TelemetryTrendChartView(
|
||||||
|
title: "Disk Read Throughput",
|
||||||
|
unit: "B/s",
|
||||||
|
color: .indigo,
|
||||||
|
samples: store.historyStore.diskReadHistory.samples
|
||||||
|
)
|
||||||
|
|
||||||
|
TelemetryTrendChartView(
|
||||||
|
title: "Disk Write Throughput",
|
||||||
|
unit: "B/s",
|
||||||
|
color: .pink,
|
||||||
|
samples: store.historyStore.diskWriteHistory.samples
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Formatting Helpers
|
// MARK: - Formatting Helpers
|
||||||
private func formatBytes(_ bytes: UInt64) -> String {
|
private func formatBytes(_ bytes: UInt64) -> String {
|
||||||
let formatter = ByteCountFormatter()
|
let formatter = ByteCountFormatter()
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
public struct MenuBarStatusView: View {
|
||||||
|
public let cpuLoad: Double
|
||||||
|
public let memoryPercent: Double
|
||||||
|
|
||||||
|
public init(cpuLoad: Double, memoryPercent: Double) {
|
||||||
|
self.cpuLoad = cpuLoad
|
||||||
|
self.memoryPercent = memoryPercent
|
||||||
|
}
|
||||||
|
|
||||||
|
public var body: some View {
|
||||||
|
HStack(spacing: 5) {
|
||||||
|
Image(systemName: "cpu")
|
||||||
|
.font(.system(size: 11))
|
||||||
|
Text(String(format: "%.0f%%", cpuLoad))
|
||||||
|
.font(.system(size: 11, weight: .medium, design: .monospaced))
|
||||||
|
|
||||||
|
Text("•")
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
|
||||||
|
Image(systemName: "memorychip")
|
||||||
|
.font(.system(size: 11))
|
||||||
|
Text(String(format: "%.0f%%", memoryPercent))
|
||||||
|
.font(.system(size: 11, weight: .medium, design: .monospaced))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
public struct QuickGlancePopoverView: View {
|
||||||
|
var store: SystemTelemetryStore
|
||||||
|
|
||||||
|
public init(store: SystemTelemetryStore) {
|
||||||
|
self.store = store
|
||||||
|
}
|
||||||
|
|
||||||
|
public var body: some View {
|
||||||
|
VStack(alignment: .leading, spacing: 14) {
|
||||||
|
// Header
|
||||||
|
HStack {
|
||||||
|
Label("MacMonitor", systemImage: "macmini")
|
||||||
|
.font(.headline)
|
||||||
|
Spacer()
|
||||||
|
Button {
|
||||||
|
NSApp.activate(ignoringOtherApps: true)
|
||||||
|
if let window = NSApp.windows.first(where: { $0.canBecomeMain }) {
|
||||||
|
window.makeKeyAndOrderFront(nil)
|
||||||
|
}
|
||||||
|
} label: {
|
||||||
|
Image(systemName: "arrow.up.right.square")
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
.help("Open Main Window")
|
||||||
|
}
|
||||||
|
|
||||||
|
Divider()
|
||||||
|
|
||||||
|
// Core Metrics Grid
|
||||||
|
VStack(spacing: 8) {
|
||||||
|
glanceRow(
|
||||||
|
icon: "cpu",
|
||||||
|
title: "CPU Activity",
|
||||||
|
value: String(format: "%.1f%%", store.cpuLoad.totalLoad),
|
||||||
|
subtitle: "\(store.logicalCpuCount) Cores"
|
||||||
|
)
|
||||||
|
|
||||||
|
glanceRow(
|
||||||
|
icon: "memorychip",
|
||||||
|
title: "Memory",
|
||||||
|
value: String(format: "%.1f%%", store.memory.utilizationPercentage),
|
||||||
|
subtitle: "\(formatBytes(store.memory.usedBytes)) / \(formatBytes(store.memory.totalBytes))"
|
||||||
|
)
|
||||||
|
|
||||||
|
glanceRow(
|
||||||
|
icon: "thermometer.medium",
|
||||||
|
title: "Thermals",
|
||||||
|
value: String(format: "%.1f°C", store.cpuThermal.packageTemperature),
|
||||||
|
subtitle: "Fans: \(store.fans.map { "\(Int($0.currentRPM)) RPM" }.joined(separator: ", "))"
|
||||||
|
)
|
||||||
|
|
||||||
|
glanceRow(
|
||||||
|
icon: "bolt.fill",
|
||||||
|
title: "Power",
|
||||||
|
value: String(format: "%.1f W", store.power.systemTotalWatts),
|
||||||
|
subtitle: store.batteryHealth.isCharging ? "Charging (\(Int(store.batteryHealth.healthPercent))%)" : "Battery (\(Int(store.batteryHealth.healthPercent))%)"
|
||||||
|
)
|
||||||
|
|
||||||
|
glanceRow(
|
||||||
|
icon: "network",
|
||||||
|
title: "Network",
|
||||||
|
value: "↓ \(formatBps(totalDownloadBps)) / ↑ \(formatBps(totalUploadBps))",
|
||||||
|
subtitle: "\(store.networkBandwidth.count) active interfaces"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Divider()
|
||||||
|
|
||||||
|
// Footer action
|
||||||
|
HStack {
|
||||||
|
Text("Last updated: \(store.lastUpdateTimestamp.formatted(date: .omitted, time: .standard))")
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
Spacer()
|
||||||
|
Button("Quit") {
|
||||||
|
NSApplication.shared.terminate(nil)
|
||||||
|
}
|
||||||
|
.font(.caption)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(14)
|
||||||
|
.frame(width: 320)
|
||||||
|
}
|
||||||
|
|
||||||
|
private var totalDownloadBps: Double {
|
||||||
|
store.networkBandwidth.reduce(0.0) { $0 + $1.downloadBps }
|
||||||
|
}
|
||||||
|
|
||||||
|
private var totalUploadBps: Double {
|
||||||
|
store.networkBandwidth.reduce(0.0) { $0 + $1.uploadBps }
|
||||||
|
}
|
||||||
|
|
||||||
|
private func glanceRow(icon: String, title: String, value: String, subtitle: String) -> some View {
|
||||||
|
HStack {
|
||||||
|
Image(systemName: icon)
|
||||||
|
.frame(width: 18)
|
||||||
|
.foregroundColor(.accentColor)
|
||||||
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
|
Text(title)
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
Text(subtitle)
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
.lineLimit(1)
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
|
Text(value)
|
||||||
|
.font(.subheadline)
|
||||||
|
.fontWeight(.semibold)
|
||||||
|
.fontDesign(.monospaced)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func formatBytes(_ bytes: UInt64) -> String {
|
||||||
|
let formatter = ByteCountFormatter()
|
||||||
|
formatter.allowedUnits = [.useAll]
|
||||||
|
formatter.countStyle = .memory
|
||||||
|
return formatter.string(fromByteCount: Int64(bytes))
|
||||||
|
}
|
||||||
|
|
||||||
|
private func formatBps(_ bps: Double) -> String {
|
||||||
|
if bps < 1024 {
|
||||||
|
return String(format: "%.0f B/s", bps)
|
||||||
|
} else if bps < 1024 * 1024 {
|
||||||
|
return String(format: "%.1f KB/s", bps / 1024)
|
||||||
|
} else {
|
||||||
|
return String(format: "%.2f MB/s", bps / (1024 * 1024))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import XCTest
|
||||||
|
import SwiftUI
|
||||||
|
@testable import MacMonitor
|
||||||
|
|
||||||
|
final class MMMenuBarTests: XCTestCase {
|
||||||
|
|
||||||
|
func testMenuBarStatusViewInitialization() {
|
||||||
|
let view = MenuBarStatusView(cpuLoad: 24.5, memoryPercent: 55.0)
|
||||||
|
XCTAssertEqual(view.cpuLoad, 24.5)
|
||||||
|
XCTAssertEqual(view.memoryPercent, 55.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testQuickGlancePopoverViewInitialization() {
|
||||||
|
let store = SystemTelemetryStore.shared
|
||||||
|
let view = QuickGlancePopoverView(store: store)
|
||||||
|
XCTAssertNotNil(view)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user