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