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.

Say on Home when History keeps every move back

Țugui Dragoșb14cd330050d
diff --git a/Peel/HomeSnapshot.swift b/Peel/HomeSnapshot.swift
index cb308f6c..42963718 100644
--- a/Peel/HomeSnapshot.swift
+++ b/Peel/HomeSnapshot.swift
@@ -17,6 +17,7 @@ enum HomeSnapshot {
let stats = LifetimeStats()
let found = FoundLastTimeStore()
let homebrew = HomebrewLibrary()
+ let history = RemovalHistoryStore()
await home.refresh()
await ExclusionsStore.shared.load()
let window = Color(nsColor: .windowBackgroundColor)
@@ -50,7 +51,7 @@ enum HomeSnapshot {
// by side.
try render(
HomePermissionsContent().environment(home).environment(helper)
- .environment(ExclusionsStore.shared),
+ .environment(ExclusionsStore.shared).environment(history),
width: 720,
on: window,
scheme: scheme,
@@ -59,7 +60,7 @@ enum HomeSnapshot {
)
try render(
HomePermissionsContent().environment(home).environment(helper)
- .environment(ExclusionsStore.shared),
+ .environment(ExclusionsStore.shared).environment(history),
width: 480,
on: window,
scheme: scheme,
diff --git a/Peel/Views/Home/HomePermissionsView.swift b/Peel/Views/Home/HomePermissionsView.swift
index 95543111..2d7599ce 100644
--- a/Peel/Views/Home/HomePermissionsView.swift
+++ b/Peel/Views/Home/HomePermissionsView.swift
@@ -6,6 +6,7 @@ struct HomePermissionsContent: View {
@Environment(HomeModel.self) private var home
@Environment(HelperModel.self) private var helper
@Environment(ExclusionsStore.self) private var exclusions
+ @Environment(RemovalHistoryStore.self) private var history
@Environment(\.openSettings) private var openSettings
@State private var pointingAt: HomeModel.Permission?
@State private var helperFailure: HelperModel.Failure?
@@ -216,10 +217,11 @@ struct HomePermissionsContent: View {
.frame(width: Self.markSize, height: Self.markSize)
}
- /// Unreadable exclusions come first: until they are read, nothing moves at all.
+ /// What keeps every move back comes first, as on the pages that move things: until it is gone, nothing moves.
@ViewBuilder
private var banner: some View {
- if exclusions.exclusions.isUnreadable {
+ let held = MovesHeld.reason(exclusions: exclusions, history: history)
+ if held == .exclusionsUnreadable {
Notice(
title: Text("Peel couldn’t read your exclusions"),
detail: Text("Peel removes nothing and puts nothing back until you start the list over in Settings."),
@@ -228,6 +230,21 @@ struct HomePermissionsContent: View {
Button("Open Peel Settings") { SettingsPane.exclusions.open(with: openSettings) }
.buttonStyle(.sticker(fill: Album.redFill, size: 11.5))
}
+ } else if held == .historyUnreadable {
+ Notice(
+ title: Text("Peel couldn’t read History"),
+ detail: Text("Peel removes nothing until you start History over, so that everything it moves can be put back."),
+ isAlbum: true
+ ) {
+ Button("Open History") { Navigator.shared.requestedTool = .history }
+ .buttonStyle(.sticker(fill: Album.redFill, size: 11.5))
+ }
+ } else if held == .historyUnwritable {
+ Notice(
+ title: Text("Peel can’t write History"),
+ detail: Text("The disk is full, or Peel’s folder can’t be written. Peel removes nothing until it can, so that everything it moves can be put back."),
+ isAlbum: true
+ ) {}
} else if home.needsAttention {
let notice = MissingPermissionsNotice(
helper: helper.standing,
diff --git a/Peel/Views/RemovalsHeldBanner.swift b/Peel/Views/RemovalsHeldBanner.swift
index 9c47f0c5..9a125659 100644
--- a/Peel/Views/RemovalsHeldBanner.swift
+++ b/Peel/Views/RemovalsHeldBanner.swift
@@ -1,9 +1,30 @@
import PeelCore
import SwiftUI
-/// Over a page that can move something to the Trash or put it back, while the exclusions or History can't be
-/// read, or History can't be written: nothing moves until they can, so the page's own button is off, and this says
-/// why. It shows only then.
+/// What keeps Peel from moving anything at all: the exclusions or History can't be read, or History can't be written.
+/// Exclusions not read yet are none of these, since they are read as Peel starts.
+enum MovesHeld: Equatable {
+ case exclusionsUnreadable
+ case historyUnreadable
+ case historyUnwritable
+
+ static func reason(exclusionsUnreadable: Bool, historyUnreadable: Bool, historyUnwritable: Bool) -> MovesHeld? {
+ if exclusionsUnreadable { return .exclusionsUnreadable }
+ if historyUnreadable { return .historyUnreadable }
+ return historyUnwritable ? .historyUnwritable : nil
+ }
+
+ @MainActor
+ static func reason(exclusions: ExclusionsStore, history: RemovalHistoryStore) -> MovesHeld? {
+ reason(
+ exclusionsUnreadable: exclusions.exclusions.isUnreadable, historyUnreadable: history.isUnreadable,
+ historyUnwritable: history.cannotBeWritten
+ )
+ }
+}
+
+/// Over a page that can move something to the Trash or put it back, while `MovesHeld` names a reason: nothing moves
+/// until it is gone, so the page's own button is off, and this says why. It shows only then.
struct RemovalsHeldBanner: View {
@Environment(ExclusionsStore.self) private var exclusions
@Environment(RemovalHistoryStore.self) private var history
@@ -12,7 +33,8 @@ struct RemovalsHeldBanner: View {
var isOnHistoryPage = false
var body: some View {
- if exclusions.exclusions.isUnreadable {
+ let held = MovesHeld.reason(exclusions: exclusions, history: history)
+ if held == .exclusionsUnreadable {
Notice(
title: Text("Peel couldn’t read your exclusions"),
detail: Text("Peel removes nothing and puts nothing back until you start the list over in Settings.")
@@ -21,7 +43,7 @@ struct RemovalsHeldBanner: View {
}
.padding(.vertical, 6)
.listRowSeparator(.hidden)
- } else if history.isUnreadable, !isOnHistoryPage {
+ } else if held == .historyUnreadable, !isOnHistoryPage {
Notice(
title: Text("Peel couldn’t read History"),
detail: Text("Peel removes nothing until you start History over, so that everything it moves can be put back.")
@@ -32,7 +54,7 @@ struct RemovalsHeldBanner: View {
}
.padding(.vertical, 6)
.listRowSeparator(.hidden)
- } else if history.cannotBeWritten {
+ } else if held == .historyUnwritable {
Notice(
title: Text("Peel can’t write History"),
detail: Text("The disk is full, or Peel’s folder can’t be written. Peel removes nothing until it can, so that everything it moves can be put back.")
diff --git a/PeelTests/MovesHeldTests.swift b/PeelTests/MovesHeldTests.swift
new file mode 100644
index 00000000..a8b85ee4
--- /dev/null
+++ b/PeelTests/MovesHeldTests.swift
@@ -0,0 +1,15 @@
+@testable import Peel
+import Testing
+
+struct MovesHeldTests {
+ @Test func namesWhatKeepsEveryMoveBack() {
+ func reason(_ exclusions: Bool, _ history: Bool, _ writing: Bool) -> MovesHeld? {
+ MovesHeld.reason(exclusionsUnreadable: exclusions, historyUnreadable: history, historyUnwritable: writing)
+ }
+
+ #expect(reason(false, false, false) == nil)
+ #expect(reason(true, true, true) == .exclusionsUnreadable)
+ #expect(reason(false, true, true) == .historyUnreadable)
+ #expect(reason(false, false, true) == .historyUnwritable)
+ }
+}