Skip to content

Linux: serve org.freedesktop.Application and pass launch activation tokens to the shown window - #2216

Merged
opencodejr[bot] merged 1 commit into
devfrom
bot/issue-22
Nov 25, 2026
Merged

opencodejr[bot] merged 1 commit into
devfrom
bot/issue-22

Conversation

@opencodejr

@opencodejr opencodejr Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Closes #22.

What changed

  • D-Bus server (open_url/instance/dbus.rs, new; Linux with the default dbus feature): when rune::single_instance(id) claims its Unix socket, the process also owns id on the session bus and serves org.freedesktop.Application at / plus the id with dots as slashes and dashes as underscores. It runs on its own thread and connection. rune::release_instance gives the name up, waiting at most 1 s.
    • Activate(a{sv}) and ActivateAction(s, av, a{sv}) reopen the app (App::on_reopen, then the default). Rune has no named actions, so the action's name is not passed on.
    • Open(as, a{sv}) sends links to App::on_open_url and local file:// URIs (percent-decoded, empty or localhost host) to App::on_open_files.
    • A call made before the loop has ever started is the D-Bus activation that started this process. It only keeps its token, and its links and files wait for the first window.
    • Once the loop has started, calls go through handoff::deliver, so after the loop ends they relaunch the app as socket launches do.
    • The name is requested without queueing. While an earlier process still holds it, the new one serves only the socket. This is documented.
    • The socket still decides which process is the first.
  • Activation tokens:
    • A later socket launch sends XDG_ACTIVATION_TOKEN or DESKTOP_STARTUP_ID as --rune-activation-token=. handoff::launch takes it out of the arguments, so a relaunch doesn't pass it on.
    • The token, or the D-Bus call's activation-token / desktop-startup-id, is kept for 20 s and used once.
    • Host::open uses it when it has no token of its own. A reopen with a token and no window to bring back activates the first visible window.
  • handoff::deliver is shared by the socket and D-Bus paths. A launch with only files doesn't reopen the app.
  • incoming.rs: Linux's files inbox now listens, so on_open_files receives Open batches. Windows is unchanged.
  • Docs:
    • App::on_reopen, on_open_url and on_open_files, and single_instance, describe the Linux behaviour.
    • The README has a new "Links and relaunches on Linux" section covering the socket, the token, the object path, the valid bus name requirement, the <id>.desktop entry and the dbus-1/services/<id>.service file.
    • Changelog entry added.

Tests

  • New:
    • instance/dbus_tests.rs: object paths, file:// decoding, splitting links from files.
    • instance/handoff_tests.rs: the token argument leaves the relaunch arguments; a kept token is used once and lapses; a files-only launch doesn't reopen.
  • cargo test -p rune --lib open_url: 27 passed.
  • cargo clippy -p rune --lib --tests and cargo check -p rune --lib --no-default-features: pass, with no warnings in the touched files.
  • scripts/file-size.sh: no errors.
  • Full cargo test -p rune --lib (RUNE_ALLOW_NO_GPU=1): 3126 passed, 1 failed. The failure is el::tx::rects::tests::a_handler_reads_a_row_it_removes_where_it_stood, which also fails on the unchanged base.
  • With --features rune/test-gpu-noop, window/tests.rs fails to compile (SurfaceMeter and acquire not found). This change doesn't touch that file.
  • Not tested against a real session bus, since none was available. Still to do by hand: gdbus call --session --dest <id> --object-path /<id path> --method org.freedesktop.Application.Open "['file:///tmp/x']" {}, then Activate.

Closes #22

@thdxr

thdxr commented Nov 25, 2026

Copy link
Copy Markdown
Member

heads up before this gets rebased: #2182 (476001e51) is on dev now and changes the same second-launch hand-over. only arguments on the app's own registered url scheme count as links now (rune::url_schemes), not anything with ://. this pr still picks links by the old rule, so if the conflict is resolved by keeping this branch's lines, --server http://… goes back to the link handler and a second launch with it stops reopening the app. please keep the url_schemes filter when you rebase.

also run cargo check -p rune -p rune-kit and cargo test -p rune before merging, dev broke today from untested merges

— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

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.

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

1 participant