Skip to content

fix: wait for macOS screenshot mtime to stabilize before reading#5

Merged
flamerged merged 1 commit into
masterfrom
fix/macos-screenshot-partial-write
May 1, 2026
Merged

fix: wait for macOS screenshot mtime to stabilize before reading#5
flamerged merged 1 commit into
masterfrom
fix/macos-screenshot-partial-write

Conversation

@flamerged
Copy link
Copy Markdown
Owner

Review item #5. Replaces the 300ms freshness heuristic with an mtime-stability check — file must keep the same mtime for at least one full poll cycle before we read it. Prevents reading partially-written screenshots on slow disks.

Pre: getLatestMacScreenshot used a single 'skip if mtime is younger
than 300ms' heuristic. macOS Cmd+Shift+3 on a large display can take
longer than 300ms to fully write; the existing check could let a
partially-written file through, causing sshshot to upload a corrupt
PNG to the remote.

Now: track the mtime we saw on the previous poll
(lastObservedScreenshotMtime) and only proceed when the current mtime
matches it. If the mtime changed, the OS is still flushing writes;
wait another poll. The 300ms freshness check is kept as belt-and-
suspenders for edge cases where stability is only one poll old.

Trade-off: minimum delay between screenshot completion and upload
goes from ~300ms to ~500ms (one poll cycle of stability + the 300ms
check). Imperceptible to humans, eliminates the corruption risk.
@flamerged flamerged merged commit c53d1bf into master May 1, 2026
2 checks passed
@flamerged flamerged deleted the fix/macos-screenshot-partial-write branch May 1, 2026 13:03
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

🎉 This PR is included in version 0.4.5 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

flamerged added a commit that referenced this pull request May 1, 2026
…, clipboard reads (#14)

Four items from the latest project review (P3/P4 cleanup):

| # | Item |
|---|------|
| #2 | `getPidFile` deduped into config.ts (single source of truth) |
| #3 | `taskkill` via spawnSync with array args |
| #5 | `startBackground` Linux/macOS path: nohup execSync → spawn
detached (closes the `\${remote}` shell-injection surface; the original
'native clipboard library crashes with detached' rationale is obsolete
since @crosscopy/clipboard was removed) |
| #6 | xclip / wl-paste / pngpaste / defaults clipboard reads via
spawnSync |

Net: zero remaining execSync calls with user-controlled string
interpolation. All tests still pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant