Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .codex/environments/environment.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# THIS IS AUTOGENERATED. DO NOT EDIT MANUALLY
version = 1
name = "Core-Monitor"

[setup]
script = ""

[[actions]]
name = "Run"
icon = "run"
command = "./script/build_and_run.sh"
4 changes: 4 additions & 0 deletions Core-Monitor.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
7381A6E82B87236C00C0DE01 /* CustomFanPresetTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7381A6E72B87236C00C0DE01 /* CustomFanPresetTests.swift */; };
DABD00032F95000100000003 /* DashboardProcessSamplingPolicyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DABD00012F95000100000001 /* DashboardProcessSamplingPolicyTests.swift */; };
DABD00042F95000100000004 /* HardwareRescueDiagnosticsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DABD00022F95000100000002 /* HardwareRescueDiagnosticsTests.swift */; };
DABD10022F96000100000002 /* CoreMonitorShareKitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DABD10012F96000100000001 /* CoreMonitorShareKitTests.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -51,6 +52,7 @@
8D6F3C76B69FEDB140682676 /* AlertEngineTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = AlertEngineTests.swift; sourceTree = "<group>"; };
DABD00012F95000100000001 /* DashboardProcessSamplingPolicyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardProcessSamplingPolicyTests.swift; sourceTree = "<group>"; };
DABD00022F95000100000002 /* HardwareRescueDiagnosticsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HardwareRescueDiagnosticsTests.swift; sourceTree = "<group>"; };
DABD10012F96000100000001 /* CoreMonitorShareKitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreMonitorShareKitTests.swift; sourceTree = "<group>"; };
E5B12BED2CCB8BBEC03C227F /* Core-MonitorTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Core-MonitorTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -98,6 +100,7 @@
children = (
8D6F3C76B69FEDB140682676 /* AlertEngineTests.swift */,
7381A6E72B87236C00C0DE01 /* CustomFanPresetTests.swift */,
DABD10012F96000100000001 /* CoreMonitorShareKitTests.swift */,
DABD00012F95000100000001 /* DashboardProcessSamplingPolicyTests.swift */,
DABD00022F95000100000002 /* HardwareRescueDiagnosticsTests.swift */,
);
Expand Down Expand Up @@ -304,6 +307,7 @@
files = (
23F2064CB38FDB73EE4AB471 /* AlertEngineTests.swift in Sources */,
7381A6E82B87236C00C0DE01 /* CustomFanPresetTests.swift in Sources */,
DABD10022F96000100000002 /* CoreMonitorShareKitTests.swift in Sources */,
DABD00032F95000100000003 /* DashboardProcessSamplingPolicyTests.swift in Sources */,
DABD00042F95000100000004 /* HardwareRescueDiagnosticsTests.swift in Sources */,
);
Expand Down
62 changes: 61 additions & 1 deletion Core-Monitor/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private struct NativeDashboardDetail: View {
case .help:
NativeHelpPage()
case .about:
NativeAboutPage()
NativeAboutPage(systemMonitor: systemMonitor, fanController: fanController)
}
}
}
Expand Down Expand Up @@ -901,7 +901,10 @@ private struct NativeHelpPage: View {
}

