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
fix: sidebar selection + purgeable space detection
moamen71e51b6b759e
diff --git a/PureMac/Services/ScanEngine.swift b/PureMac/Services/ScanEngine.swiftindex a9de03c..e4aa41c 100644--- a/PureMac/Services/ScanEngine.swift+++ b/PureMac/Services/ScanEngine.swift@@ -46,9 +46,20 @@ actor ScanEngine {}info.usedSpace = info.totalSpace - info.freeSpace- // Calculate purgeable space from Time Machine local snapshots- // Purgeable = space used by local snapshots that macOS can reclaim- info.purgeableSpace = getLocalSnapshotSize()+ // Use URLResourceValues for accurate purgeable space detection+ let rootURL = URL(fileURLWithPath: "/")+ let values = try rootURL.resourceValues(forKeys: [+ .volumeAvailableCapacityForImportantUsageKey,+ .volumeAvailableCapacityKey+ ])+ if let importantCapacity = values.volumeAvailableCapacityForImportantUsage,+ let freeCapacity = values.volumeAvailableCapacity {+ // Purgeable = important capacity (free + purgeable) minus actual free+ let purgeable = importantCapacity - Int64(freeCapacity)+ if purgeable > 10 * 1024 * 1024 { // Only report if > 10 MB+ info.purgeableSpace = purgeable+ }+ }} catch {Logger.shared.log("Disk info unavailable: \(error.localizedDescription)", level: .warning)}@@ -202,33 +213,33 @@ actor ScanEngine {var items: [CleanableItem] = []var totalSize: Int64 = 0- // List Time Machine local snapshots - these are the main purgeable items- let snapshots = getLocalSnapshots()- for snapshot in snapshots {+ // Detect APFS purgeable space via URLResourceValues (no admin needed)+ let diskInfo = getDiskInfo()+ if diskInfo.purgeableSpace > 0 {items.append(CleanableItem(- name: "TM Snapshot: \(snapshot.name)",- path: snapshot.name,- size: snapshot.size,+ name: "APFS Purgeable Space",+ path: "/",+ size: diskInfo.purgeableSpace,category: .purgeableSpace,isSelected: true,- lastModified: snapshot.date+ lastModified: nil))- totalSize += snapshot.size+ totalSize = diskInfo.purgeableSpace}- // If no snapshots found but system reports purgeable, show a single entry- if items.isEmpty {- let diskInfo = getDiskInfo()- if diskInfo.purgeableSpace > 0 {+ // Also list Time Machine local snapshots if any exist+ let snapshots = getLocalSnapshots()+ for snapshot in snapshots {+ let snapshotSize = snapshot.size > 0 ? snapshot.size : 0+ if snapshotSize > 0 {items.append(CleanableItem(- name: "APFS Purgeable Space",- path: "/",- size: diskInfo.purgeableSpace,+ name: "TM Snapshot: \(snapshot.name)",+ path: snapshot.name,+ size: snapshotSize,category: .purgeableSpace,- isSelected: true,- lastModified: nil+ isSelected: false,+ lastModified: snapshot.date))- totalSize = diskInfo.purgeableSpace}}diff --git a/PureMac/Views/MainWindow.swift b/PureMac/Views/MainWindow.swiftindex fd93672..ede64b0 100644--- a/PureMac/Views/MainWindow.swift+++ b/PureMac/Views/MainWindow.swift@@ -11,36 +11,45 @@ struct MainWindow: View {} detail: {detailView}- .navigationSplitViewColumnWidth(min: 200, ideal: 220, max: 280)+ .navigationSplitViewColumnWidth(min: 200, ideal: 230, max: 300).frame(minWidth: 860, minHeight: 520).onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)) { _ inappState.checkFullDiskAccess()}}+ // All sidebar items as a flat array so ForEach gives proper selectability+ private var allSidebarItems: [SidebarItem] {+ var items: [SidebarItem] = [+ SidebarItem(section: .apps, label: "Installed Apps", icon: "square.grid.2x2", badge: "\(appState.installedApps.count)", group: "Applications"),+ SidebarItem(section: .orphans, label: "Orphaned Files", icon: "doc.questionmark", badge: appState.orphanedFiles.count > 0 ? "\(appState.orphanedFiles.count)" : nil, group: "Applications"),+ ]+ for category in CleaningCategory.scannable {+ let size = appState.categoryResults[category]?.totalSize ?? 0+ let badge = size > 0 ? ByteCountFormatter.string(fromByteCount: size, countStyle: .file) : nil+ items.append(SidebarItem(section: .cleaning(category), label: category.rawValue, icon: category.icon, badge: badge, group: "Cleaning"))+ }+ return items+ }+private var sidebar: some View {List(selection: $selectedSection) {- Section("Applications") {- Label("Installed Apps", systemImage: "square.grid.2x2")- .tag(AppSection.apps)- .badge(appState.installedApps.count)- Label("Orphaned Files", systemImage: "doc.questionmark")- .tag(AppSection.orphans)- .badge(appState.orphanedFiles.count)- }-- Section("Cleaning") {- ForEach(CleaningCategory.scannable) { category in- HStack {- Label(category.rawValue, systemImage: category.icon)- Spacer()- if let size = appState.categoryResults[category]?.totalSize, size > 0 {- Text(ByteCountFormatter.string(fromByteCount: size, countStyle: .file))- .font(.caption)- .foregroundStyle(.secondary)+ let grouped = Dictionary(grouping: allSidebarItems, by: \.group)+ let order = ["Applications", "Cleaning"]+ ForEach(order, id: \.self) { group in+ Section(group) {+ ForEach(grouped[group] ?? [], id: \.section) { item in+ HStack {+ Label(item.label, systemImage: item.icon)+ Spacer()+ if let badge = item.badge {+ Text(badge)+ .font(.caption)+ .foregroundStyle(.secondary)+ }}+ .tag(item.section)}- .tag(AppSection.cleaning(category))}}}@@ -66,3 +75,11 @@ struct MainWindow: View {}}}++private struct SidebarItem {+ let section: AppSection+ let label: String+ let icon: String+ let badge: String?+ let group: String+}