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.

Offer the way back in an excluded row's Control-click menu

Țugui Dragoș067b8adc8d8a
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 5b3a1c60..df5bcfe3 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -36287,6 +36287,112 @@
}
}
},
+ "Excluded with “%@”" : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Vyloučeno spolu se složkou „%@“"
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Mit „%@“ ausgeschlossen"
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Excluido con “%@”"
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Exclu avec « %@ »"
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Escluso con “%@”"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "“%@”とともに除外済み"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "‘%@’과(와) 함께 제외됨"
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Uitgesloten met '%@'"
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Wykluczone wraz z „%@”"
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Excluído junto com “%@”"
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Exclus împreună cu „%@”"
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Исключено вместе с папкой «%@»"
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Undantagen med ”%@”"
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "“%@” ile birlikte hariç tutuldu"
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "У винятках разом із папкою «%@»"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "已随“%@”一起排除"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "已隨「%@」排除"
+ }
+ }
+ }
+ },
"Exclusions" : {
"localizations" : {
"cs" : {
@@ -53126,6 +53232,112 @@
}
}
},
+ "Include in Peel" : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Zahrnout do Peelu"
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "In Peel einbeziehen"
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Incluir en Peel"
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Inclure dans Peel"
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Includi in Peel"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peelに含める"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel에 포함"
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Neem op in Peel"
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Uwzględnij w Peel"
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Remover das Exclusões do Peel"
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Includeți în Peel"
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Включить в Peel"
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Inkludera i Peel"
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel’e Dahil Et"
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Вилучити з винятків у Peel"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "纳入Peel"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "重新納入Peel"
+ }
+ }
+ }
+ },
"Input Methods" : {
"localizations" : {
"cs" : {
@@ -90020,6 +90232,112 @@
}
}
},
+ "Open Exclusions in Settings…" : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Otevřít Výjimky v Nastavení…"
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "„Ausschlüsse“ in den Einstellungen öffnen …"
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Abrir Exclusiones en Ajustes…"
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ouvrir Exclusions dans les Réglages…"
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Apri “Esclusioni” nelle Impostazioni…"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "設定で“除外”を開く…"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "설정에서 제외 항목 열기…"
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Open 'Uitsluitingen' in Instellingen…"
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Otwórz Wykluczenia w Ustawieniach…"
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Abrir Exclusões nos Ajustes…"
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Deschideți Excluderi în Configurări…"
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Открыть «Исключения» в Настройках…"
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Öppna Undantag i Inställningar…"
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ayarlar’da Hariç Tutulanlar’ı Aç…"
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Відкрити «Винятки» в Параметрах…"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "在设置中打开排除项…"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "在「設定」中打開「排除項目」⋯"
+ }
+ }
+ }
+ },
"Open Finder" : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCore/Support/Exclusions.swift b/Packages/PeelCore/Sources/PeelCore/Support/Exclusions.swift
index ce07351c..ab9d58fb 100644
--- a/Packages/PeelCore/Sources/PeelCore/Support/Exclusions.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Support/Exclusions.swift
@@ -158,6 +158,31 @@ public struct Exclusions: Sendable, Codable, Hashable {
paths.flatMap { spellings(of: $0) }.map(PathComponents.of).filter { !$0.isEmpty }
}
+ /// What on the list excludes an item: the app's identifier and the entries for the item itself, which taking off
+ /// the list includes it again, and the excluded folders around it, which hold other things too.
+ public struct Reasons: Sendable, Hashable {
+ public let identifier: String?
+ public let paths: [URL]
+ public let folders: [URL]
+
+ public var isEmpty: Bool { identifier == nil && paths.isEmpty && folders.isEmpty }
+ }
+
+ /// `app` is the identifier of the app the item is, when it is one.
+ public func reasons(excluding url: URL, app: String?) -> Reasons {
+ let asked = Self.spellings(of: url).map(PathComponents.of)
+ let sorted = paths.sorted { $0.path(percentEncoded: false) < $1.path(percentEncoded: false) }
+ return Reasons(
+ identifier: app.flatMap { bundleIdentifiers.contains($0) ? $0 : nil },
+ paths: sorted.filter { Self.isSamePlace($0, url) },
+ folders: sorted.filter { entry in
+ Self.spellings(of: entry).map(PathComponents.of).contains { folder in
+ asked.contains { $0.count > folder.count && $0.starts(with: folder) }
+ }
+ }
+ )
+ }
+
public func excludes(bundleIdentifier: String) -> Bool {
bundleIdentifiers.contains(bundleIdentifier)
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ExclusionsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ExclusionsTests.swift
index ad74e693..4d987a7b 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/ExclusionsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/ExclusionsTests.swift
@@ -3,6 +3,27 @@ import Foundation
import Testing
struct ExclusionsTests {
+ @Test func saysWhichEntriesExcludeAnItem() {
+ let app = URL(filePath: "/Applications/Example.app", directoryHint: .isDirectory)
+ let folder = URL(filePath: "/Users/me/Projects", directoryHint: .isDirectory)
+ let project = folder.appending(path: "Site", directoryHint: .isDirectory)
+
+ let byIdentifier = Exclusions(bundleIdentifiers: ["org.example.app"]).reasons(excluding: app, app: "org.example.app")
+ #expect(byIdentifier == Exclusions.Reasons(identifier: "org.example.app", paths: [], folders: []))
+
+ let byPath = Exclusions(paths: [URL(filePath: "/Applications/Example.app/")]).reasons(excluding: app, app: nil)
+ #expect(byPath.paths.count == 1 && byPath.folders.isEmpty && byPath.identifier == nil)
+
+ let byFolder = Exclusions(paths: [folder]).reasons(excluding: project, app: nil)
+ #expect(byFolder == Exclusions.Reasons(identifier: nil, paths: [], folders: [folder]))
+
+ let both = Exclusions(paths: [folder, project], bundleIdentifiers: ["org.example.other"])
+ .reasons(excluding: project, app: nil)
+ #expect(both.paths == [project] && both.folders == [folder] && both.identifier == nil)
+
+ #expect(Exclusions(paths: [project]).reasons(excluding: folder, app: nil).isEmpty)
+ }
+
@Test func findsTheExcludedPlacesInsideAFolderOnce() {
let caches = URL(filePath: "/Users/x/Library/Caches", directoryHint: .isDirectory)
let exclusions = Exclusions(paths: [
diff --git a/Peel/Views/ItemMenu.swift b/Peel/Views/ItemMenu.swift
index ef9240a0..16aa5531 100644
--- a/Peel/Views/ItemMenu.swift
+++ b/Peel/Views/ItemMenu.swift
@@ -4,11 +4,12 @@ import SwiftUI
/// The Control-click menu of a row for one file, folder, or app Peel can move, the same on every page.
///
-/// Excluding adds the item to the list Settings keeps, where it can be removed again, and every tool stops
-/// offering it. An app is added by its identifier, as Settings does, so it stays excluded wherever it moves.
+/// Excluding adds the item to the list Settings keeps, and every tool stops offering it; an excluded item's menu
+/// takes it off again. An app is added by its identifier, as Settings does, so it stays excluded wherever it moves.
/// Excluding is off while the list can't be read, since adding to it then would start it over and drop what
/// it held, and for anything Settings refuses as too broad.
struct ItemMenu: View {
+ @Environment(\.openSettings) private var openSettings
let url: URL
/// The identifier of the app itself, when the row is one.
var appIdentifier: String?
@@ -30,6 +31,36 @@ struct ItemMenu: View {
NSPasteboard.general.setString(url.path(percentEncoded: false), forType: .string)
}
Divider()
+ if isExcluded {
+ wayBack
+ } else {
+ exclude
+ }
+ }
+
+ /// Takes off the list exactly what excludes the item. An excluded folder around it holds other things too, so
+ /// that one is named and left to Settings.
+ @ViewBuilder private var wayBack: some View {
+ let reasons = ExclusionsStore.shared.exclusions.reasons(excluding: url, app: appIdentifier)
+ if let folder = reasons.folders.first {
+ Text("Excluded with “\(folder.lastPathComponent)”")
+ Button("Open Exclusions in Settings…", systemImage: "gearshape") {
+ SettingsPane.exclusions.open(with: openSettings)
+ }
+ } else {
+ Button("Include in Peel", systemImage: "hand.raised.slash") {
+ Task {
+ if let identifier = reasons.identifier {
+ await ExclusionsStore.shared.remove(bundleIdentifiers: [identifier])
+ }
+ await ExclusionsStore.shared.remove(paths: reasons.paths)
+ }
+ }
+ .disabled(ExclusionsStore.shared.exclusions.isUnreadable || reasons.isEmpty)
+ }
+ }
+
+ private var exclude: some View {
Button("Exclude from Peel", systemImage: "hand.raised") {
Task {
if let appIdentifier {
@@ -40,8 +71,7 @@ struct ItemMenu: View {
}
}
.disabled(
- isExcluded || ExclusionsStore.shared.exclusions.isUnreadable
- || (appIdentifier == nil && ExclusionsStore.isTooBroad(url))
+ ExclusionsStore.shared.exclusions.isUnreadable || (appIdentifier == nil && ExclusionsStore.isTooBroad(url))
)
}
}