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

Notices

How egui-pop shows a message in sentences: an error, a warning, a success, a piece of information. This page starts with the widget that draws one inside a page, then the model behind messages: one notice, raised once on the bus, kept by egui-pop’s store, and shown by the views a routing policy picks (a note in its page, a toast, the status bar’s bell, the Notices panel); how notices outlive the session; then how a command’s failure becomes a notice.

Note: a message inside a page

A Note (egui_pop::core::note) is a message drawn where it belongs: under a form’s field, at the top of a settings page, in a list. Use it for sentences; a short state (NEW, Offline) stays a badge (micro-indicators).

  • Its severity (Info, Success, Warning, Error) gives its symbol from the icon registry, named and tooltipped with the severity’s word, and its colour.
  • Its headline says what happened in plain words. An optional reason says why, and a hint what to do.
  • Its details hold the technical chain (an error’s sources), folded under “Details” until opened.
  • Every text wraps to the width given and can be selected.
  • Copy copies the headline, the reason, the hint, the details and the time the note was first shown (or the time given with .time).
  • Its actions are buttons; show_with adds widgets of your own after them.
  • For screen readers it is a group with the Alert role (an error, a warning) or the Status role, holding its text. It is announced when it appears or its text changes, at once for an error.
use egui_pop::core::note::Note;

fn page(ui: &mut egui_pop::egui::Ui) {
    let r = Note::error("cloudy was not added")
        .reason("The network found no route to it.")
        .hint("Check that cloudy is on and on the same network.")
        .details("cannot enrol with cloudy: connect: No route to host (os error 113)")
        .action("Try again")
        .show(ui);
    if r.action == Some(0) {
        // Try again.
    }
}

Note::compact draws one line after the symbol: wrapped and selectable, with no frame, no Copy button and no announcement (a toned title in a list, a reason beside a button).

In admin forms

Admin forms (admin forms) draw their messages as notes: a callout, a status whose read-out is a sentence or whose read failed, a store’s errors, a list’s error, a wizard’s problems. A toned list title or table cell stays a badge while short, and becomes a compact note when it is a sentence.

The notice: one message, raised once

A Notice (egui_pop_model::notice::Notice) is the message as data, without egui, so a background service or a node on another machine raises the same fact as the interface:

  • an id (n42; a notice from another node carries the node’s name, cloudy/n42) and a time (at_ms, milliseconds since 1970, UTC);
  • a severity: Info, Success, Warning, Error;
  • a kind: an Event (it happened once), a Condition (a state that lasts until it is resolved: a node offline, a disk full) or an Ask (a question waiting for the user);
  • an origin: User (their own action), Background, Node (with its node) or System;
  • a headline, and optionally a reason, a hint and details (the technical chain, copyable; details_from writes an error and its sources);
  • its actions: an id and a label each, and optionally the arguments its command runs with (.action_with(id, label, args), a JSON value: “Undo this restore” with {"restore": 7});
  • a subject (what it is about: node:cloudy, job:backup-7) and a place (where it happened in the interface: settings/storage/nodes).

Its JSON shape is stable: fields are added, never renamed, empty ones are left out (an action without arguments writes no args), and v (egui_pop_model::notice::VERSION) rises if a field changes meaning.

{
  "v": 1,
  "id": "n42",
  "at_ms": 1796121723000,
  "severity": "error",
  "kind": "event",
  "origin": "user",
  "headline": "cloudy was not added",
  "reason": "The network found no route to it.",
  "details": "cannot enrol with cloudy: connect: No route to host (os error 113)",
  "actions": [
    { "id": "nodes.add", "label": "Try again", "args": { "node": "cloudy" } }
  ],
  "subject": "node:cloudy",
  "place": "settings/storage/nodes"
}

On the bus

Notices are facts on the application’s bus, under egui-pop’s pop. prefix:

PointCarriesSaid when
pop.notice.raiseda Noticea notice is raised, by any module, plugin or node
pop.notice.resolved{ "ids": [...] }conditions ended
pop.notice.seen{ "ids": [...] }notices were read
pop.notice.dismissed{ "ids": [...] }the user put notices away

egui-pop’s listener pop.notices.store keeps the last notices raised (500 and 30 days, oldest out first, errors not seen yet kept until seen: see Persistence), marks them seen or resolved and drops the dismissed ones; it runs on any thread. A process holding the bus but no application publishes on the same points by name (egui_pop_model::notice::points); a notice raised without an id gets one from the store.

Reporting

AppHandle::report is the one call for a message to the user: it gives the notice an id and a time when it has none, says pop.notice.raised and returns the id. resolve_notice, see_notice and dismiss_notice say the other points; notices reads the store.

use egui_pop::api::AppHandle;
use egui_pop::model::notice::Notice;

fn add_failed(app: &AppHandle, err: &std::io::Error) {
    let id = app.report(
        Notice::error("cloudy was not added")
            .reason("The network found no route to it.")
            .hint("Check that cloudy is on and on the same network.")
            .details_from(err)
            .subject("node:cloudy")
            .place("settings/storage/nodes")
            .action("nodes.add", "Try again"),
    );
    // Later, when cloudy answers: app.resolve_notice(id);
    let _ = id;
}

