1pub mod command;
4
5use crux_core::capability::{CapabilityContext, Operation};
6use crux_core::macros::Capability;
7use serde::{Deserialize, Serialize};
8
9#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
10pub struct PlatformRequest;
11
12#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
14pub struct PlatformResponse(pub String);
15
16impl Operation for PlatformRequest {
17 type Output = PlatformResponse;
18}
19
20#[derive(Capability)]
21pub struct Platform<Ev> {
22 context: CapabilityContext<PlatformRequest, Ev>,
23}
24
25impl<Ev> Platform<Ev>
26where
27 Ev: 'static,
28{
29 pub fn new(context: CapabilityContext<PlatformRequest, Ev>) -> Self {
30 Self { context }
31 }
32
33 pub fn get<F>(&self, callback: F)
34 where
35 F: FnOnce(PlatformResponse) -> Ev + Send + Sync + 'static,
36 {
37 self.context.spawn({
38 let context = self.context.clone();
39 async move {
40 let response = context.request_from_shell(PlatformRequest).await;
41
42 context.update_app(callback(response));
43 }
44 });
45 }
46}