private struct NativeAboutPage: View {
@ObservedObject var systemMonitor: SystemMonitor
@ObservedObject var fanController: FanController
@AppStorage(AppLocaleStore.localeOverrideKey) private var localeOverrideIdentifier = AppLocaleStore.systemLocaleValue
@State private var shareStatusMessage: String?

var body: some View {
NativeSettingsSection("Core Monitor") {
Expand All @@ -924,6 +927,57 @@ private struct NativeAboutPage: View {
NativeValueRow("Model Identifier", value: SystemMonitor.hostModelIdentifier())
}

NativeSettingsSection("Share") {
HStack(spacing: 10) {
Button {
copyToClipboard(CoreMonitorShareKit.productPitch(), message: "Pitch copied")
} label: {
Label("Copy Pitch", systemImage: "text.quote")
}

Button {
copyToClipboard(CoreMonitorShareKit.launchPost(), message: "Launch post copied")
} label: {
Label("Copy Post", systemImage: "megaphone")
}

Button {
let snapshot = CoreMonitorShareKit.makeSupportSnapshot(
systemMonitor: systemMonitor,
fanController: fanController
)
copyToClipboard(snapshot, message: "Snapshot copied")
} label: {
Label("Copy Snapshot", systemImage: "doc.on.doc")
}
}

HStack(spacing: 10) {
Button {
NSWorkspace.shared.open(CoreMonitorShareKit.websiteURL)
} label: {
Label("Website", systemImage: "safari")
}

Button {
NSWorkspace.shared.open(CoreMonitorShareKit.latestReleaseURL)
} label: {
Label("Latest Release", systemImage: "arrow.down.circle")
}

Button {
NSWorkspace.shared.open(CoreMonitorShareKit.repositoryURL)
} label: {
Label("GitHub", systemImage: "chevron.left.forwardslash.chevron.right")
}
}

if let shareStatusMessage {
NativeDivider()
NativeValueRow("Clipboard", value: shareStatusMessage)
}
}

NativeSettingsSection("Language") {
Picker("Language", selection: $localeOverrideIdentifier) {
Text("System Default").tag(AppLocaleStore.systemLocaleValue)
Expand All @@ -943,6 +997,12 @@ private struct NativeAboutPage: View {
}
}
}

private func copyToClipboard(_ text: String, message: String) {
NSPasteboard.general.clearContents()
NSPasteboard.general.setString(text, forType: .string)
shareStatusMessage = message
}
}

private struct NativeSettingsSection<Content: View>: View {
Expand Down
220 changes: 220 additions & 0 deletions Core-Monitor/CoreMonitorShareKit.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
import Foundation

struct CoreMonitorShareSnapshotContext: Equatable {
let generatedAt: Date
let appVersion: String
let macOSVersion: String
let hostModelIdentifier: String
let hostModelName: String
let chipName: String
let cpuUsagePercent: Double
let performanceCoreUsagePercent: Double?
let efficiencyCoreUsagePercent: Double?
let memoryUsagePercent: Double
let memoryUsedGB: Double
let totalMemoryGB: Double
let cpuTemperature: Double?
let gpuTemperature: Double?
let ssdTemperature: Double?
let fanSpeeds: [Int]
let fanModeTitle: String
let helperStateTitle: String
let helperInstalled: Bool
let batteryChargePercent: Int?
let batteryPowerWatts: Double?
let totalSystemWatts: Double?
let thermalStateTitle: String
let hasSMCAccess: Bool
let smcError: String?
}

enum CoreMonitorShareKit {
static let websiteURL = URL(string: "https://offyotto.github.io/Core-Monitor/")!
static let repositoryURL = URL(string: "https://github.com/offyotto/Core-Monitor")!
static let latestReleaseURL = URL(string: "https://github.com/offyotto/Core-Monitor/releases/latest")!
static let appStoreURL = URL(string: "https://apps.apple.com/us/app/core-monitor/id6762558526?mt=12")!

static func productPitch() -> String {
"""
Core-Monitor is a free, open-source Apple Silicon system monitor and optional fan-control app for macOS.

It tracks thermals, power, battery, CPU, GPU, memory, menu bar status, alerts, Touch Bar widgets, and helper-backed fan control locally on your Mac. Monitoring works without elevated access; the helper is only needed for fan writes.

Website: \(websiteURL.absoluteString)
Download: \(latestReleaseURL.absoluteString)
Mac App Store edition: \(appStoreURL.absoluteString)
Source: \(repositoryURL.absoluteString)
"""
}

static func launchPost() -> String {
"""
Core-Monitor is a free, open-source Apple Silicon monitor for macOS: thermals, watts, battery, fans, menu bar status, alerts, Touch Bar widgets, and optional fan control with no account or telemetry.

Download: \(latestReleaseURL.absoluteString)
Source: \(repositoryURL.absoluteString)
"""
}

@MainActor
static func makeSupportSnapshot(
systemMonitor: SystemMonitor,
fanController: FanController,
helperManager: SMCHelperManager = .shared,
generatedAt: Date = Date()
) -> String {
let snapshot = systemMonitor.snapshot
let modelIdentifier = SystemMonitor.hostModelIdentifier()
let context = CoreMonitorShareSnapshotContext(
generatedAt: generatedAt,
appVersion: AppVersion.current,
macOSVersion: ProcessInfo.processInfo.operatingSystemVersionString,
hostModelIdentifier: modelIdentifier,
hostModelName: MacModelRegistry.displayName(for: modelIdentifier),
chipName: SystemMonitor.chipName(),
cpuUsagePercent: snapshot.cpuUsagePercent,
performanceCoreUsagePercent: snapshot.performanceCoreUsagePercent,
efficiencyCoreUsagePercent: snapshot.efficiencyCoreUsagePercent,
memoryUsagePercent: snapshot.memoryUsagePercent,
memoryUsedGB: snapshot.memoryUsedGB,
totalMemoryGB: snapshot.totalMemoryGB,
cpuTemperature: snapshot.cpuTemperature,
gpuTemperature: snapshot.gpuTemperature,
ssdTemperature: snapshot.ssdTemperature,
fanSpeeds: snapshot.fanSpeeds,
fanModeTitle: fanModeTitle(fanController.mode),
helperStateTitle: helperStateTitle(helperManager.connectionState),
helperInstalled: helperManager.isInstalled,
batteryChargePercent: snapshot.batteryInfo.chargePercent,
batteryPowerWatts: snapshot.batteryInfo.powerWatts,
totalSystemWatts: snapshot.totalSystemWatts,
thermalStateTitle: thermalStateTitle(snapshot.thermalState),
hasSMCAccess: snapshot.hasSMCAccess,
smcError: snapshot.lastError
)
return supportSnapshotMarkdown(from: context)
}

static func supportSnapshotMarkdown(from context: CoreMonitorShareSnapshotContext) -> String {
var lines: [String] = [
"# Core-Monitor Support Snapshot",
"",
"- Generated: \(iso8601String(context.generatedAt))",
"- App: Core Monitor \(context.appVersion)",
"- macOS: \(context.macOSVersion)",
"- Mac: \(context.hostModelName) (\(context.hostModelIdentifier))",
"- Chip: \(context.chipName)",
"",
"## Monitoring",
"",
"- CPU: \(percentString(context.cpuUsagePercent))"
]

if let performanceCoreUsagePercent = context.performanceCoreUsagePercent {
lines.append("- P-cores: \(percentString(performanceCoreUsagePercent))")
}

if let efficiencyCoreUsagePercent = context.efficiencyCoreUsagePercent {
lines.append("- E-cores: \(percentString(efficiencyCoreUsagePercent))")
}

lines.append("- Memory: \(gbString(context.memoryUsedGB)) of \(gbString(context.totalMemoryGB)) (\(percentString(context.memoryUsagePercent)))")
lines.append("- Thermal pressure: \(context.thermalStateTitle)")
lines.append("- CPU temperature: \(temperatureString(context.cpuTemperature))")
lines.append("- GPU temperature: \(temperatureString(context.gpuTemperature))")
lines.append("- SSD temperature: \(temperatureString(context.ssdTemperature))")
lines.append("- System power: \(wattsString(context.totalSystemWatts))")
lines.append("- Battery: \(batteryString(chargePercent: context.batteryChargePercent, watts: context.batteryPowerWatts))")
lines.append("- Fans: \(fanSpeedsString(context.fanSpeeds))")
lines.append("- SMC access: \(context.hasSMCAccess ? "Available" : "Unavailable")")

if let smcError = context.smcError?.trimmingCharacters(in: .whitespacesAndNewlines), smcError.isEmpty == false {
lines.append("- SMC note: \(smcError)")
}

lines.append(contentsOf: [
"",
"## Cooling",
"",
"- Mode: \(context.fanModeTitle)",
"- Helper: \(context.helperStateTitle) (installed: \(context.helperInstalled ? "yes" : "no"))",
"",
"Core-Monitor: \(websiteURL.absoluteString)",
"Source: \(repositoryURL.absoluteString)"
])

return lines.joined(separator: "\n")
}

private static func iso8601String(_ date: Date) -> String {
let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime]
return formatter.string(from: date)
}

private static func percentString(_ value: Double) -> String {
"\(Int(value.rounded()))%"
}

private static func gbString(_ value: Double) -> String {
guard value > 0 else { return "0 GB" }
if value >= 10 {
return String(format: "%.0f GB", value)
}
return String(format: "%.1f GB", value)
}

private static func temperatureString(_ value: Double?) -> String {
guard let value else { return "Unavailable" }
return "\(Int(value.rounded())) C"
}

private static func wattsString(_ value: Double?) -> String {
guard let value else { return "Unavailable" }
return String(format: "%.1f W", value)
}

private static func batteryString(chargePercent: Int?, watts: Double?) -> String {
let charge = chargePercent.map { "\($0)%" } ?? "Unavailable"
guard let watts else { return charge }
return "\(charge), \(wattsString(watts))"
}

private static func fanSpeedsString(_ fanSpeeds: [Int]) -> String {
guard fanSpeeds.isEmpty == false else { return "Unavailable" }
return fanSpeeds.map { "\($0) RPM" }.joined(separator: ", ")
}

private static func fanModeTitle(_ mode: FanControlMode) -> String {
switch mode {
case .smart: return "Smart"
case .silent: return "System"
case .balanced: return "Balanced"
case .performance: return "Performance"
case .max: return "Maximum"
case .manual: return "Manual"
case .custom: return "Custom"
case .automatic: return "System Automatic"
}
}

private static func helperStateTitle(_ state: SMCHelperManager.ConnectionState) -> String {
switch state {
case .missing: return "Missing"
case .unknown: return "Unknown"
case .checking: return "Checking"
case .reachable: return "Reachable"
case .unreachable: return "Unavailable"
}
}

private static func thermalStateTitle(_ state: ProcessInfo.ThermalState) -> String {
switch state {
case .nominal: return "Nominal"
case .fair: return "Fair"
case .serious: return "Serious"
case .critical: return "Critical"
@unknown default: return "Unknown"
}
}
}
Loading
Loading