Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
Choose an app from a short list with a search field
Țugui Dragoș00bcc6f958fd
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 009b4981..3a23fbcc 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -180,6 +180,8 @@ its changes the way [Keep a Changelog](https://keepachangelog.com/) suggests.- Sidebar is the first section of General.- App Folders and Exclusions add and remove with `+` and `-` at the foot of each list, and the Helper tab keeps itsstate and its buttons on one row.+- Exclusions' `+` for apps opens a short list with a search field, rather than a menu that ran to the edge of the+ screen.#### Applications@@ -197,6 +199,8 @@ its changes the way [Keep a Changelog](https://keepachangelog.com/) suggests.#### Orphaned Files- A group holding an audio plug-in reads unsure, since music apps load it on their own.+- This Belongs To… opens a short list of apps with a search field, rather than a menu that ran to the edge of the+ screen.#### Intel Softwarediff --git a/GUIDE.md b/GUIDE.mdindex 16b25d7b..4f751666 100644--- a/GUIDE.md+++ b/GUIDE.md@@ -363,7 +363,7 @@ It sets up the command line as well:page the folders named exactly with its identifier, such as its caches, and an update it downloaded; to keep itsother files, such as plug-ins or a folder named after it, exclude them too. Add them inSettings > Exclusions, or Control-click a row and choose Exclude from Peel. In Orphaned Files, Control-click a- group and choose This Belongs To, and Peel stops listing it while the app you chose is installed.+ group and choose This Belongs To…, and Peel stops listing it while the app you chose is installed.## Work your waydiff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstringsindex 3751d056..ef5f5b5e 100644--- a/Localization/Peel/Localizable.xcstrings+++ b/Localization/Peel/Localizable.xcstrings@@ -14392,108 +14392,108 @@}}},- "Add App" : {+ "Add App…" : {"localizations" : {"cs" : {"stringUnit" : {"state" : "translated",- "value" : "Přidat aplikaci"+ "value" : "Přidat aplikaci…"}},"de" : {"stringUnit" : {"state" : "translated",- "value" : "App hinzufügen"+ "value" : "App hinzufügen …"}},"es" : {"stringUnit" : {"state" : "translated",- "value" : "Añadir app"+ "value" : "Añadir app…"}},"fr" : {"stringUnit" : {"state" : "translated",- "value" : "Ajouter une app"+ "value" : "Ajouter une app…"}},"it" : {"stringUnit" : {"state" : "translated",- "value" : "Aggiungi app"+ "value" : "Aggiungi app…"}},"ja" : {"stringUnit" : {"state" : "translated",- "value" : "アプリを追加"+ "value" : "アプリを追加…"}},"ko" : {"stringUnit" : {"state" : "translated",- "value" : "앱 추가"+ "value" : "앱 추가…"}},"nl" : {"stringUnit" : {"state" : "translated",- "value" : "Voeg app toe"+ "value" : "Voeg app toe…"}},"pl" : {"stringUnit" : {"state" : "translated",- "value" : "Dodaj aplikację"+ "value" : "Dodaj aplikację…"}},"pt" : {"stringUnit" : {"state" : "translated",- "value" : "Adicionar App"+ "value" : "Adicionar App…"}},"ro" : {"stringUnit" : {"state" : "translated",- "value" : "Adăugați o aplicație"+ "value" : "Adăugați o aplicație…"}},"ru" : {"stringUnit" : {"state" : "translated",- "value" : "Добавить приложение"+ "value" : "Добавить приложение…"}},"sv" : {"stringUnit" : {"state" : "translated",- "value" : "Lägg till app"+ "value" : "Lägg till app…"}},"tr" : {"stringUnit" : {"state" : "translated",- "value" : "Uygulama Ekle"+ "value" : "Uygulama Ekle…"}},"uk" : {"stringUnit" : {"state" : "translated",- "value" : "Додати програму"+ "value" : "Додати програму…"}},"zh-Hans" : {"stringUnit" : {"state" : "translated",- "value" : "添加App"+ "value" : "添加App…"}},"zh-Hant" : {"stringUnit" : {"state" : "translated",- "value" : "加入App"+ "value" : "加入App⋯"}}}@@ -203562,6 +203562,112 @@}}},+ "This Belongs To…" : {+ "localizations" : {+ "cs" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Patří aplikaci…"+ }+ },+ "de" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Gehört zu …"+ }+ },+ "es" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Pertenece a…"+ }+ },+ "fr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Appartient à…"+ }+ },+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Appartiene a…"+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "所属先のアプリ…"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "소유한 앱 지정…"+ }+ },+ "nl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Dit hoort bij…"+ }+ },+ "pl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Należy do…"+ }+ },+ "pt" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Isto Pertence a…"+ }+ },+ "ro" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Aparține aplicației…"+ }+ },+ "ru" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Принадлежит приложению…"+ }+ },+ "sv" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Det här hör till…"+ }+ },+ "tr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Şuna Ait…"+ }+ },+ "uk" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Належить програмі…"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "归属于…"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "屬於⋯"+ }+ }+ }+ },"This Java runtime is Intel only, so it needs Rosetta to run. If its maker offers one for Apple silicon, install that one instead." : {"localizations" : {"cs" : {diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/AppListFilter.swift b/Packages/PeelCore/Sources/PeelCore/Apps/AppListFilter.swiftindex de5ce429..5702f24b 100644--- a/Packages/PeelCore/Sources/PeelCore/Apps/AppListFilter.swift+++ b/Packages/PeelCore/Sources/PeelCore/Apps/AppListFilter.swift@@ -32,13 +32,16 @@ public struct AppListFilter: Sendable, Hashable {public func keeps(_ app: InstalledApp, source: AppSource, developer appsDeveloper: String?, isUnused: Bool) -> Bool {- if !text.isEmpty, !app.names.contains(where: { SearchText.matches($0, text) }),- !(app.bundleIdentifier.map { SearchText.matches($0, text) } ?? false),- !(appsDeveloper.map { SearchText.matches($0, text) } ?? false) {- return false- }+ guard Self.matches(app, text: text, developer: appsDeveloper) else { return false }if !sources.isEmpty, !sources.contains(source) { return false }if let developer, appsDeveloper != developer { return false }return !onlyUnused || isUnused}++ /// Whether the words typed name the app, by any of its names, its identifier, or who makes it.+ public static func matches(_ app: InstalledApp, text: String, developer: String?) -> Bool {+ text.isEmpty || app.names.contains { SearchText.matches($0, text) }+ || (app.bundleIdentifier.map { SearchText.matches($0, text) } ?? false)+ || (developer.map { SearchText.matches($0, text) } ?? false)+ }}diff --git a/Packages/PeelCore/Sources/PeelCore/Support/ListHighlight.swift b/Packages/PeelCore/Sources/PeelCore/Support/ListHighlight.swiftnew file mode 100644index 00000000..080dd96e--- /dev/null+++ b/Packages/PeelCore/Sources/PeelCore/Support/ListHighlight.swift@@ -0,0 +1,10 @@+/// Which row of a list the arrow keys leave highlighted, while the focus stays in the search field above it.+public enum ListHighlight {+ public static func moved<ID: Equatable>(from current: ID?, by step: Int, among rows: [ID]) -> ID? {+ guard !rows.isEmpty else { return nil }+ guard let current, let index = rows.firstIndex(of: current) else {+ return step > 0 ? rows.first : rows.last+ }+ return rows[min(max(index + step, 0), rows.count - 1)]+ }+}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ListHighlightTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ListHighlightTests.swiftnew file mode 100644index 00000000..621cd27a--- /dev/null+++ b/Packages/PeelCore/Tests/PeelCoreTests/ListHighlightTests.swift@@ -0,0 +1,28 @@+import Testing+@testable import PeelCore++struct ListHighlightTests {+ @Test func downFromNothingIsTheFirstRowAndUpIsTheLast() {+ #expect(ListHighlight.moved(from: nil, by: 1, among: ["a", "b", "c"]) == "a")+ #expect(ListHighlight.moved(from: nil, by: -1, among: ["a", "b", "c"]) == "c")+ }++ @Test func aStepMovesOneRow() {+ #expect(ListHighlight.moved(from: "a", by: 1, among: ["a", "b", "c"]) == "b")+ #expect(ListHighlight.moved(from: "c", by: -1, among: ["a", "b", "c"]) == "b")+ }++ @Test func theEndsOfTheListHold() {+ #expect(ListHighlight.moved(from: "c", by: 1, among: ["a", "b", "c"]) == "c")+ #expect(ListHighlight.moved(from: "a", by: -1, among: ["a", "b", "c"]) == "a")+ }++ @Test func aRowASearchTookAwayStartsOver() {+ #expect(ListHighlight.moved(from: "z", by: 1, among: ["a", "b"]) == "a")+ #expect(ListHighlight.moved(from: "z", by: -1, among: ["a", "b"]) == "b")+ }++ @Test func noRowsLeaveNothingHighlighted() {+ #expect(ListHighlight.moved(from: "a", by: 1, among: [String]()) == nil)+ }+}diff --git a/Peel/Views/AppChooser.swift b/Peel/Views/AppChooser.swiftnew file mode 100644index 00000000..591511af--- /dev/null+++ b/Peel/Views/AppChooser.swift@@ -0,0 +1,130 @@+import AppKit+import PeelCore+import SwiftUI++/// A short list of apps to choose one from, under a search field. A menu of every app would run to the screen's edge,+/// and macOS gives a menu no shorter limit, so this list shows a few rows and scrolls past them.+struct AppChooser: View {+ private static let visibleRows = 8+ private static let rowHeight: CGFloat = 28++ @Environment(AppLibrary.self) private var library+ let apps: [InstalledApp]+ let choose: (InstalledApp) -> Void++ @State private var search = ""+ @State private var highlighted: InstalledApp.ID?++ private var shown: [InstalledApp] {+ apps.filter { AppListFilter.matches($0, text: search, developer: library.developer(of: $0)) }+ .sorted { $0.name.localizedStandardCompare($1.name) == .orderedAscending }+ }++ var body: some View {+ let shown = shown+ ScrollViewReader { proxy in+ VStack(spacing: 8) {+ SearchBox(text: $search, prompt: String(localized: "Search Applications")) { step in+ highlighted = ListHighlight.moved(from: highlighted, by: step, among: shown.map(\.id))+ if let highlighted { proxy.scrollTo(highlighted) }+ } onReturn: {+ if let app = shown.first(where: { $0.id == highlighted }) { choose(app) }+ }+ ScrollView {+ LazyVStack(spacing: 0) {+ ForEach(shown) { row($0) }+ }+ }+ .scrollBounceBehavior(.basedOnSize)+ .frame(height: CGFloat(min(max(shown.count, 1), Self.visibleRows)) * Self.rowHeight)+ .overlay {+ if shown.isEmpty {+ Text("No Results")+ .foregroundStyle(.secondary)+ }+ }+ }+ }+ .onChange(of: search) {+ highlighted = search.isEmpty ? nil : self.shown.first?.id+ }+ }++ private func row(_ app: InstalledApp) -> some View {+ Button {+ choose(app)+ } label: {+ HStack(spacing: 8) {+ AppIcon(url: app.url)+ .frame(width: 20, height: 20)+ Text(verbatim: app.name)+ .lineLimit(1)+ .truncationMode(.middle)+ Spacer(minLength: 0)+ }+ .padding(.horizontal, 6)+ .frame(height: Self.rowHeight)+ .contentShape(.rect)+ }+ .buttonStyle(.plain)+ .background(.quaternary.opacity(highlighted == app.id ? 1 : 0), in: .rect(cornerRadius: 6))+ .onHover { if $0 { highlighted = app.id } }+ .help(Text(verbatim: app.url.abbreviatedPath))+ }+}++/// macOS's own search field, holding the focus so typing goes on filtering, while its arrow keys move through the list+/// under it and its Return chooses.+private struct SearchBox: NSViewRepresentable {+ @Binding var text: String+ let prompt: String+ let onMove: (Int) -> Void+ let onReturn: () -> Void++ func makeCoordinator() -> Coordinator { Coordinator(self) }++ func makeNSView(context: Context) -> FocusedSearchField {+ let field = FocusedSearchField()+ field.placeholderString = prompt+ field.focusRingType = .none+ field.delegate = context.coordinator+ return field+ }++ func updateNSView(_ field: FocusedSearchField, context: Context) {+ context.coordinator.parent = self+ if field.stringValue != text { field.stringValue = text }+ }++ final class Coordinator: NSObject, NSSearchFieldDelegate {+ var parent: SearchBox++ init(_ parent: SearchBox) {+ self.parent = parent+ }++ func controlTextDidChange(_ notification: Notification) {+ if let field = notification.object as? NSSearchField { parent.text = field.stringValue }+ }++ func control(_ control: NSControl, textView: NSTextView, doCommandBy selector: Selector) -> Bool {+ switch selector {+ case #selector(NSResponder.moveDown(_:)): parent.onMove(1)+ case #selector(NSResponder.moveUp(_:)): parent.onMove(-1)+ case #selector(NSResponder.insertNewline(_:)): parent.onReturn()+ default: return false+ }+ return true+ }+ }+}++private final class FocusedSearchField: NSSearchField {+ override func viewDidMoveToWindow() {+ super.viewDidMoveToWindow()+ // Once the window is set up: focused before its first layout, the field draws its prompt under what is typed.+ DispatchQueue.main.async { [weak self] in+ self?.window?.makeFirstResponder(self)+ }+ }+}diff --git a/Peel/Views/Orphans/OrphanList.swift b/Peel/Views/Orphans/OrphanList.swiftindex c5ec5420..4c7552f8 100644--- a/Peel/Views/Orphans/OrphanList.swift+++ b/Peel/Views/Orphans/OrphanList.swift@@ -9,6 +9,7 @@ struct OrphanList: View {@State private var searchText = ""@State private var isRescanning = false@State private var notGivenTo: String?+ @State private var groupToGive: OrphanGroup?var body: some View {@Bindable var orphans = orphans@@ -29,16 +30,7 @@ struct OrphanList: View {.contextMenu(forSelectionType: OrphanPage.self) { pages inif pages.count == 1, case .group(let id)? = pages.first,let group = filtered.first(where: { $0.id == id }) {- Menu("This Belongs To") {- // What a group belongs to is kept by the app's identifier.- let apps = library.apps.filter { $0.bundleIdentifier != nil }- .sorted { $0.name.localizedStandardCompare($1.name) == .orderedAscending }- ForEach(apps) { app in- Button(app.name) {- if !orphans.give(group, to: app) { notGivenTo = app.name }- }- }- }+ Button("This Belongs To…") { groupToGive = group }}}.scanState(phase(filtered, forAnAdministrator), isRescanning: isRescanning, scan: orphans.scanRun) {@@ -151,6 +143,31 @@ struct OrphanList: View {}.rescanOnExclusionChange("OrphanList") { await orphans.refresh(from: library) }.rescanAfterPutBack(.orphans) { await orphans.refresh(from: library) }+ .sheet(item: $groupToGive) { group in+ VStack(alignment: .leading, spacing: 12) {+ VStack(alignment: .leading, spacing: 2) {+ Text("This Belongs To")+ .font(.headline)+ Text(verbatim: group.title)+ .font(.callout)+ .foregroundStyle(.secondary)+ .lineLimit(1)+ .truncationMode(.middle)+ }+ // What a group belongs to is kept by the app's identifier.+ AppChooser(apps: library.apps.filter { $0.bundleIdentifier != nil }) { app in+ groupToGive = nil+ if !orphans.give(group, to: app) { notGivenTo = app.name }+ }+ HStack {+ Spacer()+ Button("Cancel", role: .cancel) { groupToGive = nil }+ .keyboardShortcut(.cancelAction)+ }+ }+ .frame(width: 410)+ .padding(20)+ }.alert("Peel couldn’t save that these files belong to \(notGivenTo ?? "")",isPresented: Binding(get: { notGivenTo != nil }, set: { if !$0 { notGivenTo = nil } })diff --git a/Peel/Views/Settings/ExclusionsSettingsView.swift b/Peel/Views/Settings/ExclusionsSettingsView.swiftindex 508d13bf..440877f7 100644--- a/Peel/Views/Settings/ExclusionsSettingsView.swift+++ b/Peel/Views/Settings/ExclusionsSettingsView.swift@@ -7,6 +7,7 @@ struct ExclusionsSettingsView: View {@Environment(AppLibrary.self) private var library@Environment(OrphanLibrary.self) private var orphans@State private var isChoosingPaths = false+ @State private var isChoosingApp = false@State private var refused: [String] = []@State private var selectedPaths: Set<URL> = []@State private var selectedApps: Set<String> = []@@ -132,30 +133,30 @@ struct ExclusionsSettingsView: View {}}ListEditingButtons {- Menu {+ Button("Add App…", systemImage: "plus") {+ isChoosingApp = true+ }+ .help(Text("Add App…"))+ .popover(isPresented: $isChoosingApp, arrowEdge: .bottom) {// An app with no identifier is left alone by where it is, as its Control-click menu does.- ForEach(- library.apps.filter { app in+ AppChooser(+ apps: library.apps.filter { app inapp.bundleIdentifier.map { !exclusions.exclusions.excludes(bundleIdentifier: $0) }?? !exclusions.exclusions.excludes(app.url)}) { app in- Button(app.name) {- Task {- if let identifier = app.bundleIdentifier {- await exclusions.add(bundleIdentifier: identifier)- } else {- await exclusions.add(paths: [app.url])- }+ isChoosingApp = false+ Task {+ if let identifier = app.bundleIdentifier {+ await exclusions.add(bundleIdentifier: identifier)+ } else {+ await exclusions.add(paths: [app.url])}}}- } label: {- Label("Add App", systemImage: "plus")+ .frame(width: 280)+ .padding(10)}- .menuStyle(.button)- .fixedSize()- .help(Text("Add App"))Button("Remove", systemImage: "minus") {let removed = selectedAppsselectedApps = []