Skip to content

macOS: Finder file-open silently lost when a second app copy launches (single-instance forwards argv only) #212

Description

@PathGao

Describe the bug

On macOS, double-clicking a markdown file can silently do nothing — no window, no error — when a second copy of Markpad ends up launching while another copy is already running. The file-open event is lost entirely.

This happens whenever two copies of the app exist (e.g. the user once ran Markpad straight from the DMG or ~/Downloads, and also has a copy in /Applications) — or in any dev/test setup running a locally built bundle alongside the installed one.

Mechanism

macOS delivers Finder file-opens as an Apple Event (odoc) — the file path is never in argv. The sequence that eats it:

  1. LaunchServices resolves the .md handler to a specific bundle path (say /Applications/Markpad.app). The running copy has a different bundle path, so LS considers the handler "not running" and launches a new process, addressing the Apple Event to it.
  2. The new process starts and tauri-plugin-single-instance runs immediately: it detects the primary instance (same bundle identifier), forwards its argv — which contains no file path on macOS — and exits.
  3. The Apple Event arrives for a process that is already dead. It is dropped; the primary instance only gets an argv-only ping (it focuses the window, opens nothing).

Single Instance Args: ["/Applications/Markpad.app/Contents/MacOS/Markpad"] in the logs confirms the forwarded argv carries no file.

To Reproduce

  1. Have two copies of Markpad (e.g. one in /Applications, one anywhere else) sharing the bundle id.
  2. Launch copy B and leave it running.
  3. Double-click any .md file in Finder (LS targets copy A).
  4. Copy A flashes into existence, forwards, exits; the file never opens anywhere.

Expected behavior

The file opens in the running instance (or the second instance keeps ownership long enough to receive and forward the actual file paths).

Suggested fix

In the single-instance handling on macOS, don't exit before the open-documents Apple Event has been received: capture the opened paths (Tauri's RunEvent::Opened) and forward those to the primary instance instead of raw argv — or delay the exit until the first event-loop turn so Opened can fire. (Upstream, this is arguably a tauri-plugin-single-instance limitation: argv-forwarding is complete on Windows/Linux but loses Finder opens on macOS.)

Device

  • OS: macOS (Darwin 25.x)
  • App Version: v2.6.11 (also reproduced against current master builds)

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions