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 upload( &mut self, url: impl Into<String>, source: impl Into<String>, ) -> TransferBuilder<'_, E>

Upload the file at source (a path / content:// / file:// / blob: handle) as the raw request body. Finish with [TransferBuilder::start].

Source

pub fn download( &mut self, url: impl Into<String>, dest: impl Into<String>, ) -> TransferBuilder<'_, E>

Download url to dest (a sandbox path on iOS/Android; a filename hint on web, which returns a blob: handle). Finish with [TransferBuilder::start].

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 request( &mut self, method: impl Into<String>, url: impl Into<String>, ) -> RequestBuilder<'_, E>

Start an HTTP request with full control — headers, and later timeouts and query params — finished with [RequestBuilder::send].

cx.request("PUT", url)
    .bearer(&token)
    .body(json)
    .send(|outcome| match outcome.status() {
        Some(409) => Event::NeedsRebase,
        Some(s) if outcome.is_success() => Event::Saved,
        Some(s) => Event::ServerError(s),
        None => Event::Offline,
    });
Source

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

GET url, delivering the outcome to then.

Source

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

POST url with body, delivering the outcome to then.

Source

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

PUT url with body, delivering the outcome to then.

Source

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

PATCH url with body, delivering the outcome to then.

Source

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

DELETE url, delivering the outcome 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 confirm_with( &mut self, dialog: Confirm, then: impl FnOnce(PluginResponse) -> E + Send + 'static, )

As confirm, with the app’s own button labels and an optional destructive style — e.g. Confirm::new("Cancel booking?", msg).confirm_label("Cancel booking") .cancel_label("Keep it").destructive(). Same response: ok is true only if confirmed.

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).

Source

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

As pick_date, with the app’s own title and button labels.

Source

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

As pick_time, with the app’s own title and button labels.

Source

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

Read the current local date-time (built-in datetime capability). The core is a pure state machine and can’t read the clock itself, so stamping an event with “now” — a ledger entry, a log line — goes through the shell. response.output is the local date-time as YYYY-MM-DD HH:MM:SS (sortable lexicographically; the date is the first 10 chars). No UI — resolves immediately. Pair with pick_date when the user should choose a different date instead.

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.