Skip to content

Linux: open-URL and reopen hook via org.freedesktop.Application #22

Done

Description

@kitlangton

On macOS, an app receives "open URL" and "reopen" (Dock click or relaunch while running) events. Linux apps need the equivalent so that relaunching a running app reuses the existing instance, and URL or file activation reaches it.

Needed: an app-level hook for open-URL/open-files and reopen, with one API across platforms. On Linux, implement the D-Bus org.freedesktop.Application interface (Activate, Open, ActivateAction) with single-instance handling on the session bus, and pass the activation token through to the shown window. Check against the existing macOS lifecycle hooks so the API is shared.

Activity

  1. ImBIOS commented on Oct 26, 2026

    @ImBIOS
    Contributor

    Implemented the Linux half in PR #29 (commit 35329d7, crates/rune/src/instance.rs + App::single_instance / App::on_open):

    • First launch owns rune.<app_id> on the session bus (zbus service role); second launch probes NameHasOwner (no stray Activate queued), forwards files/URIs via org.freedesktop.Application Open (or bare Activate), and exits 0 before any window opens.
    • Owner drains the queue on the event thread through on_open(&[String]); empty URIs act as on_reopen. No bus → runs unclaimed; headless never claims.
    • Gotcha found while testing: a leaked serving connection alone is not enough — with no executor left, the owner's method calls never dispatch and the second launch hangs. The owner now serves on a dedicated bus thread for the app's life.

    E2E: cargo test -p rune --lib instance — bus-name shaping unit + two live session-bus round-trips (Open-forward with 2 URIs landing in the owner's queue; bare Activate as empty reopen), green in 0.04s.

    Activation tokens: XDG_ACTIVATION_TOKEN/DESKTOP_STARTUP_ID is captured on the forwarded request; passing it through to the shown window rides the existing AppHandle::activate(token) path (the owner's on_open handler calls it) — same mechanism the X11/Wayland window code already uses.

  2. opencodejr commented on Nov 25, 2026

    @opencodejr
    Contributor

    Thanks, this makes sense. Some of it is already in Rune, so here's what's there and what's missing.

    Already there (Linux): rune::single_instance(id) keeps one process per app over a Unix socket in $XDG_RUNTIME_DIR (crates/rune/src/open_url/instance/linux.rs). A later launch hands its arguments to the running process: its links go to App::on_open_url, and a launch without links runs on_reopen and its default. The doc comments on on_open_url and on_reopen in app.rs still say they never run on Linux, so they need updating.

    Missing, and what this issue would add:

    • An org.freedesktop.Application server on the session bus (Activate, Open, ActivateAction), so DBusActivatable=true desktop entries and launchers that go over D-Bus reach the running instance. It also needs to fit with the socket handoff that's already there.
    • File opens on Linux: App::on_open_files never runs there today, so Open with file:// URIs, or file paths passed as launch arguments, should reach it, as on macOS.
    • The activation token: the launch's activation-token / desktop-startup-id platform data, or XDG_ACTIVATION_TOKEN / DESKTOP_STARTUP_ID, should be passed along to the window that gets shown so the compositor lets it take focus. Nothing in the handoff passes it along yet.
    • Keeping one set of hooks across platforms (on_reopen, on_open_url, on_open_files) rather than adding a Linux-only one.
  3. opencodejr commented on Nov 25, 2026

    @opencodejr
    Contributor

    I've opened a PR that adds this on Linux, using the same hooks as macOS and Windows:

    • With rune::single_instance(id), the first process also owns id on the session bus and serves org.freedesktop.Application.
      • Activate and ActivateAction run App::on_reopen. Rune has no named actions, so the action's name isn't passed on.
      • Open sends links to App::on_open_url and file:// URIs to App::on_open_files.
    • Launch arguments are sorted the same way. A desktop entry's %U file URIs reach on_open_files, from the first launch and from later ones handed to the running app. Plain paths (%F) aren't passed on to a running app, so use %U.
    • A later launch's activation token, from XDG_ACTIVATION_TOKEN / DESKTOP_STARTUP_ID or the call's activation-token, goes to the window the launch brings forward, or else to the next window the app opens. A launch that has to start the app again passes both its URIs and its token to the new process.
    • id has to be a valid bus name. DBusActivatable=true also needs a desktop entry named <id>.desktop and a session service file; the README now says how.

    The tests cover the URI and token handling and how launches are routed. It hasn't been tried against a real session bus or built for Windows yet.

    Fixed in #2216.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions