eave_api/lib.rs
1//! The plugin API for eave.
2//!
3//! A plugin is a crate that implements [`Widget`] for one or more types and exports a
4//! `register` function:
5//!
6//! ```ignore
7//! pub fn register(registry: &mut eave_api::Registry) {
8//! registry.widget::<Clock>("clock");
9//! }
10//! ```
11//!
12//! Widgets describe their UI with the closed vocabulary in [`ui`]. They never pick colors, fonts or
13//! spacing, and they never touch the bar's layout or surfaces: the host owns all of that.
14
15mod effect;
16mod registry;
17pub mod ui;
18mod widget;
19
20#[doc(hidden)]
21pub mod erased;
22
23pub use effect::{Effect, Nudge, NudgeRequest};
24pub use iced_futures::Subscription;
25pub use iced_runtime::Task;
26pub use registry::Registry;
27pub use widget::Widget;
28
29/// Timers, for the few things that have no event source (clocks, `/proc` counters), and one-shot
30/// delays (`Task::future(sleep(..))`, e.g. to show something for a moment).
31pub mod time {
32 pub use iced_futures::backend::native::tokio::time::every;
33 pub use iced_futures::core::time::{Duration, Instant};
34
35 /// Waits `duration`. Nothing starts until the task runs it, so it's safe to build in `update`.
36 pub async fn sleep(duration: Duration) {
37 tokio::time::sleep(duration).await;
38 }
39}
40
41/// The [`Widget::Config`] of a widget without options. Rejects any option it is given.
42#[derive(Debug, Default, Clone, Copy, serde::Deserialize)]
43#[serde(deny_unknown_fields)]
44pub struct NoConfig {}
45
46/// The version of this API. `eave-build` checks plugin manifests against it.
47pub const API_VERSION: &str = env!("CARGO_PKG_VERSION");