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.
Drawing a link
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-listitem with its text); - is a
linkfor 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:
| Target | A click | Ctrl+click, middle click |
|---|---|---|
Web page (https:, http:) | the system browser; a new tab on the web build | the 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 file | the viewer’s video page with views-video (see below), else as a local file | outside |
mailto: | the mail client (the same tab on the web, which hands it over) | the same |
docs: page | the viewer when there is one (see below), else its online copy (Policy::docs_online) | outside |
| Local file | its default application, after a confirmation; a program refused, Show in folder offered | Show in folder |
| Local folder | the file manager | the same |
The application’s own scheme (<app>://) | deeplink.open, inside | the same |
command:<id>?<json> | runs the command, from declared text only | nothing |
Anything else (javascript:, data:, a device, an unknown scheme) | blocked, with the reason | blocked |
Trust
Every request says where it comes from: declared by the application, found in content, or asked by an agent.
| Source | Web and mail | Local file | Show in folder | Command |
|---|---|---|---|---|
| Declared | opens | confirmed | opens | runs |
| Content | opens when its host is trusted, else confirmed | confirmed | confirmed | refused |
| Agent | always confirmed | always confirmed | always confirmed | refused |
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
- 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,commandand 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’sOpenUrl; on native eframe’slinksfeature (webbrowser) opens the system browser, on the web a new tab (mailto:in the same tab).SystemOpener(egui_pop::platform::open, featureplatform-open; install it withOpenPlugin): 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-openis 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
| Command | What |
|---|---|
links.open | target, 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.check | target, how, source: the policy’s decision and the opener’s capabilities, without the step |
files.reveal | path: shows a file in its folder |
links.copy | target: 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):
| Written | Drawn |
|---|---|
*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 (adocs: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 runcommand:links), another page’s are content; anotherdocs: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-htmlfeature (see below), local video files with theviews-videofeature (see below), YouTube videos with theviews-webviewfeature 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::Fetchthe 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 fromhostare not loaded” with Load images fromhost; the host is then remembered in theviewer.image_hostssetting (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: itsfile:image shows its alt text and is named in the bar over the page and inviewer.state’sdropped, 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.failedon the journal.
| Command | What |
|---|---|
viewer.back, viewer.forward, viewer.reload | the history |
viewer.find | query: searches the page and goes to its first match |
viewer.find_next, viewer.find_previous | the matches |
viewer.zoom_in, viewer.zoom_out, viewer.zoom_reset | the page’s zoom |
viewer.open_outside, viewer.copy_link | the page’s address |
viewer.state | the 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_quieter | a video page’s keys |
viewer.video_seek, viewer.video_volume | seconds, 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.
| Kept | As |
|---|---|
h1 to h6 (with id) | headings and their anchors |
p, div, section, article and their like | paragraphs |
ul, ol (with start), li, dl, dt, dd | lists |
table, thead, tbody, tr, th, td, caption | a table, its first row as the header; no cell spans |
blockquote, pre, hr | quotes, code, a rule |
em, strong, del, code, kbd, q, br and their like | inline styles |
a href | a link, through the links service |
img src alt | an image, through the same rules as markdown’s |
- Dropped with their content, and named in a bar over the page:
script,formand its controls,iframe,object,embed,audio,video,canvas,template,dialog, foreignsvgandmath. The bar says Open outside shows the page whole;viewer.statelists them asdropped. - 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 ondocs:pages,file:not on pages from the network (afile: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 adocs: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).
| Control | Mouse | Keys |
|---|---|---|
| Play, Pause | Play or Pause, or a click on the picture | Space on the picture |
| Position | the slider (a drag seeks when it ends) | Left and Right on the picture, five seconds; the slider’s own keys |
| Volume | the slider, kept for the session | Up 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-devandlibgstreamer-plugins-base1.0-devon 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.failedon 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_sinknames the element the sound goes to, kept in time with the pictures even when silent (fakesink). Both are also named underviewer::, as before the widget.video::write_test_clipwrites 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 aRefererthat 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 anhttpsURL whose domain is the application’s id. It is built fromAppBuilder::app_id(reverse-DNS,org.example.App;run_nativetakes the window’sViewportBuilder::with_app_idwhen none is given) ashttps://<app id>/, lowercased (viewer::referrer_for);ViewerPlugin::embed_referrerreplaces it. Without either, YouTube links open outside and a warning is logged. The gallery sendshttps://org.egui_pop.gallery/(its idorg.egui_pop.Gallery). Nooriginorwidget_referrerplayer parameter is sent:origingoes with the IFrame API (enablejsapi=1), which the page does not use, andwidget_referrernames 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, whichAppBuilder::run_nativecalls; an application starting eframe itself calls it from its creation context. - What it needs. To build: WebKitGTK’s development packages
(
libwebkit2gtk-4.1-devon Debian and Ubuntu,webkit2gtk4.1-develon 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(throughdirs), is MPL-2.0;deny.tomlallows 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; itsin_panelsays 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.