Skip to content

feat(platform): add desktop Tx::open_path and Tx::reveal_path with headless Runtime::take_path_requests - #1947

Merged
Hona merged 1 commit into
devfrom
feat/147-open-path
Nov 24, 2026
Merged

Hona merged 1 commit into
devfrom
feat/147-open-path

Conversation

@Hona

@Hona Hona commented Nov 24, 2026

Copy link
Copy Markdown
Member

Fixes #147

Adds desktop Tx::open_path and Tx::reveal_path alongside headless Runtime::take_path_requests, keeping Tx::open_url strictly limited to http:, https:, and mailto: links.

API

use std::path::Path;
use rune::{OpenPathError, PathAction, PathRequest, Tx};

// From a handler: syntax-checked only (no UI-thread stat), executed off the UI thread after the frame.
tx.open_path(Path::new("/path/to/file-or-folder"))?;
tx.reveal_path(Path::new("/path/to/file"))?;

// In headless tests:
let requests: Vec<PathRequest> = rt.take_path_requests();
  • Types: OpenPathError::{Empty, Invalid, Unsupported, Failed(String)}, PathAction::{Open, Reveal}, and PathRequest { path: PathBuf, action: PathAction } re-exported from rune.
  • Handlers: Tx::open_path(impl AsRef<Path>) and Tx::reveal_path(impl AsRef<Path>) validate syntax only (Empty, embedded NUL -> Invalid, non-desktop targets -> Unsupported), obeying Rune's no-file-I/O-in-frame-loop rule.
  • Headless: Runtime::take_path_requests() drains captured requests; headless CLI runs log unexecuted open_path / reveal_path requests beside open_url.
  • Example: examples/drop-files shows accessible Open and Reveal buttons for dropped file paths (plus a --scene dropped scene).

Frame & Platform Flow

flowchart LR
    H["Handler: tx.open_path / tx.reveal_path"] --> V{"Syntax check (no I/O)"}
    V -->|Empty / NUL / non-desktop| E["Err(OpenPathError)"]
    V -->|Ok| Q["Tx.open_paths"]
    Q -->|End of frame| D{"open_urls_natively?"}
    D -->|false: headless / tests| R["Runtime::take_path_requests()"]
    D -->|true: desktop| W["Background worker (off UI thread)"]
    W --> M["macOS: stat on worker -> mainQueue NSWorkspace"]
    W --> Win["Windows: STA worker ShellExecuteW / SHOpenFolderAndSelectItems"]
    W --> L["Linux: portal worker OpenURI.OpenFile / FileManager1.ShowItems -> OpenURI.OpenDirectory -> xdg-open"]
Loading

Outside Answers Followed

  • Electron (shell.openPath / shell.showItemInFolder) and Rune's Tx::open_url (crates/rune/src/open_url.rs): separate desktop path APIs from web/mail URLs, queued on Tx and drained after the frame, captured in headless runs.
  • Apple AppKit / Chromium platform_util_mac.mm: NSWorkspace openURL:configuration:completionHandler: (fallback openURL:) and activateFileViewerSelectingURLs: on the main queue with NSURL::fileURLWithPath_isDirectory: after background path resolution/metadata check so the UI thread never stats and AppKit never runs off the main thread.
  • Win32 Shell: STA worker calling ShellExecuteW (default verb) for open and ILCreateFromPathW + SHOpenFolderAndSelectItems(pidl, None, 0) + ILFree for reveal, normalizing slashes and \\?\ verbatim prefixes.
  • Freedesktop XDG Desktop Portal & FileManager1: org.freedesktop.portal.OpenURI.OpenFile opens both files and directories; reveal tries org.freedesktop.FileManager1.ShowItems (RFC 8089 file:// URI), then org.freedesktop.portal.OpenURI.OpenDirectory, then xdg-open on the parent folder.

Not Checked Live

  • Real OS launches (Finder, Windows Explorer, GNOME Files / portal / xdg-open) and live interactive windows were not launched on a desktop; native dispatch is covered through a unit-tested seam (HostState::dispatch_paths) and platform-specific compilation/unit tests.

@Hona
Hona force-pushed the feat/147-open-path branch from 37cd875 to f3e3846 Compare November 24, 2026 14:43
@Hona
Hona force-pushed the feat/147-open-path branch from f3e3846 to 217e28f Compare November 24, 2026 14:57
@Hona
Hona merged commit e725e06 into dev Nov 24, 2026
@Hona
Hona deleted the feat/147-open-path branch November 24, 2026 14:57
Hona added a commit that referenced this pull request Nov 25, 2026
…une and procwatch (#2370)

A feature-set warning sweep across Linux, macOS, Windows, and wasm32 found
eight dead-code warnings under optional and non-default feature sets:

- `crates/rune/src/open_path.rs:203` (`file_uri_from_bytes`, added in #1947):
  used on Unix only under `feature = "dbus"` (FileManager1) and tests; gate
  with `feature = "dbus"` alongside `test`.
- `crates/rune/src/platform/preferences.rs:77` (`DEFAULT_DOUBLE_CLICK_SECS`,
  added in #1923/#2128): used on Linux only under `feature = "dbus"` and tests;
  gate with `all(target_os = "linux", feature = "dbus")` alongside `test`.
- `crates/rune/src/window/titlebar/linux.rs:82` (`Sides::ALL`, added in #2244):
  used only in `linux_tests.rs`; gate with `#[cfg(test)]`.
- `crates/rune/src/frame/live_log.rs:33` (`CAPTURED` / `capture_frames`, added
  in #2309): used only in `window/win32/resize_sync/tests.rs` under
  `frame-profile`; gate with `#[cfg(all(test, target_os = "windows"))]`.
- `crates/procwatch/src/alloc/sites.rs:222,271,413,418` (`report`, `unsampled`,
  `os::modules`, `os::nt_heaps`, added in #744): `alloc-sites` sampling and
  dumper are Windows-only; gate the implementation behind `#[cfg(windows)]`
  with clean `#[cfg(not(windows))]` no-op stubs.
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.

Desktop: no way to open a local folder or reveal a file, because Tx::open_url refuses file: links

1 participant