Skip to content

feat(open_url): url_schemes names an app's own schemes, so a flag's URL value isn't a link - #2182

Merged
Hona merged 3 commits into
devfrom
open-url-own-schemes
Nov 25, 2026
Merged

Hona merged 3 commits into
devfrom
open-url-own-schemes

Conversation

@Hona

@Hona Hona commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

On Windows and Linux every scheme:// launch argument is a link for App::on_open_url. That also takes a flag's value for one.

What goes wrong

For an app started as myapp --server http://localhost:4096:

  • The hook gets http://localhost:4096, which is not a link the system opened with the app.
  • With rune::single_instance, a later launch with that flag is not "a launch without links", so the running app is not reopened and its window does not come forward. (By reading relaunched: links go to the hook, only a launch with none calls the reopen.)

Change

rune::url_schemes(["myapp"]) names the schemes the app registered for itself. From then on only launch arguments on one of them are links, at the first process's start and for every later launch handed to it. Schemes compare without case and match whole (myapp does not match myapp-beta://).

  • Called first thing in main, before single_instance.
  • Without the call nothing changes: every scheme:// argument is still a link.
  • macOS: does nothing; the system already hands an app only links on the schemes its bundle declares.

This is what an Electron shell does by hand when it filters argv for its own protocol.

What it can change for an app

Nothing until the app calls it. After the call, links on schemes the app did not name no longer reach App::on_open_url from launch arguments.

Tests

crates/rune/src/open_url/instance/tests.rs: what counts as a link; every link opens until schemes are named; a flag's URL value is not a link once they are; a launch with only such a flag has no links; whole, caseless scheme match; an app that names no scheme opens no link.

Runs

  • Unit tests (the macOS test workflow, run by hand on this branch): the six new tests pass, and the whole rune library is green (3,321 passed, 0 failed) in the run on a09e71352 (this change with dev merged in). The only failures in that run are three rune-kit integration tests that are dev's own and fail the same way on a branch without this change: kit_metrics::controls_take_their_metrics_from_the_kit and kit_metrics::text_area_takes_its_type_and_padding_from_the_kit (a prefix lookup in the test, since fixed on dev by fix(rune-kit): require path separator boundary in kit_metrics descendant lookups #2220) and diff_custom::file_header_replaces_built_in_header_in_list_and_sticky_overlay_and_toggles_collapse (a paint-keep self-check, being looked at separately). A later run on this branch with newer dev merged in did not build: dev itself does not compile from feat(selection): El::selection_enabled(bool), a subtree or window switch for selectable text #2206 on (the TextSpec size assert; fix in fix(text): TextSpec is 224 bytes again, so rune compiles #2227), which this change does not touch.

  • Compiled in an app: an app pinned to this change (its pinned Rune commit plus this one), calling rune::url_schemes with its scheme before single_instance, builds on macOS, Windows x64 and arm64, and Linux x64.

  • Run, Windows x64, that app's build against one without the change: a real window started as app --server http://127.0.0.1:<port>, then a second launch with the same arguments, then a third with none. The app prints a line for each link it does not open.

    Without the change With url_schemes
    Lines after the first launch 1 (the flag's value reached on_open_url) 0
    Lines after the second launch 2 (handed over as a link) 0
    Lines after the third launch 2 0

    Both later launches exit 0 in 10 to 33 ms on both builds.

Not run: Linux (compiled only); that the window comes forward on the second launch (read from relaunched, where a launch without links is the one that reopens; not observed); a link on the app's own scheme through a real system open.

…RL value isn't a link

On Windows and Linux every scheme:// launch argument was a link for App::on_open_url. An app with a flag that takes a URL (myapp --server http://localhost:4096) got the flag's value in the hook, and with single_instance a later launch with such a flag was not a launch without links, so it did not reopen the app. rune::url_schemes(['myapp']) names the schemes the app registered; from then on only arguments on them are links. Without the call nothing changes.
@Hona
Hona marked this pull request as ready for review November 25, 2026 09:01
@Hona
Hona merged commit 476001e into dev Nov 25, 2026
3 of 4 checks passed
@Hona
Hona deleted the open-url-own-schemes branch November 25, 2026 09:02
@Hona

Hona commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

Run on Linux x64 after the merge (a headless Wayland compositor, an app build pinned to this change that calls rune::url_schemes with its scheme, against a build without it): started with --server http://127.0.0.1:<port>, the build without the change hands the URL to on_open_url and this one does not; a second launch with only that flag is handed over as a launch with no link (it was a link before); a foreign https:// link as the only argument is no longer a link; a link on the app's own scheme still reaches the hook. Not observable there: whether the running window comes forward (the compositor used has no activation protocol). By reading, the hand-over message carries no XDG_ACTIVATION_TOKEN, so on a Wayland desktop that enforces activation a reopen cannot raise the window, with or without this change; #2216 is about that.

Hona added a commit to anomalyco/opencode-rune that referenced this pull request Nov 25, 2026
…of --server is not one (#1195)

* fix(deps): pin rune to d5c7a5ad (214 commits), the effect warm for backdrop blur only

* fix(launch): only links on the app's own scheme are links; the value of --server is not one

Rune took every scheme:// launch argument for a link. Started as 'app --server http://127.0.0.1:4096', the app got the server's URL in its link handler ('ignored a link it doesn't open'), and a second launch with that flag was handed over as a link, not as a launch that reopens the app. The app now names its scheme (rune::url_schemes, anomalyco/rune#2182, in the pin of #1192).

* chore(pgo): the profiles re-keyed to Rune d5c7a5ad's symbol names

A pin move renames every Rune symbol, so the committed profiles were dead for Rune's code on this branch's first commit. Both are re-keyed onto this tree's names, read from the instrumented build of #1193 (scripts/pgo-rekey.mjs).

Windows x64: the counts trained on 25 Nov (launch weight 1): 17,961 of 18,439 functions keep their counts, 337 are dropped because their code changed, 141 no longer exist.
Apple silicon: the committed profile, not trained anew: 15,030 of 15,445 kept, 285 dropped, 130 gone.
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.

1 participant