Note::from_notice draws a notice as a note inside a page: its severity, headline, reason, hint, details, time and its actions’ labels.

Actions with arguments

An action names a command, and may carry the arguments it runs with: the notice says which restore to undo, which photos to show, which failure a bug report is about. The arguments are stored with the notice, saved with it in notices.json, and given to the command when the action runs, wherever it is shown: a toast’s button, a notice site’s or the Notices panel’s note. An action without arguments runs its command with null.

use egui_pop::api::AppHandle;
use egui_pop::model::notice::Notice;
use serde_json::json;

fn restored(app: &AppHandle, restore: u64, photos: &[u64]) {
    app.report(
        Notice::success(format!("{} photos restored", photos.len()))
            .action_with("restore.undo", "Undo", json!({ "restore": restore }))
            .action_with("library.show", "Show them", json!({ "photos": photos })),
    );
}

Routing: which views show a notice

egui-pop gives the mechanism, the application the policy. Each notice raised is given to the routing policy, which answers a Route: the surfaces that show it (egui_pop::api::notices, from egui_pop_model::notice::route):

  • Inline(place): a note in the page or panel that drew the notice site of that place;
  • Toast: a toast, transient for information, success and warnings, until closed for errors; it has a Copy button, and closing it marks the notice seen;
  • StatusBadge: counted by the status bar’s badge until seen (or, for a condition, resolved);
  • History: the history of notices;
  • Decisions: a question for the user, handed to the application’s Decisions surface.

egui-pop’s listener pop.notices.route hears pop.notice.raised after the store and shows the notice on its route; AppHandle::notice_route reads the route a notice was given.

The default policy

default_route (installed until the application gives its own): background work never pops up, and a user’s own failure shows where it happened.

NoticeSurfaces
an ask (any origin)Decisions, history
a condition (any origin)inline at its place when a site shows it, history; the badge when a warning or an error
a user’s error or warninginline at its place when a site shows it, else a toast; history
a user’s information or successa toast, history
a background, node or system error or warningthe badge, history; never a toast
a background, node or system information or successhistory

A site “shows” a place while it is drawn: in its window’s last pass or the current one.

An application’s own policy

A policy is a NoticeRouting: route picks the surfaces, ask hands a question routed to Decisions to the application’s panel (egui-pop has none; by default it does nothing). A closure Fn(&Notice, &RouteCx) -> Route is a policy too. It runs on the thread that raised the notice: it must be quick and must not raise notices.

use egui_pop::api::AppHandle;
use egui_pop::api::notices::{NoticeRouting, Route, RouteCx, default_route};
use egui_pop::model::notice::{Kind, Notice};

struct Policy;

impl NoticeRouting for Policy {
    fn route(&self, n: &Notice, cx: &RouteCx) -> Route {
        // egui-pop's table, but a node's notices only in the history.
        match n.node {
            Some(_) => Route::none().history(),
            None => default_route(n, cx),
        }
    }

    fn ask(&self, n: &Notice) {
        // Hand the question to the application's Decisions panel.
        let _ = (n.kind == Kind::Ask, &n.headline);
    }
}

fn install(app: &AppHandle) {
    app.route_notices(Policy);
}

Notice sites

A page or a panel calls notice_site(ui, app, place) where its notes belong. While it is drawn, the policy may route the notices of that place there; the site draws each as a Note (selectable, with Copy and Details), the newest three, marks them seen, runs their actions that name a command, and puts one away with its close button (pop.notice.dismissed). Admin forms draw the site of each section’s page under its title, at settings/<scope>/<section>.

The badge

AppHandle::notice_badge says what the status bar’s badge counts: the notices routed to StatusBadge not seen yet (nor resolved), with the errors and warnings among them, and the list of them. The bell shows it (below).

The bell and the Notices panel

NoticesPlugin (egui_pop::api::notices, opt-in: add it to the builder) brings the history of notices into view.

use egui_pop::api::App;
use egui_pop::api::notices::NoticesPlugin;

let app = App::builder()
    .plugin(NoticesPlugin::default())
    .build(&egui_pop::egui::Context::default())
    .unwrap();
let _ = app;

The bell

An item of the status bar (the app.status-bar zone, block egui_pop.notices.bell): the notification symbol, and on its corner the count of the errors and warnings not seen yet (the badge’s), red when one is an error, amber for warnings only, hidden at zero. Its tooltip says them in words: “1 error, 1 warning not yet seen”, or “No new errors or warnings”. A click opens the Notices panel, or gives it the keyboard when it is open.

For screen readers it is a button named “Notices” with its count (“Notices, 2”); when the count rises, its tooltip’s words are announced politely. notices::bell(ui, app) draws it anywhere else (NoticesPlugin::without_bell leaves the status bar alone).

The Notices panel

A workbench panel (PANEL_NOTICES, egui_pop.notices), closed until the bell or the application opens it, docked at the bottom by default, dockable and floatable like the others. It lists every notice the store keeps: the unresolved ones first, newest first, then the conditions that ended. Each row says the severity (its symbol, named), the time (UTC, to the minute), the origin (the node’s name for a notice from another node) and the headline, in bold while not seen. A resolved condition is dimmed, with the “Resolved” symbol. A click on a row opens its Note under it (Note::from_notice): the reason, the hint, the details folded under “Details”, Copy, and the actions (those naming a command run it); a second click closes it. Its close button dismisses the notice (pop.notice.dismissed).

  • Filters: severity, origin (you, background, other nodes, system), node (when notices come from nodes) and a search over the headline, reason, hint, details and node (case ignored). notices::Filter and notices::listed give the same list in code.
  • Mark all seen marks every notice kept seen, listed or not.
  • Copy all copies the notices listed, as each note’s Copy writes it (headline, reason, hint, then under --- the details and the time), separated by a ===== line: ready for a bug report (notices::copy_all_text).
  • Clear seen dismisses the notices seen, but a condition still going on.

Drawing the panel marks the notices it lists seen (pop.notice.seen): opening it clears the bell’s count. notices::panel(ui, app) draws its content anywhere; notices::panel_preview draws it without marking anything seen.

Persistence

With a persistence directory (AppBuilder::persist), the notices kept are saved in the notices document (notices.json, written about a second after a change and by App::save, with the backup every document has) and read back at the next start: each notice, whether it was seen or resolved, the route it was given (so the bell counts the same), and the next id, so new notices never take a saved one’s.

  • Bounds: the store keeps at most 500 notices and none older than 30 days, whichever keeps fewer; the oldest leave first. An error not seen yet stays past both until it is seen. AppHandle::set_notice_limits changes the two bounds.
  • Versions: the document has a version (1) and a kind (notices); a file without a version reads as version 1 (so does one written before actions had arguments: an action without args runs with null), a missing file is a first start, and a file that cannot be read (nor its backup) is logged and replaced at the next save: the application starts with no notices.
  • Notices raised before the file is read (a plugin’s, at start) come after the saved ones.

Commands that fail: CommandError

A command’s failure, structured (egui_pop_model::commands::CommandError, also in egui_pop::api::notices): a headline, a reason, a hint, details (the technical chain) and user, whether the headline is in the user’s words.

  • CommandError::new(headline) is a failure told in the user’s words (user on), with .reason, .hint and .details.
  • A String, a &str, an std::io::Error, a serde_json::Error or a boxed error (anyhow::Error converts to one with .into()) converts to one whose headline is its text and whose user mark is off; CommandError::from_error keeps an error’s sources as its details.
  • Its Display is the headline, then : and the reason: one made from a text displays that text unchanged, and String::from(err) gives it back, so command results that are still Result<Json, String> keep working.

A handler tells its failure in full with Call::fail, which keeps the structured error for the run and returns its text:

use egui_pop::api::Call;
use egui_pop::api::notices::CommandError;
use serde_json::Value as Json;

fn add_node(call: &Call<'_>) -> Result<Json, String> {
    Err(call.fail(
        CommandError::new("cloudy was not added")
            .reason("The network found no route to it.")
            .hint("Check that cloudy is on and on the same network.")
            .details("connect 192.168.1.12:7443: No route to host (os error 113)"),
    ))
}

The failure, for the code that ran the command

A command’s result is still Result<Json, String>: App::run and the host’s dispatch give the failure’s text only. AppHandle::take_failure(&command) gives the rest, once the result is in: the CommandError of the command’s last failed run, as its handler told it with Call::fail (headline, reason, hint, details, user on), or one made from the text of any other failure (user off). It is taken: a second call returns None, and a run of the command that succeeds clears it. An application that reports failures itself (its own words, its own actions) reads it instead of parsing the text:

use egui_pop::api::App;
use egui_pop::model::commands::Origin;
use egui_pop::model::ids::CommandId;

fn add_node(app: &mut App, add: &CommandId) {
    if let Some(Err(_)) = app.run(add, serde_json::json!({}), Origin::User).now()
        && let Some(err) = app.handle().take_failure(add)
    {
        let notice = err
            .to_notice("cloudy was not added")
            .action_with("bug.report", "Report a bug", serde_json::json!({ "command": add }));
        app.handle().report(notice);
    }
}

A command run with AppHandle::run (before the next frame) or whose reply comes later (Reply::Later) has its failure there once its result arrived.

Reported where it was asked

AppHandle::run_reported(command, args, place) runs a command for the user as run does; if it fails, the failure is reported, as a notice from the user at place, and the policy shows it. A failure told in full gives its headline, reason, hint and details; any other gives “Command did not work” with its text under Details. Admin forms run their actions and their rows’ fields this way, at their page’s place, and a wizard’s Finish at settings/wizard/<id>: an admin action that fails is never silent.