Skip to content

pitis/perch#24: Launch no longer checks copied files on the main thread, or in folders Perch can't read yet - #27

Merged
pitis merged 2 commits into
mainfrom
autopilot/pitis-perch-24-clips-off-main
Nov 13, 2026
Merged

pitis merged 2 commits into
mainfrom
autopilot/pitis-perch-24-clips-off-main

Conversation

@pitis

@pitis pitis commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

Refs #24

This uses Refs, not Closes, because the repo's rule is to close an issue only after the change has run on a real Mac, and this one hasn't yet (see Not done below).

What changed

  • Saved clips are checked in the background. ClipsManager.load() no longer calls fileExists on the main thread. It sets the saved clips and calls pruneMissing(), which now checks the files on a utility queue and removes the missing ones back on the main thread.
  • Clips in protected folders are never checked unless Perch already has access. That covers Desktop, Documents, Downloads, and /Volumes (removable and network volumes). The only access Perch knows it has is the screenshot folder it's watching. If that folder is inside a protected folder, files there are checked as before, so deleted Desktop screenshots still disappear when screenshots are on. Other clips in protected folders stay, as the issue suggests. Opening one whose file is gone does nothing, and dragging it carries nothing instead of an empty piece of text.
  • The launch check leaves Desktop alone. It runs before the screenshot watcher starts, so it never touches Desktop. Turning screenshots off now also clears the watched folder. Together these keep the rule in AGENTS.md: don't touch the Desktop folder unless captureScreenshots is on.
  • QuickLook thumbnails are requested in a detached task, so the request can't block the main thread.
  • The decision "could touching this path raise a prompt?" is ProtectedFolders.mayPrompt in PerchCore, with tests.

Why

Same freeze as #21, by another route. A file copied from ~/Documents before Perch had Documents access was checked with fileExists on the main thread at launch. That check can block on a macOS permission prompt, and the notch freezes until the prompt is answered. If the user had denied access, the check came back false and the clip was silently pruned.

How it was tested

  • make check: 45 tests pass, including 4 new ProtectedFoldersTests. They didn't compile before ProtectedFolders existed.
  • swift build builds with no warnings.
  • make shots: no screen changes. Every pair matches except the clock: the Clips screen differs only in its 22:16 / 22:17 captions, and the other differing screens show times and countdowns this change doesn't touch. No before/after table is posted because nothing visible changed in the screens --snapshot can render. The one behaviour a person could notice is that a clip for a deleted file in Documents, Downloads or Desktop (with screenshots off) now stays instead of disappearing. Sample data can't show that.

Not done

  • Not run on the real Mac. The steps in the issue need a real open launch with Documents access revoked, and AGENTS.md says not to raise permission prompts on the user's machine from a session like this. After merge, this should be checked with those steps and get the verify label.
  • Opening Clips may still prompt. A QuickLook thumbnail for a file in a folder Perch can't read yet may still bring up the macOS prompt. That matches the README line from Describe Perch for visitors and license it under MIT, before the repo goes public #23 ("copying one from Desktop, Documents or Downloads may make macOS ask about that folder too"), and the request no longer runs on the main thread, so it shouldn't freeze the panel.
  • Not covered: iCloud Drive and other app containers. Open and drag still touch the file on the main thread when the user asks for them, as before.
  • Review: /pr-review-toolkit:review-pr and /ponytail:ponytail-review were run, and the fixes are in the review comment below. Two product questions are left open there.

Launch checked every saved clip's file on the main thread. A file copied from
Documents or Downloads, before Perch had access there, could block on a macOS
permission prompt and freeze the panel, the same way the Desktop did before.

Pruning now runs in the background and never touches files in Desktop,
Documents, Downloads or /Volumes unless that folder holds the screenshot folder
Perch already watches. Those clips stay. QuickLook thumbnails are also requested
off the main thread.
… on the main thread

Clip.url no longer asks the disk whether a path is a folder, which the
Clips page did on every redraw. The prune only drops files that are
really gone, not ones macOS refused access to. Protected folders now
include iCloud Drive and cloud storage, match regardless of case, and
count each volume on its own. The prune runs again once the screenshot
folder is known, and the drag fallback that never ran is gone.
@pitis

pitis commented Nov 13, 2026

Copy link
Copy Markdown
Owner Author

Review

Ran /pr-review-toolkit:review-pr (code, error handling, tests, comments) and /ponytail:ponytail-review on git diff origin/main...HEAD. Fixes are in 7ea5aa6. make check: 47 tests pass, 3 of them new, and each failed before the fix. swift build gives no warnings. Nothing on screen changed, so there are no new screenshots.

Fixed

  1. Critical: opening Clips could still freeze. Clip.url used URL(fileURLWithPath:) without isDirectory:. That form checks the disk to decide whether the path is a folder. ClipCard read it on every redraw on the main thread, through title and the accessibility label. Now it's isDirectory: false.
  2. Important: a refused folder still deleted clips. fileExists returns false on "permission denied" too. A denied iCloud Drive folder, or Desktop access turned off later, would drop those clips. The prune now removes a clip only when access() fails with ENOENT.
  3. Important: the protected list missed cloud folders. ~/Library/Mobile Documents (iCloud Drive) and ~/Library/CloudStorage (Dropbox, Google Drive, OneDrive) were checked at launch and could raise a prompt. They're in ProtectedFolders.all now.
  4. Important: one volume's grant covered every volume. A screenshot folder on /Volumes/USB counted as access to /Volumes/NAS. Each volume is now its own area. Test: testAGrantedVolumeCoversOnlyItself.
  5. Important: matching was case-sensitive. The default volume opens ~/desktop/x as the Desktop. Matching ignores case now. Test: testMatchingIgnoresCase.
  6. Important: the drag fallback never ran. NSItemProvider(contentsOf:) returned a provider for every file URL tried, missing files included, so ?? NSItemProvider() was dead code with a comment describing behavior that doesn't happen. The original line is restored and the comment removed.
  7. Comments. The pruneMissing doc no longer says opening or dragging a gone clip "does nothing", and it says "granted" means the watched screenshot folder. The ProtectedFolders doc matches the list. The thumbnail comment says it prevents a freeze, not the prompt.
  8. Suggestion, taken: deleted screenshots now disappear at launch again. The launch prune runs before the screenshot folder is known. The prune now runs again once the watcher is set, as it did before this PR.

Declined

  • "dragProvider reads the file on the main thread." The error-handling reviewer checked: building the provider types the file from its extension and doesn't open it. Starting a drag doesn't touch the disk.
  • Prune by clip id instead of path. The pasteboard, the drop and the scan all refuse a second clip with the same path. A wrong removal would need the user to remove a clip and re-add the same file within the milliseconds the check takes.
  • .. segments, /System/Volumes/Data firmlinks, user symlinks. Finder puts standardized paths on the pasteboard. A miss now costs a prompt, not a freeze.
  • Clip uses synthesized decoding, so a future field could wipe clips.json. True, but it isn't in this diff and is safe today. Every field has existed since the first commit.

Left for you (product decisions)

  • Thumbnails for protected files. The prune skips Documents, Downloads and ungranted Desktop files, but QuickLook still thumbnails them when Clips opens. That may raise the macOS prompt (no freeze now). Skipping them would avoid the prompt, but those files would never get a thumbnail, since Perch can't tell when access was granted. The README already says copying a file from those folders may make macOS ask.
  • What a gone file's clip should do. Clips in protected folders now stay after their file is deleted. Opening one does nothing, and clicking it puts a dead file link on the clipboard, replacing what was there. Options: remove the clip when it fails, mark it as missing, or leave it as it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant