Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Tell VoiceOver only the readings of Applications the person asked for

Țugui Dragoș6532afed3b9e
diff --git a/Peel/Model/AppLibrary.swift b/Peel/Model/AppLibrary.swift
index a16c0c14..7aaf2b6e 100644
--- a/Peel/Model/AppLibrary.swift
+++ b/Peel/Model/AppLibrary.swift
@@ -81,6 +81,10 @@ final class AppLibrary {
/// Whether the last reading read every app, which Orphaned Files waits for.
var readEverything: Bool { listing.readEverything }
+ /// True while a reading the person asked for runs, the first or Rescan's: the list tells VoiceOver only those, and
+ /// the readings Peel starts on its own change it quietly.
+ var isReadingAsAsked: Bool { scanRun.isRunning && askedForReading }
+ private var askedForReading = false
private(set) var updateStatuses: [InstalledApp.ID: UpdateStatus] = [:] {
didSet { updatesRevision += 1 }
}
@@ -231,7 +235,9 @@ final class AppLibrary {
releaseNotes = await releaseNotesStore.load()
}
let chosen = readFolders()
+ askedForReading = true
let found = await scanRun.run { await AppCatalog.scan(chosen: chosen) }
+ if !scanRun.isRunning { askedForReading = false }
if let found {
keepUnreadable(of: found)
adopt(found.apps)
@@ -293,7 +299,9 @@ final class AppLibrary {
func refresh() async -> [InstalledApp] {
lastRead = .now
let chosen = readFolders()
- guard let scan = await scanRun.run({ await AppCatalog.scan(chosen: chosen) }) else { return [] }
+ let read = await scanRun.run { await AppCatalog.scan(chosen: chosen) }
+ if !scanRun.isRunning { askedForReading = false }
+ guard let scan = read else { return [] }
keepUnreadable(of: scan)
let found = scan.apps
let listed = AppCatalog.sorted(found + stillThere(revealed, beside: found))
@@ -321,6 +329,7 @@ final class AppLibrary {
/// Reads the folders again and asks about every app's updates, in a round of its own so the list isn't held.
func rescan() async {
+ askedForReading = true
let changed = await refresh()
if !changed.isEmpty { await checkSigningTeams() }
checkEveryAppAgain()
diff --git a/Peel/Views/AppList.swift b/Peel/Views/AppList.swift
index d56c2e0f..5326b57f 100644
--- a/Peel/Views/AppList.swift
+++ b/Peel/Views/AppList.swift
@@ -83,7 +83,7 @@ struct AppList: View {
}
.fadesInColumn(whenRowsChange: library.apps.map(\.id))
.navigationTitle(Text(Tool.applications.title))
- .announcesScan(library.scanRun.isRunning, found: library.summary, wasStopped: library.scanRun.wasStopped)
+ .announcesScan(library.isReadingAsAsked, found: library.summary, wasStopped: library.scanRun.wasStopped)
.announcesScan(
library.isCheckingEveryApp,
found: Tool.applications.sentence(for: Looked(count: library.appsWithUpdates.count, size: nil))
diff --git a/PeelTests/AppLibraryTests.swift b/PeelTests/AppLibraryTests.swift
index d4a7ba3d..8b2004fe 100644
--- a/PeelTests/AppLibraryTests.swift
+++ b/PeelTests/AppLibraryTests.swift
@@ -924,4 +924,36 @@ private nonisolated final class TestClock: Sendable {
await library.refresh()
#expect(library.folders == [] && !library.listOfFoldersUnreadable)
}
+
+ @Test func onlyTheReadingsThePersonAskedForAreToldToVoiceOver() async throws {
+ let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")
+ try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true)
+ defer { try? FileManager.default.removeItem(at: folder) }
+ let made = try MadeUpDefaults()
+ defer { made.forget() }
+ AppcastProtocol.body.withLock { $0 = Data() }
+ let configuration = URLSessionConfiguration.ephemeral
+ configuration.protocolClasses = [AppcastProtocol.self]
+ let library = AppLibrary(
+ defaults: made.defaults,
+ updateChecker: UpdateChecker(session: URLSession(configuration: configuration)),
+ releaseNotesStore: ReleaseNotesStore(url: folder.appending(path: "release-notes.json")),
+ appFolders: AppFolders(url: folder.appending(path: "app-folders.json")),
+ appMemory: AppMemory(url: folder.appending(path: "apps.json"))
+ )
+ func toldWhile(_ reading: @escaping () async -> Void) async throws -> Bool {
+ let task = Task { await reading() }
+ for _ in 0..<10_000 where !library.scanRun.isRunning { await Task.yield() }
+ try #require(library.scanRun.isRunning)
+ let told = library.isReadingAsAsked
+ await task.value
+ return told
+ }
+
+ #expect(try await toldWhile { await library.load() })
+ #expect(try await !toldWhile { await library.refresh() })
+ #expect(try await toldWhile { await library.rescan() })
+ library.recheck?.cancel()
+ #expect(!library.isReadingAsAsked)
+ }
}