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.

Take what left the disk off Plug-ins and Installers when Peel comes forward

Țugui Dragoșe99e46ab52d1
diff --git a/Peel/Views/ExclusionRescan.swift b/Peel/Views/ExclusionRescan.swift
index ac21ee09..a56b8f74 100644
--- a/Peel/Views/ExclusionRescan.swift
+++ b/Peel/Views/ExclusionRescan.swift
@@ -18,6 +18,12 @@ extension View {
modifier(PageExclusionRescan(scannedUnder: revision, rescan: rescan))
}
+ /// Takes off a page what has left the disk, moved by another page or in Finder: when the page appears, when History
+ /// changes, and when Peel comes forward.
+ func leavesOutWhatLeft(_ leaveOut: @escaping () -> Void) -> some View {
+ modifier(WhatLeft(leaveOut: leaveOut))
+ }
+
/// Scans again once a Put Back, from History or Undo, brought back what `tool` moved, so it is listed again.
func rescanAfterPutBack(_ tool: Tool, _ rescan: @escaping () async -> Void) -> some View {
modifier(PutBackRescan(tool: tool, rescan: rescan))
@@ -37,6 +43,19 @@ private struct PutBackRescan: ViewModifier {
}
}
+private struct WhatLeft: ViewModifier {
+ @Environment(RemovalHistoryStore.self) private var history
+ let leaveOut: () -> Void
+
+ func body(content: Content) -> some View {
+ content
+ .task(id: history.revision) { leaveOut() }
+ .onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)) { _ in
+ leaveOut()
+ }
+ }
+}
+
private struct PageExclusionRescan: ViewModifier {
@Environment(ExclusionsStore.self) private var exclusions
let scannedUnder: Int?
diff --git a/Peel/Views/Installers/InstallerList.swift b/Peel/Views/Installers/InstallerList.swift
index 4c102c81..5fe44cde 100644
--- a/Peel/Views/Installers/InstallerList.swift
+++ b/Peel/Views/Installers/InstallerList.swift
@@ -5,7 +5,6 @@ import SwiftUI
struct InstallerList: View {
@Environment(AppLibrary.self) private var library
@Environment(InstallerLibrary.self) private var installers
- @Environment(RemovalHistoryStore.self) private var history
@Environment(HelperModel.self) private var helper
@State private var isRescanning = false
@@ -91,7 +90,7 @@ struct InstallerList: View {
guard library.hasLoaded else { return }
await installers.refreshUnlessScanned(within: InstallerLibrary.scanAgainAfter, installedApps: library.apps)
}
- .task(id: history.revision) { installers.leaveOutWhatLeft() }
+ .leavesOutWhatLeft { installers.leaveOutWhatLeft() }
.onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)) { _ in
guard library.hasLoaded else { return }
Task {
diff --git a/Peel/Views/Plugins/PluginList.swift b/Peel/Views/Plugins/PluginList.swift
index 8b5718f1..86c654d6 100644
--- a/Peel/Views/Plugins/PluginList.swift
+++ b/Peel/Views/Plugins/PluginList.swift
@@ -3,7 +3,6 @@ import SwiftUI
struct PluginList: View {
@Environment(PluginLibrary.self) private var plugins
- @Environment(RemovalHistoryStore.self) private var history
@State private var searchText = ""
@State private var isRescanning = false
@@ -107,7 +106,7 @@ struct PluginList: View {
guard plugins.plugins == nil, !plugins.scanRun.isWaitedFor, !plugins.scanRun.wasStopped else { return }
await plugins.refresh()
}
- .task(id: history.revision) { plugins.leaveOutWhatLeft() }
+ .leavesOutWhatLeft { plugins.leaveOutWhatLeft() }
.rescanOnExclusionChange("PluginList") { await plugins.refresh() }
.rescanAfterPutBack(.plugins) { await plugins.refresh() }
}
diff --git a/PeelTests/WhatLeftTests.swift b/PeelTests/WhatLeftTests.swift
new file mode 100644
index 00000000..05640071
--- /dev/null
+++ b/PeelTests/WhatLeftTests.swift
@@ -0,0 +1,43 @@
+import AppKit
+@testable import Peel
+import PeelCore
+import SwiftUI
+import Testing
+
+@MainActor
+struct WhatLeftTests {
+ private final class Looks {
+ var count = 0
+ }
+
+ private func settle(_ host: NSView, until isDone: () -> Bool) async {
+ for _ in 0..<200 where !isDone() {
+ host.layoutSubtreeIfNeeded()
+ try? await Task.sleep(for: .milliseconds(5))
+ }
+ }
+
+ @Test func aPageLooksForWhatLeftWhenItAppearsAndWhenPeelComesForward() async {
+ let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")
+ defer { try? FileManager.default.removeItem(at: folder) }
+ let history = RemovalHistoryStore(
+ log: RemovalLog(url: folder.appending(path: "removals.json")),
+ refusals: RefusalLog(url: folder.appending(path: "refusals.json")),
+ knowsTheExclusions: { true }
+ )
+ let looks = Looks()
+ let host = NSHostingView(rootView: Color.clear.leavesOutWhatLeft { looks.count += 1 }.environment(history))
+ let window = NSWindow(
+ contentRect: NSRect(x: 0, y: 0, width: 100, height: 100), styleMask: [.titled], backing: .buffered,
+ defer: true
+ )
+ window.contentView = host
+ await settle(host) { looks.count == 1 }
+ #expect(looks.count == 1)
+
+ NotificationCenter.default.post(name: NSApplication.didBecomeActiveNotification, object: NSApp)
+ await settle(host) { looks.count == 2 }
+
+ #expect(looks.count == 2)
+ }
+}