Skip to main content

Cx

Struct Cx 

Source
pub struct Cx<E> { /* private fields */ }
Expand description

Effects an app requests during update, generic over the app event type so continuations stay fully typed.

Implementations§

Source§

impl<E> Cx<E>

Source

pub fn notify( &mut self, plugin: impl Into<String>, op: impl Into<String>, input: impl Into<String>, )

Fire-and-forget call to a native plugin.

Source

pub fn plugin( &mut self, plugin: impl Into<String>, op: impl Into<String>, input: impl Into<String>, then: impl FnOnce(PluginResponse) -> E + Send + 'static, )

Request/response call: when the plugin replies, then(response) produces the typed event delivered back to your update.

Source

pub fn subscribe( &mut self, key: impl Into<String>, plugin: impl Into<String>, op: impl Into<String>, input: impl Into<String>, on_event: impl Fn(PluginResponse) -> E + Send + 'static, )

Subscribe to a streaming plugin: the shell starts a native source and delivers every event it produces to on_event (which fires repeatedly, once per event), each producing a typed event into your update. key is a caller-chosen id for this subscription — pass the same key to unsubscribe to stop it. Call subscribe once per key (e.g. in init or on a connect event); calling it again with a live key starts a second source.

Source

pub fn unsubscribe(&mut self, key: impl Into<String>)

Stop the streaming subscription started under key by subscribe. The shell tears down the native source registered under key, so it stops producing events. No-op if key isn’t subscribed.

Source

pub fn save(&mut self, data: impl Into<String>)

Persist data (handed back to MobilerApp::restore on next startup).

Source

pub fn copy(&mut self, text: impl Into<String>)

Copy text to the system clipboard (built-in clipboard capability).

Source

pub fn share(&mut self, text: impl Into<String>)

Open the system share sheet with text (built-in share capability).

Source

pub fn open_url(&mut self, url: impl Into<String>)

Open url in the platform browser / default handler (built-in browser capability). Fire-and-forget: the app leaves the foreground.

Source

pub fn toast(&mut self, text: impl Into<String>)

Show a transient toast / snackbar with text (built-in toast capability).

Source

pub fn haptic(&mut self, style: impl Into<String>)

Fire a haptic tap (built-in haptics capability). style is "light", "medium", or "heavy"; unknown styles fall back to medium.

Source

pub fn http( &mut self, method: impl Into<String>, url: impl Into<String>, body: Option<String>, then: impl FnOnce(PluginResponse) -> E + Send + 'static, )

Perform an HTTP request via the shell’s built-in http capability. When it completes, then(response) produces the typed event delivered back to updateresponse.output is the body, response.ok is success (2xx). Rides the request/response plugin mechanism, so it resolves asynchronously.

Source

pub fn get( &mut self, url: impl Into<String>, then: impl FnOnce(PluginResponse) -> E + Send + 'static, )

GET url, delivering the response to then.

Source

pub fn post( &mut self, url: impl Into<String>, body: impl Into<String>, then: impl FnOnce(PluginResponse) -> E + Send + 'static, )

POST url with a JSON body, delivering the response to then.

Source

pub fn patch( &mut self, url: impl Into<String>, body: impl Into<String>, then: impl FnOnce(PluginResponse) -> E + Send + 'static, )

PATCH url with a JSON body, delivering the response to then.

Source

pub fn delete( &mut self, url: impl Into<String>, then: impl FnOnce(PluginResponse) -> E + Send + 'static, )

DELETE url, delivering the response to then.

Source

pub fn device_model( &mut self, then: impl FnOnce(PluginResponse) -> E + Send + 'static, )

Query the device model/name via the built-in device capability; the result (response.output, e.g. “Google Pixel 7” / “Apple iPhone (iOS 18.0)”) is delivered to then.

Source

pub fn device_locale( &mut self, then: impl FnOnce(PluginResponse) -> E + Send + 'static, )

Query the device’s preferred locale as a BCP-47 language tag (e.g. "de-CH", "en-US") via the built-in device capability; then receives it in response.output. Pair with Locale::from_tag to choose the app’s language / formatting locale at startup. Works on iOS, Android, and web.

Source

pub fn pick_photo( &mut self, then: impl FnOnce(PluginResponse) -> E + Send + 'static, )

Let the user pick an image (built-in photo capability — the system photo picker, no permission required). then receives the result: on success response.ok is true and response.output is a local image URI you can hand straight to the image(...) widget; on cancel, ok is false.

Source

pub fn capture_photo( &mut self, then: impl FnOnce(PluginResponse) -> E + Send + 'static, )

Capture a photo with the device camera (built-in camera capability — launches the system camera). then receives the result: on success response.ok is true and response.output is a local image URI you can hand straight to the image(...) widget; on cancel, ok is false. iOS requires an NSCameraUsageDescription (the template ships one, opt-in); Android captures via the system camera app, so no extra runtime permission is needed.

Source

pub fn confirm( &mut self, title: impl Into<String>, message: impl Into<String>, then: impl FnOnce(PluginResponse) -> E + Send + 'static, )

Ask the user to confirm via a native dialog (built-in dialog capability). then receives the choice: response.ok is true if confirmed, false if cancelled/dismissed. Resolves asynchronously (the user replies whenever).

Source

pub fn pick_date( &mut self, then: impl FnOnce(PluginResponse) -> E + Send + 'static, )

Let the user pick a date via the native date picker (built-in datetime capability). On success response.ok is true and response.output is the chosen date as an ISO YYYY-MM-DD string; on cancel/dismiss, ok is false. Resolves asynchronously (the user replies whenever).

Source

pub fn pick_time( &mut self, then: impl FnOnce(PluginResponse) -> E + Send + 'static, )

Let the user pick a time via the native time picker (built-in datetime capability). On success response.ok is true and response.output is the chosen time as a 24-hour HH:MM string; on cancel/dismiss, ok is false. Resolves asynchronously (the user replies whenever).

Trait Implementations§

Source§

impl<E> Default for Cx<E>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<E> !RefUnwindSafe for Cx<E>

§

impl<E> !Sync for Cx<E>

§

impl<E> !UnwindSafe for Cx<E>

§

impl<E> Freeze for Cx<E>

§

impl<E> Send for Cx<E>

§

impl<E> Unpin for Cx<E>

§

impl<E> UnsafeUnpin for Cx<E>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.