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.

Read Intel Software again quietly

Țugui Dragoșcc95b4870af2
diff --git a/Peel/Model/IntelLibrary.swift b/Peel/Model/IntelLibrary.swift
index 8d660ce9..02818eb7 100644
--- a/Peel/Model/IntelLibrary.swift
+++ b/Peel/Model/IntelLibrary.swift
@@ -16,17 +16,40 @@ final class IntelLibrary {
var findings: [IntelFinding] { scan?.findings ?? [] }
- /// Scans everything the report covers, so it is complete even when the other pages were never opened.
- func refresh(installedApps: [InstalledApp]) async {
- guard let result = await scanRun.run({
- let exclusions = ExclusionsStore.shared.exclusions
+ private let read: @MainActor ([InstalledApp], Exclusions) async -> IntelScan
+
+ /// `read` scans everything the report covers, so it is complete even when the other pages were never opened.
+ init(
+ read: @escaping @MainActor ([InstalledApp], Exclusions) async -> IntelScan = { installedApps, exclusions in
async let backgroundItems = BackgroundItems.scan(exclusions: exclusions)
return await IntelInspector.scan(
installedApps: installedApps,
backgroundItems: backgroundItems,
exclusions: exclusions
)
- }) else { return }
+ }
+ ) {
+ self.read = read
+ }
+
+ func refresh(installedApps: [InstalledApp]) async {
+ let read = read
+ guard let result = await scanRun.run({ await read(installedApps, ExclusionsStore.shared.exclusions) }) else {
+ return
+ }
+ show(result)
+ }
+
+ /// Reads the page again without showing a scan, once it has been read.
+ func readAgain(installedApps: [InstalledApp]) async {
+ guard scan != nil else { return }
+ let read = read
+ guard let result = await scanRun.runQuietly({ await read(installedApps, ExclusionsStore.shared.exclusions) })
+ else { return }
+ show(result)
+ }
+
+ private func show(_ result: IntelScan) {
scan = result
if let selection, !result.findings.contains(where: { $0.id == selection }) {
self.selection = nil
diff --git a/Peel/Views/Intel/IntelList.swift b/Peel/Views/Intel/IntelList.swift
index 5c2b99f7..9d628d9a 100644
--- a/Peel/Views/Intel/IntelList.swift
+++ b/Peel/Views/Intel/IntelList.swift
@@ -81,15 +81,20 @@ struct IntelList: View {
}
}
}
- // What the page lists can change from other pages and other apps, and a scan costs little, so it looks again
- // each time it is shown and each time Peel comes forward.
+ // What the page lists can change from other pages and other apps, and a scan costs little, so once read it
+ // looks again, quietly, each time it is shown and each time Peel comes forward.
.task(id: library.revision) {
- guard library.hasLoaded, !(intel.scan == nil && intel.scanRun.wasStopped) else { return }
+ guard library.hasLoaded else { return }
+ guard intel.scan == nil else {
+ await intel.readAgain(installedApps: library.apps)
+ return
+ }
+ guard !intel.scanRun.wasStopped else { return }
await scan()
}
.onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)) { _ in
- guard library.hasLoaded, !(intel.scan == nil && intel.scanRun.wasStopped) else { return }
- Task { await scan() }
+ guard library.hasLoaded else { return }
+ Task { await intel.readAgain(installedApps: library.apps) }
}
.rescanOnExclusionChange("IntelList") { await scan() }
}
diff --git a/PeelTests/IntelLibraryTests.swift b/PeelTests/IntelLibraryTests.swift
new file mode 100644
index 00000000..2f7b3b8f
--- /dev/null
+++ b/PeelTests/IntelLibraryTests.swift
@@ -0,0 +1,33 @@
+import Foundation
+@testable import Peel
+@testable import PeelCore
+import Testing
+
+@MainActor
+struct IntelLibraryTests {
+ private final class Reads {
+ var count = 0
+ var library: IntelLibrary?
+ var wereShownAsAScan: [Bool] = []
+ }
+
+ @Test func readsAgainWithoutShowingAScan() async {
+ let reads = Reads()
+ let unread = URL(filePath: "/org.example/Vendor")
+ let library = IntelLibrary { _, _ in
+ reads.count += 1
+ reads.wereShownAsAScan.append(reads.library?.isScanning == true)
+ return IntelScan(findings: [], unreadable: reads.count > 1 ? [unread] : [])
+ }
+ reads.library = library
+
+ await library.readAgain(installedApps: [])
+ #expect(reads.count == 0, "nothing is read again before the page was read once")
+
+ await library.refresh(installedApps: [])
+ await library.readAgain(installedApps: [])
+
+ #expect(library.scan?.unreadable == [unread])
+ #expect(reads.wereShownAsAScan == [true, false], "a read again is announced to nobody")
+ }
+}