Fix macOS file open association and scroll sync#3
Merged
Conversation
Handle macOS Apple Events for file associations (#1) by switching from argv-based detection to Tauri's RunEvent::Opened handler, emitting an event to the frontend. Fix scroll sync drift (#2) by replacing the single-frame requestAnimationFrame guard with a 200ms debounced timeout to prevent feedback loops on macOS. Closes #1, Closes #2 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses two macOS-specific UX issues in the Tauri-based Inkwell app: handling file-association opens on macOS, and preventing scroll-sync feedback loops between editor and preview.
Changes:
- Add a Tauri
RunEvent::Openedhandler to forward macOS “open document” events to the frontend. - Register a frontend event listener to load files requested by the backend.
- Replace
requestAnimationFrame-based scroll-sync reset with a debounced timeout to prevent scroll bounce/drift.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/preview/scroll-sync.js |
Debounces scroll-sync reset to avoid feedback loops with async scroll events. |
src/main.js |
Listens for a new backend-emitted event and loads the requested file path. |
src-tauri/src/lib.rs |
Switches to build().run() and emits an event on RunEvent::Opened for macOS file associations. |
src-tauri/Cargo.lock |
Reflects version bump to 0.2.0. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src-tauri/src/lib.rs
Outdated
Comment on lines
+52
to
+54
| if let Some(path_str) = path.to_str() { | ||
| let _ = app_handle.emit("open-file-requested", path_str.to_string()); | ||
| } |
Comment on lines
+7
to
+9
| function deferSyncReset() { | ||
| clearTimeout(syncResetTimer); | ||
| syncResetTimer = setTimeout(() => { syncSource = null; }, 200); |
src/main.js
Outdated
Comment on lines
+67
to
+71
|
|
||
| // Handle macOS file-open events (double-click / "Open With" file associations) | ||
| await listen("open-file-requested", async (event) => { | ||
| await loadFile(event.payload); | ||
| }); |
Issue #1: RunEvent::Opened fires before the webview is ready on macOS, so app_handle.emit() silently drops events on cold launch. Fix by buffering opened paths in managed AppState (PendingOpenFiles) and exposing get_pending_open_file command for the frontend to poll at startup. The event listener is kept for runtime opens when the app is already running. Issue #2: The 200ms deferSyncReset was applied to applyScrollRatio, blocking user scroll for 200ms after every view-mode switch. Restore requestAnimationFrame for applyScrollRatio (one-shot restore only needs one-frame suppression) while keeping the 200ms debounce for the bidirectional sync handlers where macOS async scroll delivery requires a longer guard window. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
argvfor file paths, but macOS uses Apple Events (kAEOpenDocuments) for file associations. Switched frombuilder.run()tobuilder.build().run()with aRunEvent::Openedhandler that emitsopen-file-requestedto the frontend. The existingget_open_file_argremains as a fallback for Linux/Windows.requestAnimationFramesync guard with a 200ms debouncedsetTimeout, preventing the bounce-back caused by macOS's asynchronous scroll event delivery.Closes #1, Closes #2
Test plan
.mdfile in Finder — Inkwell should open and display the file.mdfile → "Open With" → Inkwell — file should open🤖 Generated with Claude Code