Files
Allofit/sources/ui/QuickLookCoordinator.swift
Bitsy 35ffc86e46 Fix idle CPU drain from open path queries, general code cleanup
Fix
- An open window with a path query (term containing "/") re-ran the search
  over the whole index on every FSEvents update, keeping several cores busy
  while files changed. Index-driven refilters are now throttled to one per
  second, skipped while the window is closed, minimized or covered, and
  replayed once when it becomes visible again. Typing stays instant.
- Path terms no longer build and lowercase the full path of every record:
  the folded folder path is precomputed once per folder (interned like
  parentPath) and matched together with the folded name without allocating
  the joined string. Path-only queries are about 3x faster.

Cleanup
- Remove dead code: FSChange.isDir, FileWatcher.latestEventId,
  IndexState.record(atPath:), the never-set lastQuery preference,
  AccessManager.reset(), SearchField.onSubmit, an unreachable return.
- Merge duplicates: the two Settings size formatters become
  Formatters.sizeOrDash, the shellQuote wrapper is replaced by
  AdminShell.quote.
- Naming conventions: "in"-prefixed parameter names everywhere (delegate
  methods, binary helpers, initializers), camelCase impl helpers.
- Comment every function and type; fix stale comments.
- Debug and release builds are warning-free.
2026-10-02 09:29:18 +02:00

41 lines
1.2 KiB
Swift

import AppKit
import Quartz
// QuickLookCoordinator drives the system-wide QLPreviewPanel for the current
// selection. It acts as both data source and delegate for the panel, which is
// itself a process-wide singleton.
@MainActor
final class QuickLookCoordinator: NSObject, @preconcurrency QLPreviewPanelDataSource, QLPreviewPanelDelegate {
// singleton because QLPreviewPanel is itself a singleton
static let shared = QuickLookCoordinator()
// urls currently being previewed
private var urls: [URL] = []
// presents the Quick Look panel for the given URLs
func show(inUrls: [URL]) {
guard !inUrls.isEmpty else { return }
urls = inUrls
guard let vPanel = QLPreviewPanel.shared() else { return }
vPanel.dataSource = self
vPanel.delegate = self
vPanel.reloadData()
vPanel.makeKeyAndOrderFront(nil)
}
// ===========================
// MARK: QLPreviewPanelDataSource
// ===========================
// number of files shown by the panel
func numberOfPreviewItems(in inPanel: QLPreviewPanel!) -> Int {
return urls.count
}
// file shown at the given panel position
func previewPanel(_ inPanel: QLPreviewPanel!, previewItemAt inIndex: Int) -> QLPreviewItem! {
return urls[inIndex] as NSURL
}
}