Skip to content

Free, open-source macOS cleaner. CleanMyMac alternative with zero telemetry. Native SwiftUI, scheduled auto-cleaning, Xcode/Homebrew/system cache cleanup. MIT licensed.

fix: orphan context menu actions + app size calculation (#96, #92)

moamen4f3354a7a0bf
diff --git a/PureMac/Logic/Scanning/AppInfoFetcher.swift b/PureMac/Logic/Scanning/AppInfoFetcher.swift
index a57b279..34c837f 100644
--- a/PureMac/Logic/Scanning/AppInfoFetcher.swift
+++ b/PureMac/Logic/Scanning/AppInfoFetcher.swift
@@ -103,30 +103,29 @@ final class AppInfoFetcher {
}
private func appSize(at url: URL) -> Int64 {
- // Try totalFileAllocatedSize on the bundle URL first (fast, accurate)
- if let values = try? url.resourceValues(forKeys: [.totalFileAllocatedSizeKey]),
- let size = values.totalFileAllocatedSize, size > 0 {
- return Int64(size)
- }
-
- // Enumerate files and sum their sizes
+ // totalFileAllocatedSizeKey on a directory URL returns only the
+ // directory inode (~4 KB on APFS), not the recursive sum - the
+ // previous fast-path returned that and exited, causing app sizes
+ // to display as ~4 KB regardless of bundle contents. Always
+ // enumerate the bundle contents and sum.
guard let enumerator = fileManager.enumerator(
at: url,
- includingPropertiesForKeys: [.totalFileAllocatedSizeKey, .isRegularFileKey],
+ includingPropertiesForKeys: [.totalFileAllocatedSizeKey, .fileAllocatedSizeKey, .isRegularFileKey, .isSymbolicLinkKey],
options: [.skipsHiddenFiles]
) else { return 0 }
var total: Int64 = 0
- var count = 0
for case let fileURL as URL in enumerator {
- count += 1
- if count > 10000 { break }
- guard let values = try? fileURL.resourceValues(forKeys: [.totalFileAllocatedSizeKey, .fileSizeKey, .isRegularFileKey]),
- values.isRegularFile == true else { continue }
+ guard let values = try? fileURL.resourceValues(forKeys: [.totalFileAllocatedSizeKey, .fileAllocatedSizeKey, .isRegularFileKey, .isSymbolicLinkKey]) else { continue }
+ // Skip symlinks so we don't double-count or follow links out of
+ // the bundle. Skip directories so we only count regular file
+ // payload.
+ if values.isSymbolicLink == true { continue }
+ guard values.isRegularFile == true else { continue }
if let allocated = values.totalFileAllocatedSize {
total += Int64(allocated)
- } else if let size = values.fileSize {
- total += Int64(size)
+ } else if let allocated = values.fileAllocatedSize {
+ total += Int64(allocated)
}
}
return total
diff --git a/PureMac/Views/Orphans/OrphanListView.swift b/PureMac/Views/Orphans/OrphanListView.swift
index 0343838..2c628e6 100644
--- a/PureMac/Views/Orphans/OrphanListView.swift
+++ b/PureMac/Views/Orphans/OrphanListView.swift
@@ -47,7 +47,15 @@ struct OrphanListView: View {
.toggleStyle(.checkbox)
.contextMenu {
Button("Reveal in Finder") {
- NSWorkspace.shared.selectFile(fileURL.path, inFileViewerRootedAtPath: "")
+ revealInFinder(fileURL)
+ }
+ Button("Copy Path") {
+ NSPasteboard.general.clearContents()
+ NSPasteboard.general.setString(fileURL.path, forType: .string)
+ }
+ Divider()
+ Button("Move to Trash", role: .destructive) {
+ Task { await removeSingleOrphan(fileURL) }
}
}
}
@@ -204,6 +212,31 @@ struct OrphanListView: View {
}
}
+ private func revealInFinder(_ url: URL) {
+ // activateFileViewerSelecting handles sandbox-bookmarked paths and
+ // missing files better than selectFile(_:inFileViewerRootedAtPath:),
+ // which silently no-ops when the path is unreachable from Finder's
+ // current scope. If the target itself was removed since the scan,
+ // fall back to opening the enclosing directory so the user lands
+ // somewhere useful instead of nothing happening.
+ let fm = FileManager.default
+ if fm.fileExists(atPath: url.path) {
+ NSWorkspace.shared.activateFileViewerSelecting([url])
+ return
+ }
+ let parent = url.deletingLastPathComponent()
+ if fm.fileExists(atPath: parent.path) {
+ NSWorkspace.shared.open(parent)
+ }
+ }
+
+ private func removeSingleOrphan(_ url: URL) async {
+ let previous = selectedOrphans
+ selectedOrphans = [url]
+ await removeSelectedOrphans()
+ selectedOrphans = previous.subtracting([url])
+ }
+
private func removeWithAdminPrivileges(_ urls: [URL]) -> Bool {
guard !urls.isEmpty else { return true }
guard urls.allSatisfy({ OrphanSafetyPolicy.isSafeCandidate($0) }) else { return false }
diff --git a/PureMac/ar.lproj/Localizable.strings b/PureMac/ar.lproj/Localizable.strings
index 46505d3..9f887a5 100644
--- a/PureMac/ar.lproj/Localizable.strings
+++ b/PureMac/ar.lproj/Localizable.strings
@@ -83,6 +83,8 @@
"Rescan" = "إعادة الفحص";
"%lld of %lld selected" = "%lld من %lld محدد";
"Reveal in Finder" = "إظهار في Finder";
+"Copy Path" = "نسخ المسار";
+"Move to Trash" = "نقل إلى المهملات";
/* Apps (AppListView) */
"Search apps" = "بحث في التطبيقات";
diff --git a/PureMac/en.lproj/Localizable.strings b/PureMac/en.lproj/Localizable.strings
index 72c93ed..6c0e9a7 100644
--- a/PureMac/en.lproj/Localizable.strings
+++ b/PureMac/en.lproj/Localizable.strings
@@ -83,6 +83,8 @@
"Rescan" = "Rescan";
"%lld of %lld selected" = "%lld of %lld selected";
"Reveal in Finder" = "Reveal in Finder";
+"Copy Path" = "Copy Path";
+"Move to Trash" = "Move to Trash";
/* Apps (AppListView) */
"Search apps" = "Search apps";
diff --git a/PureMac/es.lproj/Localizable.strings b/PureMac/es.lproj/Localizable.strings
index f7079be..3ae5f3f 100644
--- a/PureMac/es.lproj/Localizable.strings
+++ b/PureMac/es.lproj/Localizable.strings
@@ -83,6 +83,8 @@
"Rescan" = "Volver a analizar";
"%lld of %lld selected" = "%lld de %lld seleccionados";
"Reveal in Finder" = "Mostrar en el Finder";
+"Copy Path" = "Copiar ruta";
+"Move to Trash" = "Mover a la Papelera";
/* Apps (AppListView) */
"Search apps" = "Buscar apps";
diff --git a/PureMac/ja.lproj/Localizable.strings b/PureMac/ja.lproj/Localizable.strings
index 7d815a8..5ba9b85 100644
--- a/PureMac/ja.lproj/Localizable.strings
+++ b/PureMac/ja.lproj/Localizable.strings
@@ -83,6 +83,8 @@
"Rescan" = "再スキャン";
"%lld of %lld selected" = "%lld / %lld 個を選択中";
"Reveal in Finder" = "Finderで表示";
+"Copy Path" = "パスをコピー";
+"Move to Trash" = "ゴミ箱に移動";
/* Apps (AppListView) */
"Search apps" = "アプリを検索";
diff --git a/PureMac/pt-BR.lproj/Localizable.strings b/PureMac/pt-BR.lproj/Localizable.strings
index e00e328..dd4ee0f 100644
--- a/PureMac/pt-BR.lproj/Localizable.strings
+++ b/PureMac/pt-BR.lproj/Localizable.strings
@@ -83,6 +83,8 @@
"Rescan" = "Verificar novamente";
"%lld of %lld selected" = "%lld de %lld selecionados";
"Reveal in Finder" = "Mostrar no Finder";
+"Copy Path" = "Copiar caminho";
+"Move to Trash" = "Mover para o Lixo";
/* Apps (AppListView) */
"Search apps" = "Buscar apps";
diff --git a/PureMac/zh-Hans.lproj/Localizable.strings b/PureMac/zh-Hans.lproj/Localizable.strings
index 4a17151..0700864 100644
--- a/PureMac/zh-Hans.lproj/Localizable.strings
+++ b/PureMac/zh-Hans.lproj/Localizable.strings
@@ -83,6 +83,8 @@
"Rescan" = "重新扫描";
"%lld of %lld selected" = "已选 %lld / %lld";
"Reveal in Finder" = "在访达中显示";
+"Copy Path" = "复制路径";
+"Move to Trash" = "移到废纸篓";
/* Apps (AppListView) */
"Search apps" = "搜索应用";
diff --git a/PureMac/zh-Hant.lproj/Localizable.strings b/PureMac/zh-Hant.lproj/Localizable.strings
index 4b1ef89..ed60aa0 100644
--- a/PureMac/zh-Hant.lproj/Localizable.strings
+++ b/PureMac/zh-Hant.lproj/Localizable.strings
@@ -83,6 +83,8 @@
"Rescan" = "重新掃描";
"%lld of %lld selected" = "已選 %lld / %lld";
"Reveal in Finder" = "在 Finder 中顯示";
+"Copy Path" = "複製路徑";
+"Move to Trash" = "移到垃圾桶";
/* Apps (AppListView) */
"Search apps" = "搜尋應用程式";