RFC 0052 — Open documents: files the OS hands the app
Status: implemented (2026-11-24) · Target: 0.54.0 · builds on single-instance & deep-linking, a file the user chose, rata bundle · see Decisions
Summary
A document app has to open its documents the way the OS offers them:
double-clicked in Finder or Explorer, dragged onto the Dock icon, chosen in
"Open With", or passed on the command line. Elyra registers URL schemes
(deep_link), but no file types. The bundle doesn't declare any, so the OS
never offers the app, and a file that reaches it anyway isn't handled. On
macOS it currently arrives as a raw file:// string on elyra:deep-link.
This RFC adds document types: declared once, registered by rata bundle
on each platform, and delivered to the page as ChosenFiles the user chose.
# elyra.toml
[[bundle.documents]]
name = "Kver document"
extensions = ["kver"]
mime = "application/vnd.kver.document+json"
role = "editor" # or "viewer"
App::new()
.opens(["kver"]) // the extensions this app accepts from the OS
.single_instance() // so a second double-click reaches this process
.run()?;
import { documents } from "@elyra/runtime";
for (const file of await documents.initial()) openTab(file); // opened at launch
documents.onOpen((files) => files.forEach(openTab)); // opened while running
// A ChosenFile, as from a dialog: pass it to a command as it is.
await commands.readDocument({ file });
- One declaration, three platforms:
rata bundlewrites macOS'sCFBundleDocumentTypesand an exported type, a.desktopMimeTypeand a shared-mime-info XML in the.deb, and the NSIS installer's ProgID. - Granted like a dialog's file: what the OS opens is something the user
chose, so it arrives as a
ChosenFilethe page can pass to a command, and a command can't be made to read a path the user didn't open. - Launch and while running alike: files at launch wait until the page asks for them; later ones arrive on an event. On Windows and Linux, the second process forwards them through single-instance.
Motivation
- Dogfood. Porting kver (a Tauri document editor) found this as the
first missing piece. Its
.kverfiles open from Finder through Tauri'sfileAssociationsandRunEvent::Opened. - Every document app needs it: an editor, a viewer, a tool for one file
format. The URL scheme
deep_linkcovers links, not files. - What exists today is a leak, not a feature. On macOS,
Event::Openedforwards every URL, files included, toelyra:deep-linkas a string. The path is not granted and not filtered by type, and the frontend has to tell a file from a link itself.
Current state (0.53)
App::deep_link(scheme)reads a launch URL from argv (deeplink::url_in_args). It registers the scheme at startup on Windows (HKCU) and Linux (.desktop+xdg-mime). On macOSrata bundlewritesCFBundleURLTypes.App::single_instance(): a second process hands one payload of at most 8 KB to the first and exits. The payload is the deep-link URL from argv, or "".shell/webview.rs, macOS only:Event::Opened { urls }emits each URL onelyra:deep-link.ChosenFile { id, path, name, kind }withFileChoice::{Open, Save, Folder}, granted for the run. It decodes in a command only from a grant'sid.rata bundle: the.app'sInfo.plist, a.debwith a.desktopentry (Exec=<bin> %u), an AppImage, and an NSIS installer with the scheme in HKCU.
Design
Declaring document types
[[bundle.documents]] in elyra.toml, any number of them:
| key | ||
|---|---|---|
name |
required | shown by the OS ("Kind: Kver document") |
extensions |
required | without the dot, lowercase |
mime |
optional | Linux's type and macOS's UTTypeTagSpecification; default application/x-<app>-<first extension> |
role |
editor (default) or viewer |
macOS's CFBundleTypeRole; Linux and Windows have no equivalent |
icon |
optional | a document icon; without it, the OS's generic one |
uti |
optional | macOS's type identifier; default <identifier>.<first extension> |
owned |
true (default) |
the app defines the type (exported); false for a type another app or the system defines (md, txt), imported and only offered as "Open With" |
App::opens([...]) lists the extensions the running app accepts. The bundle
gets the OS to offer the app, and the app decides what it takes, so a file
with another extension (via "Open With…" → Other) is turned away. rata check reports a declared extension the app doesn't open, and one it opens
that no document type declares.
Registration (rata bundle)
- macOS: the
Info.plistgetsCFBundleDocumentTypes, one entry per type withCFBundleTypeName,CFBundleTypeRole,LSItemContentTypes[<uti>]andLSHandlerRank(Ownerwhen owned,Alternateotherwise). Owned types also go inUTExportedTypeDeclarations(conforming topublic.data, pluspublic.content, with the extensions and MIME type); the others go inUTImportedTypeDeclarations. An icon is converted to.icnslike the app's own. - Linux (
.deb): the.desktopentry getsMimeType=<mime>;…, andExectakes%F(files) when there are document types, alongside the%ua deep link needs. Owned types get/usr/share/mime/packages/<identifier>.xml(shared-mime-info: the glob, comment and icon).postinstrunsupdate-mime-databaseandupdate-desktop-database. AppImage can't register types without something like appimaged, and the docs say so. - Windows (NSIS): per type a ProgID
<identifier>.<ext>with its name, icon andshell\open\command"<exe>" "%1", and.<ext>→OpenWithProgids. Owned types also become the default; the others are only offered. All of it goes under HKCU, like the scheme, and the uninstaller removes it.SHChangeNotifyruns after both.
App::opens registers nothing at runtime. File types belong to an install,
unlike the scheme that deep_link registers at startup today (open
question 4).
Delivery
A file is accepted when it exists, is a regular file, and has an extension
the app opens. Then it is granted as a ChosenFile and handed over.
- macOS:
Event::Opened { urls }: eachfile://URL is a candidate. Other URLs keep going toelyra:deep-linkas before, and files stop going there. - Windows and Linux at launch: argv. Each argument that isn't a flag or the deep link and names an accepted file is a candidate.
- While running (Windows, Linux): the second process forwards its
candidates through single-instance. The payload becomes a small JSON
object,
{ "url": …, "files": […] }, still capped at 8 KB. A plain string from an older build is still read as the URL. The primary checks every forwarded path again before granting it. - Before the page is ready (all three): accepted files queue up until
documents.initial()takes them. After that, each batch goes out onelyra:open-documentsto every window, and the app decides which window opens it.
The grant
What the OS hands over is something the user chose, so it is granted the
way a dialog's file is. Its kind is FileChoice::Document, new in this RFC:
opened from the OS, to read and to save back to (open question 1).
Frontend and Rust API
documents.initial(): Promise<ChosenFile[]> // the launch files; each is handed out once
documents.onOpen(cb: (files: ChosenFile[]) => void): () => void
App::opens(extensions) // what the app accepts
App::on_open(|ctx: &Ctx, files: Vec<ChosenFile>| { … }) // optional: Rust sees them first
With on_open, Rust handles each batch (to show a window per document, or
to record recents) and the page still gets it.
Testing
- Offline (unit): generating
Info.plist,.desktop, shared-mime XML and NSIS, each with no, one, and several types, owned and not; argv parsing (flags, the deep link, paths with spaces, other extensions, folders, missing files); the single-instance payload both ways, including an old plain string; the queue beforeinitial()and the event after it; and the grant's kind. - CI on Linux: the
.debinstalled in the bundle job, thenxdg-mime query filetype x.<ext>gives the MIME type andxdg-mime query default <mime>gives the app's.desktop. The example app started with a file argument, and the page reads it fromdocuments.initial(). - CI on Windows: after the silent install, the ProgID and
OpenWithProgidsare in HKCU.Start-Process x.<ext>reaches the running app. - CI on macOS:
lsregister -fon the built.app, thenopen x.<ext>. The page gets it fromonOpen(the app is running) and frominitial()(it isn't). If LaunchServices proves flaky on the runner, this part stays checked by hand, and the docs say so.
Implementation plan
[[bundle.documents]]inratatosk/src/config.rs; the plist,.desktop, mime XML,postinstand NSIS output;rata check.App::opensandApp::on_open,FileChoice::Document, argv candidates, the JSON single-instance payload, macOSOpenedsplit into files and URLs, the queue andelyra:open-documents.documentsin@elyra/runtime, codegen's types, and the example app opening a.elyranote.- Tests, CI steps, docs (
docs/documents.md, configuration, single-instance, system), CHANGELOG, roadmap.
Open questions
Answered in Decisions.
- The grant's kind. A new
FileChoice::Document(read and save back), orOpenlike a dropped file? Recommendation:Document. An editor saves back to the file it opened, and withOpenthe app would have to ask a save dialog for a path the user already chose, or ignorekind. Adding a variant toFileChoicebreaks an exhaustivematch, so it's called out under Upgrading (orFileChoicebecomes#[non_exhaustive]in the same release). - Does
opensrepeat the bundle? The extensions could come fromelyra.tomlat build time instead. Recommendation: keepApp::opens. The runtime doesn't readelyra.tomltoday, and a test orcargo runshould behave like the install.rata checkkeeps the two in step. - Which window gets a file? Every window gets the event, or only the
focused one?
Recommendation: every window, and the app decides (a document app
usually has one window that opens tabs, or
on_openopens a window). One window choosing for all makes "a window per document" harder. - Register at runtime too, as
deep_linkdoes on Windows and Linux, forcargo runand an AppImage? Recommendation: no. An app run fromtarget/that claims file types leaves registrations behind that point at a build folder. File types belong to the install. The AppImage limit goes in the docs. - The macOS file URLs on
elyra:deep-linktoday. Stop sending files there at once, or keep them for a release? Recommendation: stop. They were never documented as files, and they arrive ungranted. An app that relied on it gets the change under Upgrading, and its files come fromdocumentsinstead.
Not in this RFC
- "Open Recent" in the Dock and File menus (
NSDocumentController), and Windows jump lists. kver keeps its own recents. - The menu itself (check items, enabled state): that's RFC 0053.
- Quick Look and thumbnail extensions for the app's own types.
- Saving as a type (a save dialog filtered by the declared types)
beyond today's
dialog.save({ filters }). .dmg, found by the same port: its own change torata bundle.
Alternatives considered
- Keep using
deep_linkwith afilescheme: no type registration, an ungranted path, and no argv handling on Windows or Linux. - Rust-only delivery (
on_open, no frontend API): every app would write the same command and event to reach the page. - Plain paths to the frontend instead of
ChosenFile: simpler, but a page could then pass any path to a command, whichChosenFileexists to prevent.
As built
As designed, with these specifics:
Exec=<bin> %Uin the.desktopentry when there are document types, not%uplus%F: the spec allows one field code perExec, and%Uhands over files (as paths orfile://URLs) and a deep link's URL alike. Without document types it stays%u. The app reads both forms from argv.ratatosk/src/documents.rsresolves[[bundle.documents]](unknown keys are an error; an extension with a dot, upper case or declared twice is refused up front) and writes each platform's text: the plist keys, the.desktopMimeType, the shared-mime-info XML, the.deb'spostinstandpostrm, and the NSIS lines.- A type the app doesn't own and names no
utifor is matched byCFBundleTypeExtensionson macOS, so no identifier is made up formd. - The uninstaller removes an extension's default only while it still names the app's ProgID.
- Document icons:
Resources/doc-<ext>.icnson macOS, a 256 px PNG underhicolor/…/mimetypes/<mime>.pngon Linux, anddoc-<ext>.icobeside the.exeon Windows.
- A type the app doesn't own and names no
framework/src/documents.rs:Documentsis bound in the container when the appopensanything. The router serves/__documents/initial, and the event loop feeds it from argv at start, fromEvent::Opened'sfile://URLs (other URLs still go toelyra:deep-link), and from a second launch's payload. Argv is read on every platform, so a terminal on macOS works too. Accepted files are canonical, with Windows'\\?\prefix taken off for a drive path.- The single-instance payload stays the URL alone unless the launch has
documents: then
{"url", "files"}.elyra:second-instancegets the URL only. - A read-only window can't call
/__documents/initial: it hands the launch's files out once, so Quick Look could otherwise take the main window's. FileChoice::readable()andwritable():Backend::download_toand a transcription use them, so adocumentis saved to and read likesaveandopenfiles.rata check:document-not-opened(an error) anddocument-not-registered(a warning), fromopensin the app'sELYRA_CHECKshape. An app on an older Elyra says nothing, and nothing is found.- Tests: rata's generated text for each platform; argv parsing, the
queue and the event, the payload both ways,
accepts; the runtime'sdocuments; the route closed to read-only windows. CI: the bundle job checks the.app's plist, the installed.deb's desktop entry and MIME package (andglobs2whereupdate-mime-databaseran), and the Windows installer's ProgID, default app and "Open With" entry, all gone after uninstalling. The running-app walk-throughs on macOS, Linux and Windows start the example with a.elyranoteon its command line and find the note on the page. - Checked by hand on macOS: a debug
.appregistered withlsregister, thenopenon a.elyranoteat launch (initial()) and while running (onOpen), and a second launch's file forwarded through single-instance. Double-clicking in Explorer and the file manager on Linux hasn't been tried; their command-line path is what CI drives.
Decisions
FileChoice::Document: opened from the OS, to read and save back. It's called out under Upgrading (an exhaustivematchneeds the arm).App::opensstays, andrata checkkeeps it in step with[[bundle.documents]].- Every window gets
elyra:open-documents, and the app decides. - No runtime registration: file types belong to the install, and the AppImage limit is documented.
- Files stop going to
elyra:deep-linkon macOS at once, under Upgrading.