Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Links

Every link in an egui-pop application opens the same way: through one service, one policy and one step, with an opener the host may replace. The decision and its reasons are ADR 0017; this page is how to use it. Everything below is egui_pop::api::links (the service, the widget, the openers, the plugin) and egui_pop::model::links (targets, requests, the policy, no egui). LinksPlugin is in DefaultPlugins.

use egui_pop::api::links::{self, Link};

// A link the application declares (About, help, a tip).
links::link(ui, app, "Source code", "https://github.com/me/app");
// A link found in content (a document, a program's output).
Link::content("the report", "https://example.org/report").show(ui, app);

The widget draws in the theme’s link colour with a pointing hand, and:

  • shows the real target on hover: the full address, then its host (an internationalised host with its punycode beside it, bücher.example (xn--bcher-kva.example));
  • opens on a click, Enter or Space; Ctrl+click (Cmd+click on macOS) or a middle click opens it outside;
  • has a context menu: Open, Open outside (when it would open inside), Show in folder (a local file or folder), Copy link (through the clipboard: a text/uri-list item with its text);
  • is a link for screen readers, its label as its name and its target as its description.

A link whose text looks like an address (https://bank.example, bank.example/login) but goes elsewhere is always confirmed, both shown.

ui.hyperlink, ui.hyperlink_to, a third-party widget or ctx.open_url still work: their OpenUrl is taken out of each frame’s output and opened through the same service on the next pass, as a declared link for http(s): and mailto:, as content otherwise. Nothing reaches the browser without the policy.

What a click does

The policy classifies the target from its scheme, host and extension (never by fetching it) and picks the way:

TargetA clickCtrl+click, middle click
Web page (https:, http:)the system browser; a new tab on the web buildthe same
Video on the web (YouTube, Vimeo, a remote video file)the browser; a YouTube video in the viewer’s web view with views-webview on Linux (see below)the same
Local video filethe viewer’s video page with views-video (see below), else as a local fileoutside
mailto:the mail client (the same tab on the web, which hands it over)the same
docs: pagethe viewer when there is one (see below), else its online copy (Policy::docs_online)outside
Local fileits default application, after a confirmation; a program refused, Show in folder offeredShow in folder
Local folderthe file managerthe same
The application’s own scheme (<app>://)deeplink.open, insidethe same
command:<id>?<json>runs the command, from declared text onlynothing
Anything else (javascript:, data:, a device, an unknown scheme)blocked, with the reasonblocked

Trust

Every request says where it comes from: declared by the application, found in content, or asked by an agent.

SourceWeb and mailLocal fileShow in folderCommand
Declaredopensconfirmedopensruns
Contentopens when its host is trusted, else confirmedconfirmedconfirmedrefused
Agentalways confirmedalways confirmedalways confirmedrefused

The confirmation shows the full target, its host (and punycode), why it asks, Copy link, Open and Cancel; for a content link to an untrusted host, Trust for this session (the host and its subdomains, until the application quits). Only the user answers it: an agent answering through the debug bridge is refused (it may cancel).

  • Content opens only on a click: a content request not made by the user is refused.
  • A program or a script (by its extension, or the executable bit of a file without one) is never opened; Show in folder is offered instead.
  • An agent has one confirmation open at a time; five more requests wait behind it, then the next is refused with the reason.
  • Allowed schemes: https, http, mailto, file, docs, command and the application’s own (the single-instance plugin adds its schemes). The host changes the policy through the service:
use egui_pop::api::links::{LINKS, LinksPlugin, Policy};

App::builder().plugin(
    LinksPlugin::default().policy(
        Policy::default()
            .app_scheme("helios")
            .docs_host("docs.example.org"),
    ),
);
// Later: app.service(&LINKS).unwrap().update_policy(|p| { p.schemes.remove("http"); });

Openers

The opening itself is an Opener the host replaces (ADR 0010):

  • EguiOpener (the default): web pages and mail through egui’s OpenUrl; on native eframe’s links feature (webbrowser) opens the system browser, on the web a new tab (mailto: in the same tab).
  • SystemOpener (egui_pop::platform::open, feature platform-open; install it with OpenPlugin): local files and folders with the system’s default application, and Show in folder (the file manager with the file selected: the freedesktop file manager interface, else the OpenURI portal; open -R; Explorer). Inside Flatpak, xdg-open is the portal’s. Not on the web.
  • RecordingOpener (tests): records each call (target, how, kind, source, origin) and answers as scripted.
  • NullOpener (a node without a screen): refuses with the reason, or forwards each request to an attached interface (NullOpener::forward).
let rec = RecordingOpener::default();
app.service(&LINKS).unwrap().set_opener(Arc::new(rec.clone()));
harness.get_by_role_and_label(Role::Link, "Source code").click();
harness.run();
assert_eq!(rec.records()[0].target, "https://github.com/me/app");

The step and the journal

links::open(app, request) runs the link.open step (ADR 0011): a before-hook vetoes it or redirects it (another target, another way), a run-hook opens it its own way, an after-hook sees the result. Its result says the kind, the way, whether it asked, and the status: opened, opening (an opener answering later), asked or queued (waiting for the user). The journal says link.opened, link.failed (with the reason), link.refused, link.asked and link.cancelled.

A refusal or a failure the user asked for shows in a warning toast with the reason and Copy link (Show in folder for a program).

Commands and agents

CommandWhat
links.opentarget, how (auto, outside, inside, reveal), label, dry_run: opens a link; from an agent, always confirmed; a dry run says the kind, the way, whether it would ask and the verdict, opening nothing
links.checktarget, how, source: the policy’s decision and the opener’s capabilities, without the step
files.revealpath: shows a file in its folder
links.copytarget: copies a link (a toast’s action)

The debug bridge’s links collector shows the opener and what it can do, the policy, the requests waiting for an answer (and queued per agent), the recent requests with their decision and outcome, and the links declared.

The lint

A plugin declares the links it shows (ctx.link(place, target), or links::declare from the application); links drawn with the widget as declared count too. links::lint::problems(app) checks them, with the menu items running links.open or files.reveal, the links in the tips’ texts and the toasts’ actions: each must parse, use an allowed scheme, name a declared command (command:) and a file that is there. In a test, after drawing the screens:

egui_pop_test::assert_links_clean(&app);

The gallery’s links pass it. Checking that remote links answer is not part of it (an opt-in task, never in the gate).

Short texts

Tips, toasts and settings descriptions read a small part of markdown, drawn by links::Inline (links::inline(ui, app, text) for a text the application declares):

WrittenDrawn
*text*, _text_emphasis
**text**, __text__strong
`code`code
[label](target)a link (the widget above)
<https://…>, a bare https://…a link showing its address
\*a literal *

A delimiter without its pair stays as written (2 * 3), _ inside a word too (snake_case_name); a text without any of it is a plain label. Headings, lists, images and HTML are not read there: a longer text belongs in the viewer.

use egui_pop::api::links::Inline;

Inline::new("Press `Ctrl+K`, or read [the guide](docs:guide).")
    .weak()
    .show(ui, app);

The viewer

egui_pop::views::viewer (feature views-markdown) shows pages inside the application: a panel of the end side bar, detachable into its own window like any panel, one page at a time. ViewerPlugin installs it in the links service (Links::set_inside), so what the policy sends inside opens there: docs: pages, markdown and HTML pages on the application’s documentation hosts (Policy::docs_host), local images.

use egui_pop::views::viewer::{Docs, ViewerPlugin};

App::builder().plugin(
    ViewerPlugin::default().docs(
        Docs::new()
            .page("index", include_str!("../help/index.md"))
            .page("guide/start", include_str!("../help/guide/start.md"))
            .file("img/panel.png", include_bytes!("../help/img/panel.png").as_slice()),
    ),
);

A docs: link names a page with or without .md or .html (docs:guide/start), a folder its index (docs:guide/, docs: the root’s), an anchor its heading (docs:guide/start#install, the heading’s text in lower case with dashes, or its {#id}). Links and images in a page resolve against it (../img/panel.png).

  • Toolbar: back and forward (the session’s history, nothing kept across runs), reload, the address bar (the real target; typing a target opens it through the links service, a bare name as a docs: page), Open outside (a docs: page’s online copy), Copy link, the zoom (a click puts it back to 100%).
  • Keys, while the viewer has the focus: Ctrl+F finds in the page, F3 and Shift+F3 (Enter and Shift+Enter in the field) move between the matches, Ctrl+plus, Ctrl+minus and Ctrl+0 zoom the page (not the interface), Alt+Left and Alt+Right go back and forward, F5 reloads.
  • Links in a page go through the links service: a docs: page’s links are declared (they may run command: links), another page’s are content; another docs: page stays inside, a web page goes outside; Ctrl+click or a middle click opens outside.
  • What it shows: markdown (egui_commonmark: tables, task lists, footnotes, code), images (PNG, JPEG, GIF), text, and a safe subset of HTML with the views-html feature (see below), local video files with the views-video feature (see below), YouTube videos with the views-webview feature on Linux (see below). Other remote videos and full web pages are not shown inside: they open outside. Without the feature an HTML page gets an error page offering Open outside.
  • Remote pages and images come through a viewer::Fetch the host gives (ViewerPlugin::fetch); without one nothing remote is loaded and the page says so. A remote image never loads before the user asks: it shows its alt text, and a bar says “Images from host are not loaded” with Load images from host; the host is then remembered in the viewer.image_hosts setting (empty it to be asked again). Images on the page’s own host (a documentation host) load at once. Allowing a host is the user’s alone: agents cannot.
  • Local files load only from a page that is itself local (docs:, file:). A page from the network never reads one: its file: image shows its alt text and is named in the bar over the page and in viewer.state’s dropped, however the address is spelled. Its links still go through the links service, as content.
  • Failures (not found, no connection, too large, a type it cannot show) show an error page in place with Retry, Open outside and Copy link, and viewer.failed on the journal.
CommandWhat
viewer.back, viewer.forward, viewer.reloadthe history
viewer.findquery: searches the page and goes to its first match
viewer.find_next, viewer.find_previousthe matches
viewer.zoom_in, viewer.zoom_out, viewer.zoom_resetthe page’s zoom
viewer.open_outside, viewer.copy_linkthe page’s address
viewer.statethe page (address, status or error, title, headings, text, links, what it did not show), the history, the search, the zoom, the images and the hosts allowed, the video
viewer.video_toggle, viewer.video_back, viewer.video_ahead, viewer.video_louder, viewer.video_quietera video page’s keys
viewer.video_seek, viewer.video_volumeseconds, volume (from 0 to 1): a video page’s position and volume

The HTML subset

With views-html (egui-pop-views/html), the viewer shows HTML pages: those the application ships (Docs::page("about.html", ...)) and those on its documentation hosts. Any other HTML page goes outside, like any web page: the policy decides, as for markdown.

A page is parsed by html5ever, as a browser would (broken markup included), and mapped to markdown, then drawn as the same blocks: find in page, anchors, zoom and links work as on a markdown page.

KeptAs
h1 to h6 (with id)headings and their anchors
p, div, section, article and their likeparagraphs
ul, ol (with start), li, dl, dt, ddlists
table, thead, tbody, tr, th, td, captiona table, its first row as the header; no cell spans
blockquote, pre, hrquotes, code, a rule
em, strong, del, code, kbd, q, br and their likeinline styles
a hrefa link, through the links service
img src altan image, through the same rules as markdown’s
  • Dropped with their content, and named in a bar over the page: script, form and its controls, iframe, object, embed, audio, video, canvas, template, dialog, foreign svg and math. The bar says Open outside shows the page whole; viewer.state lists them as dropped.
  • Never read: every other attribute (on*, style, class, …). <style> is ignored, without being named: the page has the theme’s look. Any other element leaves its text.
  • Links and images keep an address that is relative or whose scheme the policy allows; a link with another (javascript:, data:, vbscript:, an unknown scheme, however spelled) is left as its text, an image as its alt text. command: is kept only on docs: pages, file: not on pages from the network (a file: image refused is named in the bar, as on a markdown page). A kept link still meets the policy when it is clicked: declared on a docs: page, content elsewhere. Remote images wait for the same click as markdown’s.
  • No script runs, no style applies, and nothing is fetched beyond the page and the images allowed.

The video page

With views-video (egui-pop-views/video, off by default), a local video file (.mp4, .webm, .mov, .mkv, .ogv, .m4v, .avi) opens in the viewer. Without the feature, on the web build, or with no player, it opens outside as any local file. A remote video stays outside either way. The page is the Video widget with its full controls, under the id egui_pop.viewer (so the video.* commands and the videos collector reach it too).

ControlMouseKeys
Play, PausePlay or Pause, or a click on the pictureSpace on the picture
Positionthe slider (a drag seeks when it ends)Left and Right on the picture, five seconds; the slider’s own keys
Volumethe slider, kept for the sessionUp and Down on the picture; the slider’s own keys
  • It opens paused on its first picture, with the focus on the picture, so that nothing makes a sound before the user asks.
  • GStreamer’s threads decode and convert; each pass uploads only the last picture. Only a playing video asks for repaints.
  • Leaving the page stops the player. So does its panel going out of view (closed, or a tab behind another): showing it again opens the file at the same place, paused.
  • What it needs. To build: GStreamer’s development packages (libgstreamer1.0-dev and libgstreamer-plugins-base1.0-dev on Debian and Ubuntu). To run: GStreamer’s libraries, its base plugins, and the plugins for the files to play. The crates are MIT OR Apache-2.0; GStreamer itself is LGPL and stays a system library.
  • Failures (a plugin or a codec missing, a file it cannot read) end on the error page, with Retry, Open outside and Copy link, and viewer.failed on the journal; a problem it plays on through (no sound device) is a line on the page. The binary links GStreamer’s libraries: without them installed it does not start, so an application declares them as a dependency of its package.
  • video::VideoBackend (ViewerPlugin::video) replaces the player; video::GStreamer::audio_sink names the element the sound goes to, kept in time with the pictures even when silent (fakesink). Both are also named under viewer::, as before the widget.
  • video::write_test_clip writes a small clip from GStreamer’s test sources, for tests and the gallery’s Video page (cargo run -p egui-pop-gallery --features video).

The YouTube page

With views-webview (egui-pop-views/webview, off by default, Linux only for now), a YouTube link (youtube.com/watch?v=, youtu.be/, embed/, shorts/, live/) plays in the viewer, in a web view: wry (MIT OR Apache-2.0) over the system’s WebKitGTK. Without the feature, on another system, on the web build, or when Ctrl+click or a middle click asks for outside, it opens in the browser as before. Other remote video stays outside either way.

  • What loads: YouTube’s privacy-enhanced player, https://www.youtube-nocookie.com/embed/<id>, as the web view’s page, its request carrying a Referer that names the application: YouTube’s player refuses to play without one (its error 153), and YouTube’s Required Minimum Functionality asks a desktop application to set it as a header, to an https URL whose domain is the application’s id. It is built from AppBuilder::app_id (reverse-DNS, org.example.App; run_native takes the window’s ViewportBuilder::with_app_id when none is given) as https://<app id>/, lowercased (viewer::referrer_for); ViewerPlugin::embed_referrer replaces it. Without either, YouTube links open outside and a warning is logged. The gallery sends https://org.egui_pop.gallery/ (its id org.egui_pop.Gallery). No origin or widget_referrer player parameter is sent: origin goes with the IFrame API (enablejsapi=1), which the page does not use, and widget_referrer names a page a widget is embedded in, which there is not (player parameters). Nothing else loads in the web view: a link the player follows (its title, “Watch on YouTube”) is opened outside through the links service, as content.
  • Its size: the player gets at least 200 by 200 of the web view’s pixels (viewer::MIN_PLAYER), YouTube’s minimum: its place in the panel is 16:9 and at least 200 tall when the panel allows. Over a panel too small for that, the web view is closed and a card says why, with Open outside; it opens again, from the start, when the panel grows. The web view’s pixels are the window’s physical pixels divided by the system’s scale: on a 2x screen the panel needs 400 physical pixels each way (viewer::fits_player). Its own window cannot be made smaller than 200 by 200.
  • Nothing over the player: the page draws only a background and a word under the web view, which covers them; no control, badge or popup of egui-pop’s is drawn on the player (egui’s popups could not be anyway: the web view is a native window above egui).
  • Where: on X11 (or Xwayland), with the panel in the main window, the web view is a child window over the panel, following it as it moves and resizes. On Wayland, or with the panel detached, it opens in a window of its own (wry’s child web views need X11); the page then says so, and once that window is closed offers Show the video. A child web view is a native window above egui: popups over the panel are drawn under it.
  • Its loop: GTK starts on the interface’s thread when the first web view opens (on X11 when the main window is an X11 one), and its loop is turned without blocking once per pass; while a web view is open the page asks for a pass every 15 ms (viewer::PUMP).
  • Leaving the page closes the web view. So does its panel going out of view, or the user closing its own window: showing it again starts the video again.
  • The main window’s X11 id comes from frame::record_native_window, which AppBuilder::run_native calls; an application starting eframe itself calls it from its creation context.
  • What it needs. To build: WebKitGTK’s development packages (libwebkit2gtk-4.1-dev on Debian and Ubuntu, webkit2gtk4.1-devel on Fedora). To run: WebKitGTK 4.1 and GStreamer’s plugins for the video’s codecs. The binary links WebKitGTK: without it installed it does not start. One crate wry brings on Linux, option-ext (through dirs), is MPL-2.0; deny.toml allows it as a narrow exception for that crate alone (ADR 0017).
  • Failures (WebKitGTK cannot start, the web view cannot open) end on the error page, with Retry, Open outside and Copy link.
  • viewer::EmbedBackend (ViewerPlugin::web_video) replaces the web view; its in_panel says whether a web view sits over the panel (whose size is then checked) or in a window of its own (which it keeps at the minimum).

Terms

YouTube allows its videos in an application through its own embedded player only (YouTube Terms of Service, API Services Terms, Developer Policies). That is all this page does: the official player, unmodified, loaded from YouTube, its links opened outside. Extracting the stream to play it in another player, downloading or caching it, or drawing over the player is ruled out, and egui-pop will not do it. The page follows the Required Minimum Functionality egui-pop controls (the Referer naming the application, the 200 by 200 minimum, nothing over the player, one player, playing only once shown). An application turning webview on accepts YouTube’s terms for itself, and owns what they ask of it beyond egui-pop: an application id that is really its own, and being able to be updated remotely (Developer Policies III.B.1), which is its packaging’s part.

The viewer collector of the debug bridge shows the same state; viewer.shown and viewer.failed go on the journal. The lint checks declared docs: links against the pages the viewer has.

Not yet

  • The lint does not yet walk the links inside docs: pages.
  • No general web view: full web pages and remote videos other than YouTube open outside. The YouTube page is a trial (ADR 0017); it has no Windows or macOS backend yet.