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.

Turn the Forget buttons off while every move is held

Țugui Dragoșfe3d8cff155e
diff --git a/Peel/Model/RemovalHistoryStore.swift b/Peel/Model/RemovalHistoryStore.swift
index 001d4043..0608304d 100644
--- a/Peel/Model/RemovalHistoryStore.swift
+++ b/Peel/Model/RemovalHistoryStore.swift
@@ -275,12 +275,14 @@ final class RemovalHistoryStore {
/// What the Edit menu shows, and nil when there is nothing to undo.
var undoTitle: String? { undoable?.title }
- /// Whether anything may move to the Trash or back now: never while the exclusions are not known or History can't
- /// be read.
- var mayMove: Bool {
- ExclusionsStore.shared.exclusions.isKnown && !isUnreadable
+ /// Why nothing may move to the Trash or back now: the exclusions are not known, or History can't be read.
+ var holdingReason: TrashFailure.Reason? {
+ guard ExclusionsStore.shared.exclusions.isKnown else { return .guarded(.exclusionsNotKnown) }
+ return isUnreadable ? .historyUnreadable : nil
}
+ var mayMove: Bool { holdingReason == nil }
+
/// Puts the last batch back. Nothing happens while another Put Back runs or none may, and the batch stays
/// undoable: `restore` takes one at a time and would drop this one without a word.
func undoLastRemoval() async {
diff --git a/Peel/Views/Homebrew/HomebrewDetailView.swift b/Peel/Views/Homebrew/HomebrewDetailView.swift
index 2d63758e..4e1276aa 100644
--- a/Peel/Views/Homebrew/HomebrewDetailView.swift
+++ b/Peel/Views/Homebrew/HomebrewDetailView.swift
@@ -5,6 +5,7 @@ struct HomebrewDetailView: View {
@Environment(HomebrewLibrary.self) private var homebrew
@Environment(AppLibrary.self) private var library
@Environment(ExclusionsStore.self) private var exclusions
+ @Environment(RemovalHistoryStore.self) private var history
@State private var isConfirmingUninstall = false
@State private var isConfirmingUpgrade = false
@State private var casksToForget: [HomebrewPackage]?
@@ -111,6 +112,8 @@ struct HomebrewDetailView: View {
if package.isMissingWhatItInstalled {
Button("Forget Cask") { casksToForget = [package] }
.buttonStyle(.borderedProminent)
+ .disabled(!history.mayMove)
+ .help(Text(verbatim: history.holdingReason?.explanation ?? ""))
} else if package.waitsForAnUpgrade {
if package.upgradeNeedsAnAdministrator || homebrew.overrides.contains(.cleansUp) {
let kind = package.kind == .cask ? "--cask" : "--formula"
diff --git a/Peel/Views/Homebrew/HomebrewList.swift b/Peel/Views/Homebrew/HomebrewList.swift
index 5b2b6a0f..8f56faea 100644
--- a/Peel/Views/Homebrew/HomebrewList.swift
+++ b/Peel/Views/Homebrew/HomebrewList.swift
@@ -3,6 +3,7 @@ import SwiftUI
struct HomebrewList: View {
@Environment(HomebrewLibrary.self) private var homebrew
+ @Environment(RemovalHistoryStore.self) private var history
@Environment(\.openSettings) private var openSettings
@State private var searchText = ""
@State private var isRescanning = false
@@ -464,7 +465,8 @@ struct HomebrewList: View {
.minimumTarget()
}
.buttonStyle(.borderless)
- .disabled(isBusy)
+ .disabled(isBusy || !history.mayMove)
+ .help(Text(verbatim: history.holdingReason?.explanation ?? ""))
}
}
}
diff --git a/Peel/Views/Packages/PackageDetailView.swift b/Peel/Views/Packages/PackageDetailView.swift
index 3b2a878f..8e82c195 100644
--- a/Peel/Views/Packages/PackageDetailView.swift
+++ b/Peel/Views/Packages/PackageDetailView.swift
@@ -64,7 +64,7 @@ struct PackageDetailView: View {
.minimumTarget()
}
.buttonStyle(.borderless)
- .disabled(!helper.canAct)
+ .disabled(!helper.canAct || !history.mayMove)
.help(helper.canAct ? Text("The receipt goes to the Trash. Files stay where they are.") : Text("Needs Peel’s helper. Settings says why it can’t act yet."))
}
}
diff --git a/Peel/Views/Settings/SavedSettingsSection.swift b/Peel/Views/Settings/SavedSettingsSection.swift
index 427dcb71..5b9686ff 100644
--- a/Peel/Views/Settings/SavedSettingsSection.swift
+++ b/Peel/Views/Settings/SavedSettingsSection.swift
@@ -80,7 +80,8 @@ struct SavedSettingsSection: View {
copyToTrash = copy
}
.labelStyle(.iconOnly)
- .help(Text("Move to Trash"))
+ .help(history.holdingReason.map { Text(verbatim: $0.explanation) } ?? Text("Move to Trash"))
+ .disabled(!history.mayMove)
}
.buttonStyle(.bordered)
.disabled(workingOn != nil)
diff --git a/Peel/Views/VendorNotes.swift b/Peel/Views/VendorNotes.swift
index 15cbb4c1..ab1e1c25 100644
--- a/Peel/Views/VendorNotes.swift
+++ b/Peel/Views/VendorNotes.swift
@@ -44,6 +44,7 @@ struct SystemExtensionNotice: View {
/// What an installer put outside the app, according to the receipt macOS kept.
struct PackageReceiptSection: View {
@Environment(HelperModel.self) private var helper
+ @Environment(RemovalHistoryStore.self) private var history
/// How many files are listed per receipt. The rest are counted, and the Package Receipts page lists them all.
private static let mostListed = 12
@@ -89,7 +90,7 @@ struct PackageReceiptSection: View {
}
.buttonStyle(.borderless)
// The page promises that an excluded app's files are left alone, its receipt included.
- .disabled(isForgetting || !helper.canAct || plan.isExcluded)
+ .disabled(isForgetting || !helper.canAct || plan.isExcluded || !history.mayMove)
.help(plan.isExcluded ? Text(.excludedApp) : helper.canAct ? Text("The receipt goes to the Trash. Files stay where they are.") : Text("Needs Peel’s helper. Settings says why it can’t act yet."))
}
if files.isEmpty {