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.

Duplicates' settings and File Search's filters in popovers, File Search in the list and detail shape

Țugui Dragoș576876637337
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 14f7a9fc..cfa92c07 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -16158,6 +16158,112 @@
}
}
},
+ "Choose a file to see where it is." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Zvolte soubor a uvidíte, kde se nachází."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Wähle eine Datei, um zu sehen, wo sie liegt."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Elige un archivo para ver dónde está."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Choisissez un fichier pour voir où il se trouve."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Scegli un file per vedere dove si trova."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "ファイルを選ぶと、その場所が表示されます。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "파일을 선택하면 위치를 볼 수 있습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Kies een bestand om te zien waar het staat."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Wybierz plik, aby zobaczyć, gdzie się znajduje."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Escolha um arquivo para ver onde ele está."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Alegeți un fișier pentru a vedea unde se află."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Выберите файл, чтобы узнать, где он находится."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Välj en fil för att se var den finns."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nerede olduğunu görmek için bir dosya seçin."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Виберіть файл, щоб побачити, де він розташований."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "选取一个文件,查看它所在的位置。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "選擇一個檔案以查看其位置。"
+ }
+ }
+ }
+ },
"Choose a folder in your home folder, /Users/Shared, or a disk Peel can write to. iCloud Drive, app data, the Music and TV apps’ media folders, and system folders aren’t scanned.\n\n%@" : {
"localizations" : {
"cs" : {
@@ -88947,6 +89053,112 @@
}
}
},
+ "Scan Settings" : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nastavení prohledávání"
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Scan-Einstellungen"
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ajustes de análisis"
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Réglages d’analyse"
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Impostazioni dell’analisi"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "スキャン設定"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "스캔 설정"
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Scaninstellingen"
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ustawienia skanowania"
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ajustes de Análise"
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Configurări scanare"
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Настройки сканирования"
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Skanningsinställningar"
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Tarama Ayarları"
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Параметри сканування"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "扫描设置"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "掃描設定"
+ }
+ }
+ }
+ },
"Scan Stopped" : {
"localizations" : {
"cs" : {
diff --git a/Peel/Model/DuplicateLibrary.swift b/Peel/Model/DuplicateLibrary.swift
index 425fb1a6..fb5a766a 100644
--- a/Peel/Model/DuplicateLibrary.swift
+++ b/Peel/Model/DuplicateLibrary.swift
@@ -102,7 +102,7 @@ final class DuplicateLibrary {
scanTask = Task { await runScan(current) }
}
- func stopScan() {
+ func stop() {
scanTask?.cancel()
}
@@ -224,3 +224,7 @@ private extension DuplicateScan {
}
}
}
+
+extension DuplicateLibrary: StoppableWork {
+ var isRunning: Bool { isScanning }
+}
diff --git a/Peel/Model/FileSearchLibrary.swift b/Peel/Model/FileSearchLibrary.swift
index 2b46a926..9a08d314 100644
--- a/Peel/Model/FileSearchLibrary.swift
+++ b/Peel/Model/FileSearchLibrary.swift
@@ -10,6 +10,8 @@ final class FileSearchLibrary {
private(set) var isSearching = false
private(set) var isRemoving = false
var selectedURLs: Set<URL> = []
+ /// The file the detail shows, chosen in the list. Checking a file for the Trash is `selectedURLs`, apart.
+ var chosen: URL?
/// The files Select All selects: not the ones that need an administrator, and not the ones an app keeps
/// for itself, which stay listed with the reason beside them.
private(set) var selectableURLs: Set<URL> = []
@@ -22,6 +24,10 @@ final class FileSearchLibrary {
selectedURLs.reduce(0) { $0 + (sizes[$1] ?? 0) }
}
+ var chosenFile: FoundFile? {
+ results?.files.first { $0.url == chosen }
+ }
+
func search() async {
generation += 1
let current = generation
diff --git a/Peel/Views/ContentView.swift b/Peel/Views/ContentView.swift
index 38a82032..efd0f7a3 100644
--- a/Peel/Views/ContentView.swift
+++ b/Peel/Views/ContentView.swift
@@ -11,6 +11,7 @@ struct ContentView: View {
@Environment(PackageLibrary.self) private var packages
@Environment(DeveloperLibrary.self) private var developer
@Environment(DuplicateLibrary.self) private var duplicates
+ @Environment(FileSearchLibrary.self) private var fileSearch
@Environment(PluginLibrary.self) private var plugins
@Environment(HomebrewLibrary.self) private var homebrew
@Environment(RemovalHistoryStore.self) private var history
@@ -246,7 +247,7 @@ struct ContentView: View {
case .cloud:
EmptyView()
case .fileSearch:
- FileSearchForm()
+ FileSearchList()
.listColumn()
case .backgroundItems:
BackgroundItemList()
@@ -301,7 +302,7 @@ struct ContentView: View {
case .cloud:
EmptyView()
case .fileSearch:
- FileSearchResultsView()
+ fileSearchDetail
case .backgroundItems:
backgroundItemDetail
case .packages:
@@ -356,9 +357,7 @@ struct ContentView: View {
@ViewBuilder
private var duplicateDetail: some View {
- if duplicates.isScanning {
- DuplicateScanProgressView()
- } else if let group = duplicates.selectedFolderGroup {
+ if let group = duplicates.selectedFolderGroup {
DuplicateFolderGroupView(group: group)
.id(group.id)
} else if let group = duplicates.selectedGroup {
@@ -367,11 +366,17 @@ struct ContentView: View {
} else if let scan = duplicates.scan, !(scan.groups.isEmpty && scan.folderGroups.isEmpty) {
DuplicateSummaryView(scan: scan)
} else {
- DetailPlaceholder(
- title: "Find Duplicate Files",
- systemImage: "doc.on.doc",
- description: "Choose folders and scan. Peel compares contents, so only exact copies are found, folders included."
- )
+ DetailPlaceholder(title: Tool.duplicates.title, systemImage: Tool.duplicates.systemImage, description: nil)
+ }
+ }
+
+ @ViewBuilder
+ private var fileSearchDetail: some View {
+ if let file = fileSearch.chosenFile {
+ FileSearchFileView(file: file)
+ .id(file.id)
+ } else {
+ DetailPlaceholder(tool: .fileSearch, summary: fileSearch.summary, instruction: "Choose a file to see where it is.")
}
}
diff --git a/Peel/Views/Duplicates/DuplicateList.swift b/Peel/Views/Duplicates/DuplicateList.swift
index e432f890..6d8f1034 100644
--- a/Peel/Views/Duplicates/DuplicateList.swift
+++ b/Peel/Views/Duplicates/DuplicateList.swift
@@ -7,6 +7,8 @@ struct DuplicateList: View {
@Environment(ExclusionsStore.self) private var exclusions
@State private var searchText = ""
@State private var isConfirmingNewScan = false
+ @State private var isShowingSettings = false
+ @State private var isStartingScan = false
var body: some View {
@Bindable var duplicates = duplicates
@@ -57,8 +59,18 @@ struct DuplicateList: View {
)
}
}
+ } else if duplicates.isScanning {
+ DuplicateScanProgressView()
+ .centeredOnColumn()
} else {
- DuplicateScanForm()
+ ContentUnavailableView {
+ Label("Find Duplicate Files", systemImage: "doc.on.doc")
+ } description: {
+ Text("Choose folders and scan. Peel compares contents, so only exact copies are found, folders included.")
+ } actions: {
+ Button("Scan Settings") { isShowingSettings = true }
+ }
+ .centeredOnColumn()
}
}
.fadesInColumn(on: duplicates.scan == nil)
@@ -69,18 +81,28 @@ struct DuplicateList: View {
// column gets no title bar section of its own, and the dividers between columns stop below the title bar.
.toolbar {
ToolbarItem {
- Button("New Scan", systemImage: "arrow.uturn.backward") {
- if let scan = duplicates.scan, !scan.groups.isEmpty || !scan.folderGroups.isEmpty {
- isConfirmingNewScan = true
- } else {
- duplicates.clearResults()
+ Button("Scan Settings", systemImage: "slider.horizontal.3") { isShowingSettings = true }
+ .help(Text("Scan Settings"))
+ .popover(isPresented: $isShowingSettings, arrowEdge: .bottom) {
+ DuplicateScanForm {
+ isShowingSettings = false
+ requestScan()
+ }
}
+ }
+ ToolbarItem {
+ RescanButton(
+ isRunning: $isStartingScan,
+ isDisabled: duplicates.folders.isEmpty || duplicates.isRemoving,
+ title: "Scan",
+ scan: duplicates
+ ) {
+ requestScan()
}
- .disabled(duplicates.scan == nil || duplicates.isRemoving)
}
}
.confirmationDialog("Start a new scan?", isPresented: $isConfirmingNewScan) {
- Button("New Scan") { duplicates.clearResults() }
+ Button("New Scan") { duplicates.startScan() }
Button("Cancel", role: .cancel) {}
} message: {
Text("The list of duplicates and your selection are cleared. No files are moved.")
@@ -89,6 +111,15 @@ struct DuplicateList: View {
.navigationTitle(Text(Tool.duplicates.title))
}
+ /// A new scan clears what the last one found, so it asks first when there is something to lose.
+ private func requestScan() {
+ if let scan = duplicates.scan, !scan.groups.isEmpty || !scan.folderGroups.isEmpty {
+ isConfirmingNewScan = true
+ } else {
+ duplicates.startScan()
+ }
+ }
+
private func folderRows(_ groups: [DuplicateFolderGroup]) -> some View {
ForEach(groups) { group in
DuplicateFolderGroupRow(group: group)
diff --git a/Peel/Views/Duplicates/DuplicateScanForm.swift b/Peel/Views/Duplicates/DuplicateScanForm.swift
index 2f6a6d72..5beecb6e 100644
--- a/Peel/Views/Duplicates/DuplicateScanForm.swift
+++ b/Peel/Views/Duplicates/DuplicateScanForm.swift
@@ -2,76 +2,66 @@ import PeelCore
import SwiftUI
import UniformTypeIdentifiers
+/// What a scan looks at, in a popover from the toolbar, so the settings can change without costing the results:
+/// they apply to the next scan.
struct DuplicateScanForm: View {
private static let sizes: [Int64] = [100_000, 1_000_000, 10_000_000, 100_000_000]
@Environment(DuplicateLibrary.self) private var duplicates
@State private var isChoosingFolders = false
@State private var rejectedFolders: [URL] = []
+ let onScan: () -> Void
var body: some View {
@Bindable var duplicates = duplicates
- Form {
- Section {
- // Only the rows are disabled, so the note beside the Folders heading still opens during a scan.
- Group {
- ForEach(duplicates.folders, id: \.self) { folder in
- FolderRow(folder: folder)
- }
- Button {
- isChoosingFolders = true
- } label: {
- Label("Add Folder…", systemImage: "plus")
- .minimumTarget()
+ VStack(spacing: 0) {
+ Form {
+ Section {
+ // Only the rows are disabled, so the note beside the Folders heading still opens during a scan.
+ Group {
+ ForEach(duplicates.folders, id: \.self) { folder in
+ FolderRow(folder: folder)
+ }
+ Button {
+ isChoosingFolders = true
+ } label: {
+ Label("Add Folder…", systemImage: "plus")
+ .minimumTarget()
+ }
+ .buttonStyle(.borderless)
}
- .buttonStyle(.borderless)
+ .disabled(duplicates.isScanning)
+ } header: {
+ heading("Folders", "Peel compares files by their full contents. A folder is a copy only when every file in it matches, hidden ones included. Repositories (Git, Mercurial, Subversion), projects with a build file such as package.json or Cargo.toml, node_modules, and libraries such as Photos and Music are left alone, and an app is never offered on its own. A build file at the top of a folder you chose doesn’t make it a project.")
}
- .disabled(duplicates.isScanning)
- } header: {
- heading("Folders", "Peel compares files by their full contents. A folder is a copy only when every file in it matches, hidden ones included. Repositories (Git, Mercurial, Subversion), projects with a build file such as package.json or Cargo.toml, node_modules, and libraries such as Photos and Music are left alone, and an app is never offered on its own. A build file at the top of a folder you chose doesn’t make it a project.")
- }
- Section {
- Picker("Kind", selection: $duplicates.kind) {
- ForEach(FileKind.allCases, id: \.self) { kind in
- Text(kind.title).tag(kind)
- }
- }
- Picker("Size", selection: $duplicates.minimumSize) {
- Text("Any size").tag(Int64(1))
- ForEach(Self.sizes, id: \.self) { size in
- Text("At least \(size.byteCount)").tag(size)
- }
- }
- }
- .disabled(duplicates.isScanning)
- }
- .formStyle(.grouped)
- .safeAreaBar(edge: .bottom) {
- // Scan is disabled as soon as scanning starts, so a second click can't start another scan. The
- // switch to Stop follows the `Busy` timing.
- BusyShown(isBusy: duplicates.isScanning) { isShown in
- Group {
- if isShown {
- Button("Stop", systemImage: "stop.fill") {
- duplicates.stopScan()
+ Section {
+ Picker("Kind", selection: $duplicates.kind) {
+ ForEach(FileKind.allCases, id: \.self) { kind in
+ Text(kind.title).tag(kind)
}
- .buttonStyle(.glass)
- .controlSize(.extraLarge)
- } else {
- Button("Scan", systemImage: "magnifyingglass") {
- duplicates.startScan()
+ }
+ Picker("Size", selection: $duplicates.minimumSize) {
+ Text("Any size").tag(Int64(1))
+ ForEach(Self.sizes, id: \.self) { size in
+ Text("At least \(size.byteCount)").tag(size)
}
- .buttonStyle(.glassProminent)
- .controlSize(.extraLarge)
- .disabled(duplicates.folders.isEmpty || duplicates.isScanning)
}
}
- .motion(value: isShown)
+ .disabled(duplicates.isScanning)
+ }
+ .formStyle(.grouped)
+ HStack {
+ Spacer()
+ Button("Scan", action: onScan)
+ .buttonStyle(.borderedProminent)
+ .keyboardShortcut(.defaultAction)
+ .disabled(duplicates.folders.isEmpty || duplicates.isScanning)
}
- .padding(.bottom, 16)
+ .padding([.horizontal, .bottom], 20)
}
+ .frame(width: 420, height: 460)
.fileImporter(isPresented: $isChoosingFolders, allowedContentTypes: [.folder], allowsMultipleSelection: true) { result in
guard case .success(let urls) = result else { return }
rejectedFolders = duplicates.add(urls)
diff --git a/Peel/Views/FileSearch/FileSearchFileView.swift b/Peel/Views/FileSearch/FileSearchFileView.swift
new file mode 100644
index 00000000..e57f1228
--- /dev/null
+++ b/Peel/Views/FileSearch/FileSearchFileView.swift
@@ -0,0 +1,66 @@
+import AppKit
+import PeelCore
+import SwiftUI
+
+/// One file a search found: where it is and what Peel knows about moving it.
+struct FileSearchFileView: View {
+ let file: FoundFile
+
+ var body: some View {
+ Form {
+ Section {
+ HStack(alignment: .center, spacing: 18) {
+ AppIcon(url: file.url)
+ .frame(width: 64, height: 64)
+ Text(verbatim: file.url.lastPathComponent)
+ .font(.title.bold())
+ .titleLine()
+ .help(Text(verbatim: file.url.lastPathComponent))
+ Spacer(minLength: 0)
+ }
+ .padding(.vertical, 8)
+ .listRowSeparator(.hidden)
+ }
+
+ Section {
+ LabeledContent("Where") {
+ Text(verbatim: file.url.abbreviatedPath)
+ .textSelection(.enabled)
+ .help(Text(verbatim: file.url.path(percentEncoded: false)))
+ }
+ .labeledContentStyle(.oneLine)
+ LabeledContent("Size") {
+ Text(file.size.byteCount).monospacedDigit()
+ }
+ LabeledContent("Modified") {
+ Text(file.modificationDate, format: .relative(presentation: .named))
+ }
+ if file.belongsToAnApp {
+ Text("An app keeps this in its Library folder, and may be using it right now.")
+ .font(.callout)
+ .foregroundStyle(.secondary)
+ }
+ if file.requiresPrivileges {
+ Text("Needs administrator access")
+ .font(.callout)
+ .foregroundStyle(.secondary)
+ }
+ } header: {
+ Text("Details")
+ }
+
+ Section {
+ HStack {
+ Spacer()
+ Button("Show in Finder", systemImage: "folder") {
+ NSWorkspace.shared.activateFileViewerSelecting([file.url])
+ }
+ Spacer()
+ }
+ }
+ }
+ .formStyle(.grouped)
+ .navigationTitle(Text(verbatim: file.url.lastPathComponent))
+ .toolbar(removing: .title)
+ }
+}
diff --git a/Peel/Views/FileSearch/FileSearchForm.swift b/Peel/Views/FileSearch/FileSearchForm.swift
index 470f29ab..f9ee75c1 100644
--- a/Peel/Views/FileSearch/FileSearchForm.swift
+++ b/Peel/Views/FileSearch/FileSearchForm.swift
@@ -1,11 +1,11 @@
import PeelCore
import SwiftUI
+/// The filters of a search, in a popover from the toolbar. The name is typed in the list's search field.
struct FileSearchForm: View {
private static let sizes: [Int64] = [10_000_000, 100_000_000, 500_000_000, 1_000_000_000, 5_000_000_000]
@Environment(FileSearchLibrary.self) private var search
- @State private var isRescanning = false
var body: some View {
@Bindable var search = search
@@ -40,22 +40,6 @@ struct FileSearchForm: View {
}
}
.formStyle(.grouped)
- // The name is typed in the search field at the top of the column, where other pages filter their lists.
- // Here the field is part of the search, so it is always shown.
- .columnSearch(text: $search.criteria.name, prompt: "Search Files", when: true)
- .navigationTitle(Text(Tool.fileSearch.title))
- .toolbar {
- ToolbarItem {
- RescanButton(isRunning: $isRescanning, isDisabled: !search.criteria.isSearchable || search.isSearching || search.isRemoving) {
- await search.search()
- }
- }
- }
- .task(id: search.criteria) {
- guard search.criteria != search.searchedCriteria else { return }
- try? await Task.sleep(for: .milliseconds(300))
- guard !Task.isCancelled else { return }
- await search.search()
- }
+ .frame(width: 400, height: 280)
}
}
diff --git a/Peel/Views/FileSearch/FileSearchResultsView.swift b/Peel/Views/FileSearch/FileSearchList.swift
similarity index 77%
rename from Peel/Views/FileSearch/FileSearchResultsView.swift
rename to Peel/Views/FileSearch/FileSearchList.swift
index ac3a3d84..4901d74b 100644
--- a/Peel/Views/FileSearch/FileSearchResultsView.swift
+++ b/Peel/Views/FileSearch/FileSearchList.swift
@@ -1,15 +1,20 @@
import PeelCore
import SwiftUI
-struct FileSearchResultsView: View {
+/// The files a search found, with every state of the search, in the list column as every tool keeps its items.
+struct FileSearchList: View {
@Environment(FileSearchLibrary.self) private var search
@Environment(ExclusionsStore.self) private var exclusions
@Environment(RemovalHistoryStore.self) private var history
@State private var isConfirmingRemoval = false
+ @State private var isShowingFilters = false
+ @State private var isRescanning = false
@Environment(RemovalOutcome.self) private var outcome
var body: some View {
- List {
+ @Bindable var search = search
+
+ List(selection: $search.chosen) {
ExclusionsUnreadableBanner()
// Says the limit rather than counting the rows, since exclusions added after the search take files
// out of the list, and can empty it, while the rest stays unlisted.
@@ -33,6 +38,7 @@ struct FileSearchResultsView: View {
isFirst: file.id == results.files.first?.id,
selection: search, isSelected: search.isSelected(file.url)
)
+ .tag(file.url)
}
.listRowSeparator(.hidden)
} header: {
@@ -74,8 +80,30 @@ struct FileSearchResultsView: View {
}
}
.fadesInColumn(whenRowsChange: search.results?.files.map(\.id))
+ // The name is typed in the search field at the top of the column, where other pages filter their lists.
+ // Here the field is part of the search, so it is always shown.
+ .columnSearch(text: $search.criteria.name, prompt: "Search Files", when: true)
.navigationTitle(Text(Tool.fileSearch.title))
- .toolbar(removing: .title)
+ .toolbar {
+ ToolbarItem {
+ Button("Filters", systemImage: "line.3.horizontal.decrease.circle") { isShowingFilters = true }
+ .help(Text("Filters"))
+ .popover(isPresented: $isShowingFilters, arrowEdge: .bottom) {
+ FileSearchForm()
+ }
+ }
+ ToolbarItem {
+ RescanButton(isRunning: $isRescanning, isDisabled: !search.criteria.isSearchable || search.isSearching || search.isRemoving) {
+ await search.search()
+ }
+ }
+ }
+ .task(id: search.criteria) {
+ guard search.criteria != search.searchedCriteria else { return }
+ try? await Task.sleep(for: .milliseconds(300))
+ guard !Task.isCancelled else { return }
+ await search.search()
+ }
.task(id: exclusions.revision) {
await search.leaveOut(exclusions.exclusions)
}
diff --git a/Peel/Views/RescanButton.swift b/Peel/Views/RescanButton.swift
index 0c8354a4..48a24b2b 100644
--- a/Peel/Views/RescanButton.swift
+++ b/Peel/Views/RescanButton.swift
@@ -10,7 +10,7 @@ struct RescanButton: View {
/// can't be stopped halfway, such as a Spotlight query or reading one file. Stop is not offered while the
/// button is disabled: the scan after a move to the Trash takes the moved rows off the list, and stopping
/// it would leave them listed.
- var scan: ScanRun?
+ var scan: (any StoppableWork)?
let action: () async -> Void
/// Set as soon as the work starts, so the button can't be pressed twice. `isRunning` is what the button shows.
@@ -75,3 +75,11 @@ struct RescanButton: View {
isWorking = false
}
}
+
+/// Work a page can stop from its toolbar and from View > Stop: a page's scan, or Duplicates' own.
+protocol StoppableWork: AnyObject {
+ var isRunning: Bool { get }
+ func stop()
+}
+
+extension ScanRun: StoppableWork {}
diff --git a/Peel/Views/ToolSummaries.swift b/Peel/Views/ToolSummaries.swift
index 7c4ca5d8..2d82aac2 100644
--- a/Peel/Views/ToolSummaries.swift
+++ b/Peel/Views/ToolSummaries.swift
@@ -17,7 +17,7 @@ extension SizeTotal {
}
extension Tool {
- /// What the tool found, as its pane and Home both say it, or nil for a tool Home doesn't list.
+ /// What the tool found, as its pane says it and Home repeats it, or nil for a tool with no such sentence.
func sentence(for looked: Looked) -> AttributedString? {
let count = looked.count
let total = looked.size.flatMap { $0.known > 0 ? $0.text : nil }
@@ -36,12 +36,12 @@ extension Tool {
case .space:
return total.map { AttributedString(localized: "\($0) in ^[\(count) area](inflect: true).") }
?? AttributedString(localized: "^[\(count) area](inflect: true).")
- case .installers, .cloud:
+ case .installers, .cloud, .fileSearch:
return total.map { AttributedString(localized: "\($0) in ^[\(count) item](inflect: true).") }
?? AttributedString(localized: "^[\(count) item](inflect: true).")
case .intel:
return AttributedString(localized: "^[\(count) item](inflect: true) built for Intel.")
- case .home, .packages, .fileSearch, .backgroundItems, .extensions, .plugins, .tweaks, .history:
+ case .home, .packages, .backgroundItems, .extensions, .plugins, .tweaks, .history:
return nil
}
}
@@ -94,6 +94,14 @@ extension HomebrewLibrary {
}
}
+extension FileSearchLibrary {
+ var summary: AttributedString? {
+ results.flatMap { results in
+ Tool.fileSearch.summary(of: Looked(count: results.files.count, size: SizeTotal(known: results.files.reduce(0) { $0 + $1.size }, isComplete: true)))
+ }
+ }
+}
+
extension PackageLibrary {
var summary: AttributedString? {
guard let receipts, !receipts.isEmpty else { return nil }