--- topic: sharing triggers: [place_link.rs, AndroidManifest.xml, assetlinks.json, "deep link", "app link", "intent filter", "cartopolis://", "?place=", "/go", "Copy link", launch_url, autoVerify] updated: 2026-11-19 --- # A link to a place opens the app, and what that costs `https://cartopolis.org/go?place=53.21940,6.56650,120m,-12.5,45.0` is one link with two destinations: on an Android phone with the published APK installed it opens the app at that camera, and everywhere else it opens the web client, which reads the same `?place=` it has read since the launch-place path existed. The whole thing is `systems::place_link` (~200 lines and its tests), one JNI call, two intent filters, a JSON file on the web root and one Caddy matcher. ## The four constraints that decided the shape **An intent filter matches scheme, host and path, and never the query.** This is the single fact the design turns on. `?place=…` therefore cannot be what marks a link as one the app should answer, so the *path* has to carry that signal, and the app claims `/go` rather than `/`. Claiming the root would have handed the app every link to `cartopolis.org` — including `/apk/`, the page whose only job is to give you the APK in a browser, and the README's "open cartopolis.org". `/go` is a path with no file behind it: Caddy rewrites it to `index.html`, and the query survives untouched, so the wasm build needed no change at all. In the deploy host's `/data/stack/Caddyfile`, inside the `cartopolis.org` block and **before** the catch-all `handle`: ```caddyfile @place path /go handle @place { root * /srv/cartopolis rewrite * /index.html header Cache-Control "no-cache" file_server } ``` **The match is exact, and both looser spellings are wrong in their own way.** `/go*` would swallow `/gophers`. `/go/*` looks harmless and is the trap: the published `index.html` addresses the wasm module absolutely but Bevy's asset root relatively (`src="assets/…"`, and `fetch("assets/…")` from the module), so a page served at `/go/anything` resolves every asset to `/go/assets/…` and 404s the lot. The manifest claims exactly the same one path (`android:path="/go"`), and the two must stay in step, or a link opens the app on a phone and breaks in a browser. `place_link` still accepts a path-carried place (`cartopolis://go/53.2194,6.5665`) because the custom scheme never touches the web server — nothing *writes* that form, and as an https link it is a 404. Also deliberately **not** a general `try_files` fallback on the main handler: that turns every missing asset into a 200 with an HTML body, and a wasm module that 404s is a diagnosis where one that arrives as `index.html` is a mystery. **App Link verification is keyed to the signing certificate**, so a locally built APK can never have one. Android fetches `/.well-known/assetlinks.json` at install time and checks it names both the package and the cert the APK was signed with; `build-apk.sh` signs a hand build with a per-machine debug keystore, so on a sideloaded build the https filter is dead by design. That is why the `cartopolis://` scheme exists alongside it, and why nothing depends on the App Link alone. Two things that look like bugs and are not: verification happens at **install** time, so publishing the JSON after installing does not retroactively fix a phone (`adb shell pm verify-app-links --re-verify eu.garage44.cartopolis` does, and `pm get-app-links eu.garage44.cartopolis` shows the verdict); and the fingerprint in `crates/cartopolis/assetlinks.json` is the *deploy host's* `cartopolis.x509.pem`, so **rotating the release key means editing that file**, or every install after the rotation silently stops handling links. **The file has to ride in the trunk dist.** `deploy-wasm.yml` publishes with `rsync --delete`, so anything under the web root that trunk did not produce is removed on the next deploy. `assetlinks.json` is therefore a `data-trunk rel="copy-file"` in `index.html` rather than a file placed on the host — a file the site needs and the build does not know about is a file that works until the next push. **`android-activity` 0.6 surfaces no intent at all**, so the URL is read by JNI — `getIntent().getDataString()`, `platform::android::launch_url`. Every class in that path is a framework one, so this worked even under the no-dex rule (`docs/notes/android-build.md`) that applied when it was written. ## A link followed while the app is running (2026-11-19) `android.app.NativeActivity` does not override `onNewIntent`, and the default implementation does not call `setIntent`. So `getIntent()` keeps handing back the intent that *started* the activity for the life of the process. With `launchMode="singleTask"` — which the app needs — a second link goes to `onNewIntent` rather than to a new activity, and until 2026-11-19 tapping one while the app ran brought it forward and did nothing else. `MainActivity.onNewIntent` (the activity has been our own subclass since the dex lane) now keeps the link until the client takes it, once: `platform::android::new_link`, polled twice a second. **One system reads it**, `place_link::take_new_link` (2026-11-20): `new_link` hands a link out once, so two readers would take it from each other. It sorts the link with `place_link::followed` — invite, contact, place — flies to a place itself and brings the map forward (`RightPanel::None`), and leaves a contact or invite in `place_link::NewLink` for `contacts::drive_contacts` and `communities::sync_device`, which open it the way they open a launch's link. `launch_url` stays a read-once-at-startup call: `getIntent` answers the same link for as long as nothing replaces it, so polling it would re-teleport the camera to a link followed hours ago. Options considered and why they lost: | | | |---|---| | A trampoline activity that reads the intent and hands it over | Unneeded once `MainActivity` existed: overriding `onNewIntent` in it is the same hand-over with no second activity in the manifest | | `launchMode="standard"` so each link starts a fresh activity | A second `NativeActivity` in one process means a second Bevy app against one `ANDROID_APP`, one winit and one surface | | `noHistory="true"` so every launch is cold | Loses the whole session — map, camera, tile cache warmth — every time the user switches apps | | Poll `getIntent()` each frame | It never changes; there is nothing to poll | ## What a link carries, and what it does not Latitude, longitude, altitude, camera pitch and yaw — `place_link::place_param`, which is what the Search panel's **Copy link** writes and what `geo_nav::parse_location` reads. No spaces and no degree signs, so the URL needs no percent-encoding and survives a chat client that ends a link at the first space; `place_from_link` still accepts the readable `53.21940, 6.56650, 120m, -12.5°, 45.0°` spelling, either scheme, any host, a percent-encoded value and a bare coordinate string, because the ones worth refusing are only the ones nobody can fix. Two functions that used to exist and deliberately do not: `hud::format_place`, which wrote that readable spelling — Copy link writes a URL now, so it had no writer left, and a format with no writer drifts away from the parser that still reads it. And an `app_link` beside `web_link`: the `cartopolis://` URL has exactly one writer and it is `index.html`'s loader, in JavaScript, because the page must offer it *while the module is still downloading*. A Rust twin would be a second definition of one string. What holds them together is that Rust only ever reads the scheme, liberally, and `a_link_round_trips_through_both_schemes` parses the exact literal the loader writes. It deliberately does **not** carry the time of day, the weather, the enabled layers, the route or the session. A link that silently rewrote the receiver's settings would be a link people learn not to follow, and every one of those is already persisted per user (`user.json`). "The exact camera" is the whole promise. ## Contact and invite links name the server that made them (2026-11-28) A contact link, a community invite and a call's guest link carry the origin of the server the app is signed in to (`place_link::link_origin`, from `ConnectAddr`), and the web page's invite its own `location.origin`. A self-hosted server's web UI answers `/go` itself (`static_files`, the chat page reads `?community=`), so the link opens there; before, every link said cartopolis.org and sent people to the wrong server. A server with no address worth sharing — loopback, `tcp://`, `ws://`, the web build's empty address — keeps `WEB_ORIGIN`. Reading one back, the host now counts for a contact: `contact_from_link` gives `sanne@rug.example` for a link from rug.example, and `Contacts::open_card_for_name` turns it back into the bare name on its own server (`address::display` against `link_home`), since the server looks a local person up by name only. The custom scheme and a loopback page name no server and give the bare name. **Place links still say cartopolis.org.** On cartopolis.org `/go` is the viewer, which flies to `?place=`; on a server of one's own it is the chat page, which does not. **On Android a link to another server opens the browser**, not the app: App Links are verified per host (`assetlinks.json` on cartopolis.org only). Pasting it in Contacts ▸ Add, or Find for an invite, reads it in the app. ## Trying it without a phone ```bash # the emulator harness in the android-emulator-on-the-vps memory, then: adb shell am start -a android.intent.action.VIEW \ -d 'cartopolis://go?place=53.21940,6.56650,120m,-12.5,45.0' adb shell am start -a android.intent.action.VIEW \ -d 'https://cartopolis.org/go?place=53.21940,6.56650,120m,-12.5,45.0' adb shell pm get-app-links eu.garage44.cartopolis # verified / not ``` On the desktop the same link is a `CARTO_PLACE` value — it goes through the same parser, so a URL and five numbers are interchangeable there: ```bash CARTO_PLACE='https://cartopolis.org/go?place=53.2194,6.5665,120m,-12.5,45' \ cargo run -p cartopolis ``` There is no desktop *scheme handler*: registering `cartopolis://` with a desktop needs an installed `.desktop` file (or the macOS/Windows equivalents), and this project ships a `cargo run`, not an installer. When it ships one, the manifest is the place that changes and nothing in `place_link` has to.