Expand description
Desktop notifications with actions, routed to commands, falling back to an in-app toast.
Experimental: may change in any release
(docs/stability.md).
A Notification has a title, a body, a level, actions (each a
label and a command with its arguments) and a command for a click on
its body. show shows one now (on the interface thread);
Notifier::post queues one from any thread, shown at the next
pass. Both go through the steps (ADR 0011):
notify.show: the notification, as JSON (its fields andid). By default it goes to the desktop (notify-rust: the XDG notification server on Linux and BSD, the notification centre on macOS, toasts on Windows) as thenotifications.desktopsetting says (always,unfocused: only while the window does not have the focus,never), else, and whenever the desktop has no notification server or fails, to a toast (TOASTS, its first action as the toast’s). The result says where:{ "id", "via": "desktop" | "toast" }. Replace it to send notifications elsewhere; veto it to keep quiet (do-not-disturb).notify.action: the user picked an action, on the desktop or on the toast:{ "id", "action", "command", "args" }(action: the action’s id, ordefaultfor a click on the body). By default its command runs through the host;defaultalso brings the window to the front.
Desktop notifications are shown from a thread of their own (a D-Bus
call can block), so a failure arrives at a later pass: it shows the
toast then and publishes notify.failed ({ "id", "error" }).
use egui_pop_api::App;
use egui_pop_api::toasts::{TOASTS, ToastsPlugin};
use egui_pop_model::ids::CommandId;
use egui_pop_platform::notify::{self, Notification, NotifyPlugin, Simulated};
let ctx = egui::Context::default();
let desktop = Simulated::unavailable("no notification server");
let app = App::builder()
.plugin(ToastsPlugin)
.plugin(NotifyPlugin::new("Demo").backend(desktop))
.build(&ctx)
.unwrap();
let n = Notification::new("Export done", "3 images in ~/Pictures")
.action("show", "Show", CommandId::from_static("files.reveal"), serde_json::json!({}));
let out = notify::show(app.handle(), n);
assert_eq!(out.result().unwrap().as_ref().unwrap()["via"], "toast");
assert_eq!(app.handle().service(&TOASTS).unwrap().shown().len(), 1);Structs§
- Action
- An action offered with a notification: a button on the desktop.
- Desktop
- The desktop’s notifications, through notify-rust.
- Notification
- A notification.
- Notifier
- The notifications, as a service: post from any thread, read what was shown and where. Cheap to clone (shared).
- Notify
Plugin - Desktop notifications, as a plugin (see the module).
- Shown
- A notification shown, as kept.
- Simulated
- A desktop that records what it shows;
Simulated::clickanswers as the user would. For tests and the gallery.
Enums§
- Level
- How much a notification matters: its toast’s level, its urgency on the desktop.
- Via
- Where a notification went.
Constants§
- CMD_ACT
- The command a toast’s action runs, to go through
notify.action({ "id", "action" }). - FAILED
- The signal published when the desktop failed to show one.
- HISTORY
- How many notifications
Notifier::historykeeps. - NOTIFIER
- The notifier, as a service.
- PLUGIN
- The plugin’s id.
- SETTING_
DESKTOP - Where notifications show:
alwayson the desktop,unfocused(while the window does not have the focus),never(toasts only). - STEP_
ACTION - An action picked:
{ "id", "action", "command", "args" }. - STEP_
SHOW - A notification to show: its fields and
id.
Traits§
- Backend
- What shows notifications on the desktop.
Desktopis the real one;Simulatedrecords them, for tests and the gallery.
Functions§
- show
- Shows a notification now, through
notify.show(on the interface thread;Notifier::postfrom others). Without the plugin, the step runs nowhere and says so.