Free, open-source macOS cleaner. CleanMyMac alternative with zero telemetry. Native SwiftUI, scheduled auto-cleaning, Xcode/Homebrew/system cache cleanup. MIT licensed.
Swift cache-cleanercleanmymaccleanupdisk-cleanerdisk-spacehomebrewmac-utilitymacosmacos-appmacos-cleanermacosxnativeossosxprivacyswiftswiftuisystem-cleanerxcode-cleaner
feat: menu-bar system monitor (opt-in CPU/memory/disk meters)
momenbasel373d3dd65f13
diff --git a/PureMac.xcodeproj/project.pbxproj b/PureMac.xcodeproj/project.pbxprojindex 6d51a3e..2132a7b 100644--- a/PureMac.xcodeproj/project.pbxproj+++ b/PureMac.xcodeproj/project.pbxproj@@ -27,10 +27,12 @@826A750D2D7EC14C2AE306A3 /* Models.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3667D46D8E2004EB4D73835A /* Models.swift */; };8947F0CE448791BD50EECF46 /* Conditions.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB94E06E145558123BB5BFB3 /* Conditions.swift */; };8B541441926847072DC5B75B /* DashboardCharts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08C60E04A0CA3F227816DB63 /* DashboardCharts.swift */; };+ 91751CF033E1541BFD39B12C /* MenuBarMonitorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A27DB5A70FA829B6C3ED0AC3 /* MenuBarMonitorView.swift */; };93743B036059418560D876E6 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A8D39C3C250F26302EC45AB /* SettingsView.swift */; };95278ABDCF5F4D6AC60503B1 /* AppearancePill.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92259B3E9F4468865F15DEEC /* AppearancePill.swift */; };9AA80E035DF7B33F6EE118DF /* AppState.swift in Sources */ = {isa = PBXBuildFile; fileRef = CED1B71D5F9510582E869CFD /* AppState.swift */; };9BB5AAA574AFED6C27A3F8E2 /* AppPathFinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC0FEE7141871ED5F9E36121 /* AppPathFinder.swift */; };+ 9E3639F9EFCB2A22F6747894 /* MenuBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 913E3064AA9BD7BE94A315CF /* MenuBarController.swift */; };A2AE68CC75CB72D6B10CBDF5 /* DashboardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F661A0F64CF93E482CB1728F /* DashboardView.swift */; };A549D8A39A9E5E70D91B90A6 /* Haptics.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40A3F22FCEF534DE4A2CAD0E /* Haptics.swift */; };A9C3A1F643C26930F442E729 /* OrphanSafetyPolicy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AE790496C936424EF98320A /* OrphanSafetyPolicy.swift */; };@@ -41,6 +43,7 @@CFA64F54CDBF8A4765E0068D /* LocalizationFilesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 155CE1B8CDCCCA6F9FD028C1 /* LocalizationFilesTests.swift */; };D50EB059E741011EB2523731 /* ScanError.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF15CB1B8EFCA78EF491824 /* ScanError.swift */; };D9445C2641A8637B65DA5ACE /* ScanEngine.swift in Sources */ = {isa = PBXBuildFile; fileRef = A711CDF5285F68775D9B5513 /* ScanEngine.swift */; };+ DBFD73E3D9BDA74EC1CA56AB /* SystemMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB798781B99987F55D77E2E3 /* SystemMonitor.swift */; };DC32253D26D0E29762006DA0 /* AppBundleDragHandle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D3F9FEDC493A8E49E910F67 /* AppBundleDragHandle.swift */; };DDD6BA35DBF32E7A6B5F6F8B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B2EA41E1096FA8E3B916AD13 /* Assets.xcassets */; };DDDA5879006CB97D5D7BDD87 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5785762276FB5E3209C6DE4D /* Logger.swift */; };@@ -100,9 +103,11 @@798B80977D14647A5691B0A0 /* AppFilesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppFilesView.swift; sourceTree = "<group>"; };82BB0904726B38DEB141BECA /* AppLanguage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppLanguage.swift; sourceTree = "<group>"; };8D5E63D733D1A3BDEDF4DCA5 /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/Localizable.strings"; sourceTree = "<group>"; };+ 913E3064AA9BD7BE94A315CF /* MenuBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBarController.swift; sourceTree = "<group>"; };92259B3E9F4468865F15DEEC /* AppearancePill.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppearancePill.swift; sourceTree = "<group>"; };9F04B811BB0012F6D2F07F91 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };9F510F232341EE18F11DC934 /* MainWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainWindow.swift; sourceTree = "<group>"; };+ A27DB5A70FA829B6C3ED0AC3 /* MenuBarMonitorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBarMonitorView.swift; sourceTree = "<group>"; };A711CDF5285F68775D9B5513 /* ScanEngine.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScanEngine.swift; sourceTree = "<group>"; };AC0FEE7141871ED5F9E36121 /* AppPathFinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppPathFinder.swift; sourceTree = "<group>"; };B2CD0028599BE178B96F18A6 /* ar */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ar; path = ar.lproj/Localizable.strings; sourceTree = "<group>"; };@@ -111,6 +116,7 @@C5ADDC35F31E40780FB5D017 /* Theme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Theme.swift; sourceTree = "<group>"; };CB94E06E145558123BB5BFB3 /* Conditions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Conditions.swift; sourceTree = "<group>"; };CED1B71D5F9510582E869CFD /* AppState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppState.swift; sourceTree = "<group>"; };+ DB798781B99987F55D77E2E3 /* SystemMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SystemMonitor.swift; sourceTree = "<group>"; };E866A1541D289C69144A5E62 /* FullDiskAccessManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FullDiskAccessManager.swift; sourceTree = "<group>"; };EEF15CB1B8EFCA78EF491824 /* ScanError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScanError.swift; sourceTree = "<group>"; };F0599AA604B0D6BA4F957537 /* ConfettiView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfettiView.swift; sourceTree = "<group>"; };@@ -190,9 +196,11 @@2A8DE5D45BA19E2670B57DC5 /* CleaningEngine.swift */,E866A1541D289C69144A5E62 /* FullDiskAccessManager.swift */,40A3F22FCEF534DE4A2CAD0E /* Haptics.swift */,+ 913E3064AA9BD7BE94A315CF /* MenuBarController.swift */,F9DCBD97CC88D77AE8DB01A4 /* PermissionCoordinator.swift */,A711CDF5285F68775D9B5513 /* ScanEngine.swift */,28181F034530331A550C6A3D /* SchedulerService.swift */,+ DB798781B99987F55D77E2E3 /* SystemMonitor.swift */,022D0EAEE2B6E54069FC2CBE /* UpdateService.swift */,);path = Services;@@ -224,6 +232,7 @@08C60E04A0CA3F227816DB63 /* DashboardCharts.swift */,424F7B28624C271620E13BBC /* EmptyStateView.swift */,231FF7CBB5F621B66F2AB8A5 /* FDADemoView.swift */,+ A27DB5A70FA829B6C3ED0AC3 /* MenuBarMonitorView.swift */,069AAE87E3F9EDE5593AD8B3 /* PermissionSheet.swift */,);path = Components;@@ -442,6 +451,8 @@E60B0A2C5D0A6CAE35BF4DFB /* Locations.swift in Sources */,DDDA5879006CB97D5D7BDD87 /* Logger.swift in Sources */,CDCDFEBA39A3290101F86AC6 /* MainWindow.swift in Sources */,+ 9E3639F9EFCB2A22F6747894 /* MenuBarController.swift in Sources */,+ 91751CF033E1541BFD39B12C /* MenuBarMonitorView.swift in Sources */,826A750D2D7EC14C2AE306A3 /* Models.swift in Sources */,BC6C800216343438413349A3 /* OnboardingView.swift in Sources */,FDA30FE6349CA01C8D859F04 /* OrphanListView.swift in Sources */,@@ -454,6 +465,7 @@27F449EDD1B082FE11FEC9DF /* SchedulerService.swift in Sources */,93743B036059418560D876E6 /* SettingsView.swift in Sources */,47C5ECD49C4DD75F271DB6CE /* StringNormalization.swift in Sources */,+ DBFD73E3D9BDA74EC1CA56AB /* SystemMonitor.swift in Sources */,340E424F759ACCDE7372F99F /* Theme.swift in Sources */,41B27CACD7C6C7471EFD03F9 /* UpdateService.swift in Sources */,);@@ -537,7 +549,7 @@CODE_SIGN_STYLE = Automatic;COMBINE_HIDPI_IMAGES = YES;COPY_PHASE_STRIP = NO;- CURRENT_PROJECT_VERSION = 17;+ CURRENT_PROJECT_VERSION = 18;DEBUG_INFORMATION_FORMAT = dwarf;DEVELOPMENT_TEAM = H3WXHVTP97;ENABLE_STRICT_OBJC_MSGSEND = YES;@@ -559,7 +571,7 @@GENERATE_INFOPLIST_FILE = NO;INFOPLIST_FILE = PureMac/Info.plist;MACOSX_DEPLOYMENT_TARGET = 13.0;- MARKETING_VERSION = 2.8.2;+ MARKETING_VERSION = 2.8.3;MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;MTL_FAST_MATH = YES;ONLY_ACTIVE_ARCH = NO;@@ -661,7 +673,7 @@CODE_SIGN_STYLE = Automatic;COMBINE_HIDPI_IMAGES = YES;COPY_PHASE_STRIP = NO;- CURRENT_PROJECT_VERSION = 17;+ CURRENT_PROJECT_VERSION = 18;DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";DEVELOPMENT_TEAM = H3WXHVTP97;ENABLE_NS_ASSERTIONS = NO;@@ -677,7 +689,7 @@GENERATE_INFOPLIST_FILE = NO;INFOPLIST_FILE = PureMac/Info.plist;MACOSX_DEPLOYMENT_TARGET = 13.0;- MARKETING_VERSION = 2.8.2;+ MARKETING_VERSION = 2.8.3;MTL_ENABLE_DEBUG_INFO = NO;MTL_FAST_MATH = YES;ONLY_ACTIVE_ARCH = NO;diff --git a/PureMac/PureMacApp.swift b/PureMac/PureMacApp.swiftindex 743ef55..4078a74 100644--- a/PureMac/PureMacApp.swift+++ b/PureMac/PureMacApp.swift@@ -1,11 +1,30 @@import AppKitimport SwiftUI+@MainActorclass AppDelegate: NSObject, NSApplicationDelegate {- func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { true }+ /// Owns the optional menu-bar status item. Nil until the monitor is enabled.+ private var menuBarController: MenuBarController?++ /// Normally PureMac quits when its window closes. When the menu-bar system+ /// monitor is enabled the app stays resident so the meters keep updating in+ /// the menu bar; "Open PureMac" in that menu reopens the window.+ func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {+ !UserDefaults.standard.bool(forKey: "settings.general.menuBarMonitor")+ }func applicationDidFinishLaunching(_ notification: Notification) {NSWindow.allowsAutomaticWindowTabbing = false++ // Install the menu-bar monitor if the user has it enabled. Never under+ // XCTest — the status-item machinery would stall the test-host run loop.+ if NSClassFromString("XCTestCase") == nil {+ syncMenuBarMonitor()+ NotificationCenter.default.addObserver(+ self, selector: #selector(syncMenuBarMonitor),+ name: .pureMacMenuBarMonitorChanged, object: nil+ )+ }// Touch TCC-protected paths so macOS registers PureMac in the// Full Disk Access pane on first launch (fixes issue #75).FullDiskAccessManager.shared.triggerRegistration()@@ -38,6 +57,25 @@ class AppDelegate: NSObject, NSApplicationDelegate {userInfo: ["path": appURL.path])}++ /// Create or tear down the menu-bar status item to match the current+ /// Settings toggle. Posted to whenever the toggle flips so it takes effect+ /// without a relaunch.+ @objc func syncMenuBarMonitor() {+ let enabled = UserDefaults.standard.bool(forKey: "settings.general.menuBarMonitor")+ if enabled, menuBarController == nil {+ menuBarController = MenuBarController()+ } else if !enabled, let controller = menuBarController {+ controller.teardown()+ menuBarController = nil+ }+ }+}++extension Notification.Name {+ /// Posted when the "Show system monitor in menu bar" Settings toggle flips,+ /// so AppDelegate can add/remove the status item live.+ static let pureMacMenuBarMonitorChanged = Notification.Name("PureMac.MenuBarMonitorChanged")}@main@@ -58,7 +96,7 @@ struct PureMacApp: App {}var body: some Scene {- WindowGroup {+ WindowGroup(id: "main") {Group {if onboardingComplete {MainWindow()@@ -70,6 +108,10 @@ struct PureMacApp: App {}.environmentObject(theme).preferredColorScheme(theme.appearance.colorScheme)+ // Record the openWindow action so the menu-bar popover can reopen+ // this window after it's been closed (the popover lives outside the+ // scene graph and can't use openWindow itself).+ .background(WindowOpenerCapture())}.windowStyle(.automatic).windowToolbarStyle(.unified)@@ -89,5 +131,12 @@ struct PureMacApp: App {SettingsView().environmentObject(appState)}++ // The opt-in menu-bar system monitor is an AppKit NSStatusItem managed+ // by AppDelegate/MenuBarController rather than a SwiftUI MenuBarExtra:+ // a conditional `.window`-style MenuBarExtra fails to type-check, and an+ // unconditional one sets up status-item machinery that hangs the XCTest+ // host. The AppKit controller is only created when enabled and never+ // under tests, sidestepping both problems.}}diff --git a/PureMac/Services/MenuBarController.swift b/PureMac/Services/MenuBarController.swiftnew file mode 100644index 0000000..e5afcbb--- /dev/null+++ b/PureMac/Services/MenuBarController.swift@@ -0,0 +1,88 @@+import AppKit+import SwiftUI+import Combine++/// Captures SwiftUI's `openWindow` action so AppKit surfaces (the menu-bar+/// popover, which lives outside the scene graph and has no working `openWindow`+/// environment) can reopen the main window after it has been closed. The main+/// window records the action on appear; the closure stays valid for the app's+/// lifetime even once the window is gone.+@MainActor+final class WindowOpener {+ static let shared = WindowOpener()+ var open: ((String) -> Void)?+ private init() {}+}++/// AppKit-backed menu-bar system monitor. A SwiftUI `MenuBarExtra` was avoided+/// here: a conditional `.window`-style `MenuBarExtra` fails to type-check, and+/// an unconditional one stalls the XCTest host's run loop. An `NSStatusItem`+/// driving an `NSPopover` (which hosts the existing SwiftUI `MenuBarMonitorView`)+/// gives the same UI with full create/destroy control and no test-host impact.+@MainActor+final class MenuBarController: NSObject, NSPopoverDelegate {+ private let statusItem: NSStatusItem+ private let popover = NSPopover()+ private let monitor = SystemMonitor.shared+ private var cancellable: AnyCancellable?++ override init() {+ statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)+ super.init()++ // Persist the user's show/hide choice and ensure the item is requested+ // visible (it defaults hidden when restored from a prior autosave state).+ statusItem.autosaveName = "PureMacSystemMonitor"+ statusItem.isVisible = true++ monitor.start()++ if let button = statusItem.button {+ button.image = NSImage(+ systemSymbolName: "gauge.with.dots.needle.67percent",+ accessibilityDescription: "System Monitor"+ )+ button.imagePosition = .imageLeading+ button.target = self+ button.action = #selector(togglePopover)+ updateTitle()+ }++ popover.behavior = .transient+ popover.contentSize = NSSize(width: 248, height: 230)+ popover.contentViewController = NSHostingController(rootView: MenuBarMonitorView())+ popover.delegate = self++ // Refresh the menu-bar CPU readout each time the monitor samples.+ cancellable = monitor.$cpuUsage+ .receive(on: RunLoop.main)+ .sink { [weak self] _ in self?.updateTitle() }+ }++ /// Remove the status item and release the monitor observer. Called by+ /// AppDelegate before dropping the controller so teardown runs on the main+ /// actor (a `@MainActor` deinit cannot touch isolated state safely).+ func teardown() {+ cancellable?.cancel()+ cancellable = nil+ if popover.isShown { popover.performClose(nil) }+ NSStatusBar.system.removeStatusItem(statusItem)+ monitor.stop()+ }++ private func updateTitle() {+ guard let button = statusItem.button else { return }+ button.title = " \(Int((monitor.cpuUsage * 100).rounded()))%"+ }++ @objc private func togglePopover() {+ guard let button = statusItem.button else { return }+ if popover.isShown {+ popover.performClose(nil)+ } else {+ NSApp.activate(ignoringOtherApps: true)+ popover.show(relativeTo: button.bounds, of: button, preferredEdge: .minY)+ popover.contentViewController?.view.window?.makeKey()+ }+ }+}diff --git a/PureMac/Services/SystemMonitor.swift b/PureMac/Services/SystemMonitor.swiftnew file mode 100644index 0000000..82810cf--- /dev/null+++ b/PureMac/Services/SystemMonitor.swift@@ -0,0 +1,144 @@+import Foundation+import Darwin++/// Lightweight live system telemetry for the menu-bar monitor (CPU / memory /+/// disk). Polls on a timer only while a SwiftUI view is observing it; the menu+/// bar's `MenuBarExtra` keeps a single shared instance alive, and `start()` /+/// `stop()` gate the timer so the app does no background sampling when the+/// monitor is disabled in Settings.+///+/// All readings use public Mach / Foundation APIs (no sandbox-incompatible+/// shelling out), so this stays valid under the app's hardened-runtime,+/// notarized build.+@MainActor+final class SystemMonitor: ObservableObject {+ static let shared = SystemMonitor()++ /// 0.0 - 1.0 fraction of total CPU time spent non-idle since the last sample.+ @Published private(set) var cpuUsage: Double = 0+ @Published private(set) var memoryUsed: Int64 = 0+ @Published private(set) var memoryTotal: Int64 = 0+ @Published private(set) var diskUsed: Int64 = 0+ @Published private(set) var diskTotal: Int64 = 0++ var memoryFraction: Double {+ guard memoryTotal > 0 else { return 0 }+ return Double(memoryUsed) / Double(memoryTotal)+ }++ var diskFraction: Double {+ guard diskTotal > 0 else { return 0 }+ return Double(diskUsed) / Double(diskTotal)+ }++ private var timer: Timer?+ /// Previous CPU tick counters, kept to turn the kernel's monotonically+ /// increasing totals into a per-interval delta.+ private var previousBusy: UInt64 = 0+ private var previousTotal: UInt64 = 0+ /// Number of live observers; the timer runs only while > 0 so two views+ /// (menu-bar label + dropdown) share one timer and the app idles cleanly.+ private var observerCount = 0++ private init() {}++ /// Begin (or keep) sampling. Refcounted so multiple observers share a timer.+ func start(interval: TimeInterval = 2.0) {+ observerCount += 1+ guard timer == nil else { return }+ memoryTotal = Int64(ProcessInfo.processInfo.physicalMemory)+ sample()+ let t = Timer(timeInterval: interval, repeats: true) { [weak self] _ in+ Task { @MainActor in self?.sample() }+ }+ // .common so sampling continues while a menu/popover tracks the run loop.+ RunLoop.main.add(t, forMode: .common)+ timer = t+ }++ /// Release one observer; the timer stops once the last one goes away.+ func stop() {+ observerCount = max(0, observerCount - 1)+ guard observerCount == 0 else { return }+ timer?.invalidate()+ timer = nil+ }++ private func sample() {+ sampleCPU()+ sampleMemory()+ sampleDisk()+ }++ // MARK: - CPU++ private func sampleCPU() {+ var info = host_cpu_load_info()+ var count = mach_msg_type_number_t(+ MemoryLayout<host_cpu_load_info_data_t>.stride / MemoryLayout<integer_t>.stride+ )+ let result = withUnsafeMutablePointer(to: &info) {+ $0.withMemoryRebound(to: integer_t.self, capacity: Int(count)) {+ host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, $0, &count)+ }+ }+ guard result == KERN_SUCCESS else { return }++ let user = UInt64(info.cpu_ticks.0)+ let system = UInt64(info.cpu_ticks.1)+ let idle = UInt64(info.cpu_ticks.2)+ let nice = UInt64(info.cpu_ticks.3)+ let busy = user &+ system &+ nice+ let total = busy &+ idle++ defer { previousBusy = busy; previousTotal = total }+ // First sample has no prior baseline to diff against.+ guard previousTotal != 0, total > previousTotal else { return }++ let busyDelta = Double(busy &- previousBusy)+ let totalDelta = Double(total &- previousTotal)+ guard totalDelta > 0 else { return }+ cpuUsage = min(1, max(0, busyDelta / totalDelta))+ }++ // MARK: - Memory++ private func sampleMemory() {+ var stats = vm_statistics64()+ var count = mach_msg_type_number_t(+ MemoryLayout<vm_statistics64_data_t>.stride / MemoryLayout<integer_t>.stride+ )+ let result = withUnsafeMutablePointer(to: &stats) {+ $0.withMemoryRebound(to: integer_t.self, capacity: Int(count)) {+ host_statistics64(mach_host_self(), HOST_VM_INFO64, $0, &count)+ }+ }+ guard result == KERN_SUCCESS else { return }++ let pageSize = Int64(vm_kernel_page_size)+ // "App Memory" + wired + compressed mirrors what Activity Monitor counts+ // as memory pressure; free + purgeable + most file-backed pages are not+ // pressure, so they're excluded.+ let used = (Int64(stats.active_count)+ + Int64(stats.wire_count)+ + Int64(stats.compressor_page_count)) * pageSize+ memoryUsed = used+ }++ // MARK: - Disk++ private func sampleDisk() {+ let url = URL(fileURLWithPath: NSHomeDirectory())+ guard let values = try? url.resourceValues(forKeys: [+ .volumeTotalCapacityKey,+ .volumeAvailableCapacityForImportantUsageKey,+ ]) else { return }++ if let total = values.volumeTotalCapacity {+ diskTotal = Int64(total)+ }+ if let available = values.volumeAvailableCapacityForImportantUsage {+ diskUsed = max(0, diskTotal - available)+ }+ }+}diff --git a/PureMac/Views/Components/MenuBarMonitorView.swift b/PureMac/Views/Components/MenuBarMonitorView.swiftnew file mode 100644index 0000000..6dfea94--- /dev/null+++ b/PureMac/Views/Components/MenuBarMonitorView.swift@@ -0,0 +1,129 @@+import SwiftUI+import AppKit++/// Zero-size helper that captures SwiftUI's `openWindow` action into+/// `WindowOpener.shared` when the main window appears, so the AppKit menu-bar+/// popover can reopen the window after it's been closed.+struct WindowOpenerCapture: View {+ @Environment(\.openWindow) private var openWindow++ var body: some View {+ Color.clear+ .frame(width: 0, height: 0)+ .onAppear { WindowOpener.shared.open = { id in openWindow(id: id) } }+ }+}++/// Drop-down panel hosted in the menu-bar `NSPopover` (via `NSHostingController`)+/// with live CPU / memory / disk meters and quick actions. Kept self-contained+/// so the menu bar surface stays decoupled from the main window's `AppState`.+struct MenuBarMonitorView: View {+ @ObservedObject private var monitor = SystemMonitor.shared++ var body: some View {+ VStack(alignment: .leading, spacing: 12) {+ Text("System Monitor")+ .font(.system(size: 13, weight: .semibold))+ .foregroundStyle(.primary)++ VStack(spacing: 10) {+ MeterRow(title: "CPU", tint: Tint.blue,+ fraction: monitor.cpuUsage,+ detail: "\(Int((monitor.cpuUsage * 100).rounded()))%")+ MeterRow(title: "Memory", tint: Tint.purple,+ fraction: monitor.memoryFraction,+ detail: byteDetail(monitor.memoryUsed, monitor.memoryTotal))+ MeterRow(title: "Disk", tint: Tint.green,+ fraction: monitor.diskFraction,+ detail: byteDetail(monitor.diskUsed, monitor.diskTotal))+ }++ Divider()++ HStack {+ Button {+ openMainWindow()+ } label: {+ Text("Open PureMac")+ }+ .buttonStyle(.borderedProminent)+ .controlSize(.small)++ Spacer()++ Button {+ NSApp.terminate(nil)+ } label: {+ Text("Quit PureMac")+ }+ .buttonStyle(.bordered)+ .controlSize(.small)+ }+ }+ .padding(14)+ .frame(width: 248)+ .onAppear { monitor.start() }+ .onDisappear { monitor.stop() }+ }++ private func byteDetail(_ used: Int64, _ total: Int64) -> String {+ let u = ByteCountFormatter.string(fromByteCount: used, countStyle: .memory)+ let t = ByteCountFormatter.string(fromByteCount: total, countStyle: .memory)+ return "\(u) / \(t)"+ }++ /// Bring the app forward and surface the main window. The app stays alive+ /// after its window closes only while the monitor is enabled (see+ /// `AppDelegate.applicationShouldTerminateAfterLastWindowClosed`), so this+ /// reopens a fresh window when none is left, otherwise just focuses it.+ private func openMainWindow() {+ NSApp.activate(ignoringOtherApps: true)+ // Exclude the menu-bar popover's own panel; a real content window is+ // titled and can become main.+ if let existing = NSApp.windows.first(where: {+ $0.canBecomeMain && $0.styleMask.contains(.titled)+ }) {+ existing.makeKeyAndOrderFront(nil)+ } else {+ // No content window left — reopen via the captured openWindow action+ // (the popover has no working openWindow environment of its own).+ WindowOpener.shared.open?("main")+ }+ }+}++/// One labeled meter: title on the left, a thin tinted progress bar, and a+/// trailing numeric detail. Mirrors the restrained chrome used elsewhere.+private struct MeterRow: View {+ let title: LocalizedStringKey+ let tint: Color+ let fraction: Double+ let detail: String++ private var clamped: Double { max(0, min(1, fraction)) }++ var body: some View {+ VStack(spacing: 4) {+ HStack {+ Text(title)+ .font(.system(size: 11, weight: .medium))+ .foregroundStyle(.secondary)+ Spacer()+ Text(detail)+ .font(.system(size: 11, weight: .semibold))+ .monospacedDigit()+ .foregroundStyle(.primary)+ }+ GeometryReader { geo in+ ZStack(alignment: .leading) {+ Capsule()+ .fill(Color.primary.opacity(0.08))+ Capsule()+ .fill(tint)+ .frame(width: max(2, geo.size.width * clamped))+ }+ }+ .frame(height: 5)+ }+ }+}diff --git a/PureMac/Views/Settings/SettingsView.swift b/PureMac/Views/Settings/SettingsView.swiftindex 8c5e4d7..f288168 100644--- a/PureMac/Views/Settings/SettingsView.swift+++ b/PureMac/Views/Settings/SettingsView.swift@@ -40,6 +40,7 @@ struct GeneralSettingsView: View {@AppStorage("settings.general.launchAtLogin") private var launchAtLogin = false@AppStorage("settings.general.searchSensitivity") private var sensitivity: SearchSensitivity = .enhanced@AppStorage("settings.general.confirmBeforeDelete") private var confirmBeforeDelete = true+ @AppStorage("settings.general.menuBarMonitor") private var menuBarMonitor = false@AppStorage(Haptics.soundEffectsKey) private var soundEffects = true@AppStorage(AppLanguage.preferenceKey) private var appLanguageRaw = AppLanguage.current.rawValue@State private var languageNeedsRelaunch = false@@ -86,6 +87,13 @@ struct GeneralSettingsView: View {}}+ Section("System Monitor") {+ Toggle("Show system monitor in menu bar", isOn: menuBarMonitorBinding)+ Text("Live CPU, memory, and disk meters in the menu bar. PureMac keeps running in the background while this is on.")+ .font(.caption)+ .foregroundStyle(.secondary)+ }+Section("Sound") {Toggle("Play sound effects", isOn: $soundEffects)}@@ -99,6 +107,17 @@ struct GeneralSettingsView: View {value: languageNeedsRelaunch)}+ private var menuBarMonitorBinding: Binding<Bool> {+ Binding(+ get: { menuBarMonitor },+ set: { newValue in+ menuBarMonitor = newValue+ // Tell AppDelegate to add/remove the status item without relaunch.+ NotificationCenter.default.post(name: .pureMacMenuBarMonitorChanged, object: nil)+ }+ )+ }+private var launchAtLoginBinding: Binding<Bool> {Binding(get: { launchAtLogin },diff --git a/PureMac/ar.lproj/Localizable.strings b/PureMac/ar.lproj/Localizable.stringsindex 4930da7..cc82f5c 100644--- a/PureMac/ar.lproj/Localizable.strings+++ b/PureMac/ar.lproj/Localizable.strings@@ -364,3 +364,13 @@"Ignored orphans: %lld" = "الملفات اليتيمة المتجاهَلة: %lld";"Forget Ignored" = "نسيان المتجاهَلة";"Ignored files won't appear in future orphan scans." = "لن تظهر الملفات المتجاهَلة في عمليات فحص الملفات اليتيمة المستقبلية.";++/* v2.8.3: menu-bar system monitor */+"System Monitor" = "مراقب النظام";+"Show system monitor in menu bar" = "إظهار مراقب النظام في شريط القوائم";+"Live CPU, memory, and disk meters in the menu bar. PureMac keeps running in the background while this is on." = "مقاييس مباشرة للمعالج والذاكرة والقرص في شريط القوائم. يستمر PureMac في العمل في الخلفية أثناء تفعيل هذا الخيار.";+"CPU" = "المعالج";+"Memory" = "الذاكرة";+"Disk" = "القرص";+"Open PureMac" = "فتح PureMac";+"Quit PureMac" = "إنهاء PureMac";diff --git a/PureMac/en.lproj/Localizable.strings b/PureMac/en.lproj/Localizable.stringsindex a6c686a..812ab62 100644--- a/PureMac/en.lproj/Localizable.strings+++ b/PureMac/en.lproj/Localizable.strings@@ -364,3 +364,13 @@"Ignored orphans: %lld" = "Ignored orphans: %lld";"Forget Ignored" = "Forget Ignored";"Ignored files won't appear in future orphan scans." = "Ignored files won't appear in future orphan scans.";++/* v2.8.3: menu-bar system monitor */+"System Monitor" = "System Monitor";+"Show system monitor in menu bar" = "Show system monitor in menu bar";+"Live CPU, memory, and disk meters in the menu bar. PureMac keeps running in the background while this is on." = "Live CPU, memory, and disk meters in the menu bar. PureMac keeps running in the background while this is on.";+"CPU" = "CPU";+"Memory" = "Memory";+"Disk" = "Disk";+"Open PureMac" = "Open PureMac";+"Quit PureMac" = "Quit PureMac";diff --git a/PureMac/es.lproj/Localizable.strings b/PureMac/es.lproj/Localizable.stringsindex 2edaeda..cadbf64 100644--- a/PureMac/es.lproj/Localizable.strings+++ b/PureMac/es.lproj/Localizable.strings@@ -364,3 +364,13 @@"Ignored orphans: %lld" = "Huérfanos ignorados: %lld";"Forget Ignored" = "Olvidar ignorados";"Ignored files won't appear in future orphan scans." = "Los archivos ignorados no aparecerán en futuros análisis de huérfanos.";++/* v2.8.3: menu-bar system monitor */+"System Monitor" = "Monitor del sistema";+"Show system monitor in menu bar" = "Mostrar el monitor del sistema en la barra de menús";+"Live CPU, memory, and disk meters in the menu bar. PureMac keeps running in the background while this is on." = "Medidores de CPU, memoria y disco en vivo en la barra de menús. PureMac sigue ejecutándose en segundo plano mientras esto está activado.";+"CPU" = "CPU";+"Memory" = "Memoria";+"Disk" = "Disco";+"Open PureMac" = "Abrir PureMac";+"Quit PureMac" = "Salir de PureMac";diff --git a/PureMac/ja.lproj/Localizable.strings b/PureMac/ja.lproj/Localizable.stringsindex 10bf101..a26b5fc 100644--- a/PureMac/ja.lproj/Localizable.strings+++ b/PureMac/ja.lproj/Localizable.strings@@ -364,3 +364,13 @@"Ignored orphans: %lld" = "無視した孤立ファイル: %lld";"Forget Ignored" = "無視リストを消去";"Ignored files won't appear in future orphan scans." = "無視したファイルは今後の孤立ファイルのスキャンに表示されません。";++/* v2.8.3: menu-bar system monitor */+"System Monitor" = "システムモニタ";+"Show system monitor in menu bar" = "メニューバーにシステムモニタを表示";+"Live CPU, memory, and disk meters in the menu bar. PureMac keeps running in the background while this is on." = "CPU、メモリ、ディスクの使用状況をメニューバーにリアルタイム表示します。オンの間、PureMacはバックグラウンドで動作し続けます。";+"CPU" = "CPU";+"Memory" = "メモリ";+"Disk" = "ディスク";+"Open PureMac" = "PureMacを開く";+"Quit PureMac" = "PureMacを終了";diff --git a/PureMac/pt-BR.lproj/Localizable.strings b/PureMac/pt-BR.lproj/Localizable.stringsindex b57eb90..7e1f6c0 100644--- a/PureMac/pt-BR.lproj/Localizable.strings+++ b/PureMac/pt-BR.lproj/Localizable.strings@@ -364,3 +364,13 @@"Ignored orphans: %lld" = "Órfãos ignorados: %lld";"Forget Ignored" = "Esquecer ignorados";"Ignored files won't appear in future orphan scans." = "Arquivos ignorados não aparecerão em futuras verificações de órfãos.";++/* v2.8.3: menu-bar system monitor */+"System Monitor" = "Monitor do sistema";+"Show system monitor in menu bar" = "Mostrar o monitor do sistema na barra de menus";+"Live CPU, memory, and disk meters in the menu bar. PureMac keeps running in the background while this is on." = "Medidores de CPU, memória e disco ao vivo na barra de menus. O PureMac continua em execução em segundo plano enquanto isso estiver ativado.";+"CPU" = "CPU";+"Memory" = "Memória";+"Disk" = "Disco";+"Open PureMac" = "Abrir o PureMac";+"Quit PureMac" = "Encerrar o PureMac";diff --git a/PureMac/zh-Hans.lproj/Localizable.strings b/PureMac/zh-Hans.lproj/Localizable.stringsindex 3a5d2e0..a94f908 100644--- a/PureMac/zh-Hans.lproj/Localizable.strings+++ b/PureMac/zh-Hans.lproj/Localizable.strings@@ -364,3 +364,13 @@"Ignored orphans: %lld" = "已忽略的孤立文件:%lld";"Forget Ignored" = "清除已忽略";"Ignored files won't appear in future orphan scans." = "已忽略的文件不会出现在以后的孤立文件扫描中。";++/* v2.8.3: menu-bar system monitor */+"System Monitor" = "系统监视器";+"Show system monitor in menu bar" = "在菜单栏中显示系统监视器";+"Live CPU, memory, and disk meters in the menu bar. PureMac keeps running in the background while this is on." = "在菜单栏中实时显示 CPU、内存和磁盘使用情况。开启时 PureMac 将在后台持续运行。";+"CPU" = "CPU";+"Memory" = "内存";+"Disk" = "磁盘";+"Open PureMac" = "打开 PureMac";+"Quit PureMac" = "退出 PureMac";diff --git a/PureMac/zh-Hant.lproj/Localizable.strings b/PureMac/zh-Hant.lproj/Localizable.stringsindex 1ed8280..091e012 100644--- a/PureMac/zh-Hant.lproj/Localizable.strings+++ b/PureMac/zh-Hant.lproj/Localizable.strings@@ -364,3 +364,13 @@"Ignored orphans: %lld" = "已忽略的孤立檔案:%lld";"Forget Ignored" = "清除已忽略";"Ignored files won't appear in future orphan scans." = "已忽略的檔案不會出現在日後的孤立檔案掃描中。";++/* v2.8.3: menu-bar system monitor */+"System Monitor" = "系統監視器";+"Show system monitor in menu bar" = "在選單列中顯示系統監視器";+"Live CPU, memory, and disk meters in the menu bar. PureMac keeps running in the background while this is on." = "在選單列中即時顯示 CPU、記憶體和磁碟使用情況。開啟時 PureMac 會在背景持續執行。";+"CPU" = "CPU";+"Memory" = "記憶體";+"Disk" = "磁碟";+"Open PureMac" = "開啟 PureMac";+"Quit PureMac" = "結束 PureMac";diff --git a/project.yml b/project.ymlindex aef77ce..f598a9a 100644--- a/project.yml+++ b/project.yml@@ -23,8 +23,8 @@ settings:CODE_SIGN_ENTITLEMENTS: "PureMac/PureMac.entitlements"INFOPLIST_FILE: "PureMac/Info.plist"PRODUCT_BUNDLE_IDENTIFIER: "com.puremac.app"- MARKETING_VERSION: "2.8.2"- CURRENT_PROJECT_VERSION: "17"+ MARKETING_VERSION: "2.8.3"+ CURRENT_PROJECT_VERSION: "18"GENERATE_INFOPLIST_FILE: "NO"ASSETCATALOG_COMPILER_APPICON_NAME: "AppIcon"COMBINE_HIDPI_IMAGES: "YES"