Expand description
A single instance, and deep links.
single, called at the top of main, before any window: the first
launch listens on a local socket named after the application (an
abstract socket on Linux, a named pipe on Windows, a socket in /tmp
elsewhere) and gets Single::First; a later launch hands its
arguments, its working directory and its activation token to the
running one and gets Single::Handed: it exits.
InstancePlugin takes what the first launch holds into the
application. Its steps (ADR 0011):
instance.second_launch: a later launch handed over, with{ "args", "cwd", "links" }(links: the arguments in one of the plugin’sschemes). By default the main window comes to the front (crate::window::raise) and each link runsdeeplink.open. Veto it to stay in the background; replace it to open the files a second launch names.deeplink.open: a link to open,{ "url", "origin" }, from a later launch or from the first launch’s own arguments (at start). By default the plugin’slinkscommand runs with{ "url" }; without one the step fails, and says so.
A link from a launch is not the user’s gesture: any program of the
user’s (a web page in a browser, another application) may launch the
application with one. Its command runs as deeplink_origin
(Origin::Remote("deeplink"), remote:deeplink on the journal and in
the step’s origin): the handler sees it in Call::origin, the
commands it starts inherit it, it may not run one as the user, and it
writes values as remote:deeplink, held to their writers. A handler
that changes or deletes anything on a link asks the user first (a
dialog: the user’s answer runs as the user). A link of the
application’s scheme clicked inside the application runs as the click
did.
The launches handed over are kept (LAUNCHES, Launches::history);
Launches::deliver hands one over in-process, as a test or the
gallery does.
Without App and its plugin, single works the same; the
application takes the later launches itself: Instance::launches
from Single::First, Launches::set_waker with its egui context
so a launch handed over repaints the window, and Launches::take
each frame (bringing the window to the front with
crate::window::raise, opening what the launch names). Registering the scheme with the system is the
packager’s part: see docs/packaging.md.
On Linux a connection from another user is refused (the abstract
socket namespace is shared by the users of a machine). Inside a
Flatpak sandbox the socket is a file in the directory the
application’s sandboxes share (flatpak_socket). Elsewhere the
socket or pipe is the user’s own by its place (/tmp with the user’s
name in the socket’s, a pipe in the user’s session).
use egui_pop_api::App;
use egui_pop_platform::instance::{self, InstancePlugin, Launch};
let launch = Launch { args: vec!["demo://open/7".into()], ..Launch::default() };
let first = instance::Instance::detached(launch);
let ctx = egui::Context::default();
let mut app = App::builder()
.plugin(InstancePlugin::new(first).scheme("demo"))
.build(&ctx)
.unwrap();
app.logic(&ctx);
// No command opens links: the step says so.
let trace = app.handle().step_traces().into_iter().rev()
.find(|t| t.step.as_str() == "deeplink.open").unwrap();
assert_eq!(trace.args["url"], "demo://open/7");Structs§
- Instance
- The first launch: what it was launched with, and the launches the later ones hand over.
- Instance
Plugin - The single instance in the application (see the module).
- Launch
- What a launch says: its arguments (without the program), its working
directory, and the activation token the desktop gave it
(
XDG_ACTIVATION_TOKEN,DESKTOP_STARTUP_ID). - Launches
- The launches handed over to this one: shared with the thread that listens, taken at the next pass of the application.
Enums§
Constants§
- CMD_
DEEPLINK - Opens a link of the application’s own scheme (
url), throughSTEP_DEEPLINK: what the links service runs for a click on one. - HISTORY
- How many launches
Launches::historykeeps. - LAUNCHES
- The launches handed over, as a service.
- PLUGIN
- The plugin’s id.
- STEP_
DEEPLINK - A link to open:
{ "url" }. - STEP_
SECOND_ LAUNCH - A later launch handed over:
{ "args", "cwd", "links" }.
Functions§
- deeplink_
origin - The origin of a link from outside the application: a launch, the first one’s arguments or a later one’s through the single-instance socket. Any program of the user’s may launch the application with a link (a web page’s, another application’s), so the link is not the user’s own gesture.
- flatpak_
socket - Inside a Flatpak sandbox, the socket’s file in the directory every
instance of the application shares (
$XDG_RUNTIME_DIR/app/<id>): each sandbox may have a network namespace of its own, where abstract sockets are not seen. - flatpak_
socket_ with flatpak_socketfrom the environmentenvgives.- single
- Makes this launch the application’s only instance, or hands it to the
one running (see the module).
app_id: a reverse-DNS id (org.example.App). - single_
with singlewith a launch of the caller’s.- socket_
name - The socket’s name for an application: its id and the user’s name, kept to what every platform accepts.