1#![doc = include_str!("../examples/clock_card.rs")]
26#![no_std]
34
35extern crate alloc;
36#[cfg(any(feature = "std", not(target_arch = "wasm32")))]
37extern crate std;
38
39#[cfg(target_endian = "big")]
40compile_error!("the shared surface buffer is little-endian");
41
42mod bindings;
43mod colour;
44mod error;
45mod geometry;
46mod host;
47mod input;
48mod local;
49#[cfg(all(target_arch = "wasm32", not(feature = "std")))]
50mod runtime;
51mod ui_runtime;
52
53pub mod api;
54pub mod daemon;
55pub mod draw;
56pub mod embed;
57pub mod links;
58pub mod surface;
59#[cfg(not(target_arch = "wasm32"))]
60pub mod testing;
61
62pub use api::{
63 Json, Target, account, calls, capabilities, claims, config, events, health, live, secrets, url,
64 values, view,
65};
66pub use colour::{Attrs, Colour, Rgba, Style, ThemeSlot, recede};
67pub use draw::{Area, Image, Shapes, font};
68pub use error::{Error, Result};
69pub use geometry::{Geometry, Rect};
70pub use input::{Button, Key, KeyCode, KeyPhase, Modifiers, Pointer, PointerKind};
71pub use surface::{
72 AgentPointer, AnySurface, AnySurfaceMut, Cell, Cells, Instances, Pixels, Surface,
73};
74pub use ui_runtime::{Context, Event, Frame, Power, UiPlugin};
75
76pub use standard_plugin_macros::ui;
80
81pub use standard_plugin_macros::daemon;
84
85pub use libm;
88
89pub mod prelude {
91 pub use crate::daemon::DaemonPlugin;
92 pub use crate::{
93 AnySurface, Area, Attrs, Button, Cells, Colour, Context, Error, Event, Frame, Geometry,
94 Instances, Json, Key, KeyCode, Modifiers, Pixels, Pointer, PointerKind, Rect, Rgba, Shapes,
95 Style, Surface, Target, ThemeSlot, UiPlugin,
96 };
97 pub use alloc::borrow::ToOwned;
98 pub use alloc::boxed::Box;
99 pub use alloc::format;
100 pub use alloc::string::{String, ToString};
101 pub use alloc::vec;
102 pub use alloc::vec::Vec;
103}
104
105pub mod sources {
110 pub const WIT: &str = include_str!("../wit/plugin.wit");
113
114 pub mod examples {
116 pub const CLOCK_CARD: &str = include_str!("../examples/clock_card.rs");
118 pub const HEARTBEAT_DAEMON: &str = include_str!("../examples/heartbeat_daemon.rs");
120 pub const TOGETHER_UI: &str = include_str!("../examples/together_ui.rs");
122 pub const TOGETHER_COMPANION: &str = include_str!("../examples/together_companion.rs");
124 }
125
126 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
129 pub struct Guide {
130 pub name: &'static str,
131 pub text: &'static str,
132 }
133
134 impl Guide {
135 #[must_use]
137 pub fn title(&self) -> &'static str {
138 self.text
139 .lines()
140 .next()
141 .and_then(|line| line.strip_prefix("# "))
142 .unwrap_or(self.name)
143 }
144 }
145
146 pub const GUIDES: &[Guide] = &[
149 Guide {
150 name: "README",
151 text: include_str!("../docs/README.md"),
152 },
153 Guide {
154 name: "getting-started",
155 text: include_str!("../docs/getting-started.md"),
156 },
157 Guide {
158 name: "agent-guide",
159 text: include_str!("../docs/agent-guide.md"),
160 },
161 Guide {
162 name: "manifest",
163 text: include_str!("../docs/manifest.md"),
164 },
165 Guide {
166 name: "grants",
167 text: include_str!("../docs/grants.md"),
168 },
169 Guide {
170 name: "rendering",
171 text: include_str!("../docs/rendering.md"),
172 },
173 Guide {
174 name: "input",
175 text: include_str!("../docs/input.md"),
176 },
177 Guide {
178 name: "handlers",
179 text: include_str!("../docs/handlers.md"),
180 },
181 Guide {
182 name: "previews",
183 text: include_str!("../docs/previews.md"),
184 },
185 Guide {
186 name: "working-together",
187 text: include_str!("../docs/working-together.md"),
188 },
189 Guide {
190 name: "daemon-plugins",
191 text: include_str!("../docs/daemon-plugins.md"),
192 },
193 Guide {
194 name: "testing",
195 text: include_str!("../docs/testing.md"),
196 },
197 Guide {
198 name: "publishing",
199 text: include_str!("../docs/publishing.md"),
200 },
201 Guide {
202 name: "abi",
203 text: include_str!("../docs/abi.md"),
204 },
205 Guide {
206 name: "other-languages",
207 text: include_str!("../docs/other-languages.md"),
208 },
209 ];
210}
211
212pub mod guide {
217 #[doc = include_str!("../docs/README.md")]
218 pub mod index {}
219 #[doc = include_str!("../docs/getting-started.md")]
220 pub mod getting_started {}
221 #[doc = include_str!("../docs/agent-guide.md")]
222 pub mod agent_guide {}
223 #[doc = include_str!("../docs/manifest.md")]
224 pub mod manifest {}
225 #[doc = include_str!("../docs/grants.md")]
226 pub mod grants {}
227 #[doc = include_str!("../docs/rendering.md")]
228 pub mod rendering {}
229 #[doc = include_str!("../docs/input.md")]
230 pub mod input {}
231 #[doc = include_str!("../docs/handlers.md")]
232 pub mod handlers {}
233 #[doc = include_str!("../docs/previews.md")]
234 pub mod previews {}
235 #[doc = include_str!("../docs/working-together.md")]
236 pub mod working_together {}
237 #[doc = include_str!("../docs/daemon-plugins.md")]
238 pub mod daemon_plugins {}
239 #[doc = include_str!("../docs/testing.md")]
240 pub mod testing {}
241 #[doc = include_str!("../docs/publishing.md")]
242 pub mod publishing {}
243 #[doc = include_str!("../docs/abi.md")]
244 pub mod abi {}
245 #[doc = include_str!("../docs/other-languages.md")]
246 pub mod other_languages {}
247}
248
249#[doc(hidden)]
251pub mod __private {
252 pub use crate::bindings::{daemon as daemon_bindings, ui as ui_bindings};
253 pub use crate::daemon::runtime::DaemonRuntime;
254 pub use crate::ui_runtime::UiRuntime;
255 pub use alloc::string::String;
256}
257
258#[doc(hidden)]
260#[macro_export]
261macro_rules! __export_ui {
262 ($plugin:ty) => {
263 const _: () = {
264 static RUNTIME: $crate::__private::UiRuntime<$plugin> =
265 $crate::__private::UiRuntime::new();
266
267 struct Export;
268
269 impl $crate::__private::ui_bindings::Guest for Export {
270 fn activate(config: $crate::__private::String) {
271 RUNTIME.activate(config);
272 }
273
274 fn frame(
275 now_ms: u64,
276 interval_ms: u32,
277 power: $crate::__private::ui_bindings::Power,
278 ) -> Option<u64> {
279 RUNTIME.frame(now_ms, interval_ms, power.into())
280 }
281
282 fn event(event: $crate::__private::ui_bindings::Event) {
283 RUNTIME.event(event.into());
284 }
285
286 fn deactivate() {
287 RUNTIME.deactivate();
288 }
289 }
290
291 $crate::__export_ui_plugin_impl!(Export with_types_in $crate::__private::ui_bindings);
292 };
293 };
294}
295
296#[doc(hidden)]
299#[macro_export]
300macro_rules! __export_daemon {
301 ($plugin:ty) => {
302 const _: () = {
303 static RUNTIME: $crate::__private::DaemonRuntime<$plugin> =
304 $crate::__private::DaemonRuntime::new();
305
306 struct Export;
307
308 impl $crate::__private::daemon_bindings::Guest for Export {
309 fn activate(config: $crate::__private::String) {
310 RUNTIME.activate(config);
311 }
312
313 fn event(event: $crate::__private::daemon_bindings::Event) {
314 RUNTIME.event(event.into());
315 }
316
317 fn drive(now_ms: u64) -> Option<u64> {
318 RUNTIME.drive(now_ms)
319 }
320
321 fn deactivate() {
322 RUNTIME.deactivate();
323 }
324 }
325
326 impl $crate::__private::daemon_bindings::exports::standard::plugin::daemon_events::Guest
327 for Export
328 {
329 fn handle_event(
330 event: $crate::__private::daemon_bindings::exports::standard::plugin::daemon_events::DaemonEvent,
331 ) {
332 RUNTIME.event(event.into());
333 }
334 }
335
336 impl $crate::__private::daemon_bindings::exports::standard::plugin::companion::Guest
337 for Export
338 {
339 fn handle_call(
340 method: $crate::__private::String,
341 payload: $crate::__private::String,
342 from: $crate::__private::daemon_bindings::exports::standard::plugin::companion::Caller,
343 ) -> Result<
344 $crate::__private::String,
345 $crate::__private::ui_bindings::standard::plugin::types::CallError,
346 > {
347 RUNTIME
348 .handle_call(&method, payload, from.into())
349 .map_err(Into::into)
350 }
351 }
352
353 #[cfg(target_family = "wasm")]
357 $crate::__export_daemon_plugin_impl!(
358 Export with_types_in $crate::__private::daemon_bindings
359 );
360
361 #[cfg(not(target_family = "wasm"))]
364 #[allow(dead_code)]
365 fn native_entry_points() {
366 use $crate::__private::daemon_bindings::Guest as _;
367 use $crate::__private::daemon_bindings::exports::standard::plugin::companion::Guest as _;
368 use $crate::__private::daemon_bindings::exports::standard::plugin::daemon_events::Guest as _;
369 let _ = (
370 Export::activate,
371 Export::event,
372 Export::handle_event,
373 Export::drive,
374 Export::deactivate,
375 Export::handle_call,
376 );
377 }
378 };
379 };
380}