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 a background item's Login Items status again with each scan

Țugui Dragoșed73846365bd
diff --git a/Peel/Model/BackgroundItemLibrary.swift b/Peel/Model/BackgroundItemLibrary.swift
index 2c881da8..f1bac5ba 100644
--- a/Peel/Model/BackgroundItemLibrary.swift
+++ b/Peel/Model/BackgroundItemLibrary.swift
@@ -10,6 +10,8 @@ final class BackgroundItemLibrary {
/// The scan this page runs, which a newer one or the Stop button ends.
let scanRun = ScanRun()
var isScanning: Bool { scanRun.isRunning }
+ /// Counts the scans that finished, so an item's page asks macOS about it again with each.
+ private(set) var scans = 0
/// The items with an action in progress. Each is tracked on its own, so one row's action ending never
/// clears another row's busy state.
private(set) var runningActionItemIDs: Set<BackgroundItem.ID> = []
@@ -34,6 +36,7 @@ final class BackgroundItemLibrary {
else { return }
items = result.items
unanswered = result.unanswered
+ scans += 1
if let selection, items?.contains(where: { $0.id == selection }) != true {
self.selection = nil
}
diff --git a/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift b/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift
index 954ddc86..d48fa463 100644
--- a/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift
+++ b/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift
@@ -11,10 +11,16 @@ struct BackgroundItemDetailView: View {
@Environment(ExclusionsStore.self) private var exclusions
@Environment(\.openSettings) private var openSettings
@State private var isConfirmingTrash = false
- /// Reading this asks macOS, so it is read once per item rather than on every evaluation of `body`.
+ /// Reading this asks macOS, so it is read once per item and scan rather than on every evaluation of `body`.
@State private var legacyStatus: LocalizedStringResource?
let item: BackgroundItem
+ /// The id of the task that reads `legacyStatus`: the item, and the scans that finished, so Rescan asks again.
+ private struct Look: Hashable {
+ let item: BackgroundItem.ID
+ let scans: Int
+ }
+
var body: some View {
Form {
Section {
@@ -163,7 +169,7 @@ struct BackgroundItemDetailView: View {
.formStyle(.grouped)
.motion(value: item.state)
.motion(value: item.isDisabled)
- .task(id: item.id) {
+ .task(id: Look(item: item.id, scans: backgroundItems.scans)) {
legacyStatus = await Self.legacyStatus(of: item)
}
.navigationTitle(item.label)