Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
Show iCloud Drive's total only once iCloud Drive has been read
Țugui Dragoșc3f53b45192c
diff --git a/Peel/Model/CloudLibrary.swift b/Peel/Model/CloudLibrary.swiftindex 5569e98c..fba4c1d6 100644--- a/Peel/Model/CloudLibrary.swift+++ b/Peel/Model/CloudLibrary.swift@@ -38,10 +38,17 @@ final class CloudLibrary {didSet { updateSelectedSize() }}private(set) var selectedSize: Int64 = 0+ private let home: URL- /// What the listed files take on this Mac, only the least it can be when there is more than the list shows.- var total: SizeTotal {- SizeTotal(known: (files ?? []).map(\.size).cappedSum, isComplete: !wasCutShort)+ init(home: URL = .homeDirectory) {+ self.home = home+ }++ /// What the listed files take on this Mac, only the least it can be when there is more than the list shows, and+ /// nil until iCloud Drive has been read.+ var total: SizeTotal? {+ guard let files, !couldNotRead else { return nil }+ return SizeTotal(known: files.map(\.size).cappedSum, isComplete: !wasCutShort)}/// The files whose folder or path holds `query`, every file for an empty one.@@ -70,9 +77,12 @@ final class CloudLibrary {func refresh() async {refusals = []let pictures = Set(NSScreen.screens.compactMap { NSWorkspace.shared.desktopImageURL(for: $0) })+ let home = homeguardlet scan = await scanRun.run({- await CloudStorage.downloaded(exclusions: ExclusionsStore.shared.exclusions, desktopPictures: pictures)+ await CloudStorage.downloaded(+ home: home, exclusions: ExclusionsStore.shared.exclusions, desktopPictures: pictures+ )})else { return }folders = scan.foldersdiff --git a/Peel/Model/FoundLastTimeStore.swift b/Peel/Model/FoundLastTimeStore.swiftindex 4446dcb4..9967d403 100644--- a/Peel/Model/FoundLastTimeStore.swift+++ b/Peel/Model/FoundLastTimeStore.swift@@ -101,6 +101,7 @@ extension DuplicateLibrary {extension CloudLibrary {var looked: Looked? {- files.map { Looked(count: $0.count, size: total) }+ guard let files, let total else { return nil }+ return Looked(count: files.count, size: total)}}diff --git a/Peel/Views/Cloud/CloudView.swift b/Peel/Views/Cloud/CloudView.swiftindex 4874a3e5..5ec35e97 100644--- a/Peel/Views/Cloud/CloudView.swift+++ b/Peel/Views/Cloud/CloudView.swift@@ -277,7 +277,9 @@ struct CloudView: View {.font(.callout).foregroundStyle(.secondary)} trailing: {- TotalLabel(total: cloud.total, caption: Text("on this Mac"))+ if let total = cloud.total {+ TotalLabel(total: total, caption: Text("on this Mac"))+ }}}}diff --git a/PeelTests/CloudLibraryTests.swift b/PeelTests/CloudLibraryTests.swiftnew file mode 100644index 00000000..b36502a8--- /dev/null+++ b/PeelTests/CloudLibraryTests.swift@@ -0,0 +1,35 @@+import Foundation+@testable import Peel+import PeelCore+import Testing++@MainActor+struct CloudLibraryTests {+ @Test func hasNoTotalUntilICloudDriveIsRead() async throws {+ let home = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")+ let drive = home.appending(path: "Library/Mobile Documents", directoryHint: .isDirectory)+ try FileManager.default.createDirectory(at: drive, withIntermediateDirectories: true)+ func permit(_ mode: Int) throws {+ try FileManager.default.setAttributes(+ [.posixPermissions: mode], ofItemAtPath: drive.path(percentEncoded: false)+ )+ }+ defer {+ try? permit(0o755)+ try? FileManager.default.removeItem(at: home)+ }+ let cloud = CloudLibrary(home: home)+ #expect(cloud.total == nil)++ try permit(0)+ await cloud.refresh()+ #expect(cloud.couldNotRead)+ #expect(cloud.total == nil)+ #expect(cloud.looked == nil)++ try permit(0o755)+ await cloud.refresh()+ #expect(!cloud.couldNotRead)+ #expect(cloud.total == SizeTotal(known: 0, isComplete: true))+ }+}