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>
impl<E> Cx<E>
Sourcepub fn notify(
&mut self,
plugin: impl Into<String>,
op: impl Into<String>,
input: impl Into<String>,
)
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.
Sourcepub fn plugin(
&mut self,
plugin: impl Into<String>,
op: impl Into<String>,
input: impl Into<String>,
then: impl FnOnce(PluginResponse) -> E + Send + 'static,
)
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.
Sourcepub 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,
)
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.
Sourcepub fn unsubscribe(&mut self, key: impl Into<String>)
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.
Sourcepub fn upload(
&mut self,
url: impl Into<String>,
source: impl Into<String>,
) -> TransferBuilder<'_, E>
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].
Sourcepub fn download(
&mut self,
url: impl Into<String>,
dest: impl Into<String>,
) -> TransferBuilder<'_, E>
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].
Sourcepub fn save(&mut self, data: impl Into<String>)
pub fn save(&mut self, data: impl Into<String>)
Persist data (handed back to MobilerApp::restore on next startup).
Sourcepub fn copy(&mut self, text: impl Into<String>)
pub fn copy(&mut self, text: impl Into<String>)
Copy text to the system clipboard (built-in clipboard capability).
Open the system share sheet with text (built-in share capability).
Sourcepub fn open_url(&mut self, url: impl Into<String>)
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.
Sourcepub fn toast(&mut self, text: impl Into<String>)
pub fn toast(&mut self, text: impl Into<String>)
Show a transient toast / snackbar with text (built-in toast capability).
Sourcepub fn haptic(&mut self, style: impl Into<String>)
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.
Sourcepub fn request(
&mut self,
method: impl Into<String>,
url: impl Into<String>,
) -> RequestBuilder<'_, E>
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,
});Sourcepub fn get(
&mut self,
url: impl Into<String>,
then: impl FnOnce(HttpOutcome) -> E + Send + 'static,
)
pub fn get( &mut self, url: impl Into<String>, then: impl FnOnce(HttpOutcome) -> E + Send + 'static, )
GET url, delivering the outcome to then.
Sourcepub fn post(
&mut self,
url: impl Into<String>,
body: impl Into<String>,
then: impl FnOnce(HttpOutcome) -> E + Send + 'static,
)
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.
Sourcepub fn put(
&mut self,
url: impl Into<String>,
body: impl Into<String>,
then: impl FnOnce(HttpOutcome) -> E + Send + 'static,
)
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.
Sourcepub fn patch(
&mut self,
url: impl Into<String>,
body: impl Into<String>,
then: impl FnOnce(HttpOutcome) -> E + Send + 'static,
)
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.
Sourcepub fn delete(
&mut self,
url: impl Into<String>,
then: impl FnOnce(HttpOutcome) -> E + Send + 'static,
)
pub fn delete( &mut self, url: impl Into<String>, then: impl FnOnce(HttpOutcome) -> E + Send + 'static, )
DELETE url, delivering the outcome to then.
Sourcepub fn device_model(
&mut self,
then: impl FnOnce(PluginResponse) -> E + Send + 'static,
)
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.
Sourcepub fn device_locale(
&mut self,
then: impl FnOnce(PluginResponse) -> E + Send + 'static,
)
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.
Sourcepub fn pick_photo(
&mut self,
then: impl FnOnce(PluginResponse) -> E + Send + 'static,
)
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.
Sourcepub fn capture_photo(
&mut self,
then: impl FnOnce(PluginResponse) -> E + Send + 'static,
)
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.
Sourcepub fn confirm(
&mut self,
title: impl Into<String>,
message: impl Into<String>,
then: impl FnOnce(PluginResponse) -> E + Send + 'static,
)
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).
Sourcepub fn pick_date(
&mut self,
then: impl FnOnce(PluginResponse) -> E + Send + 'static,
)
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).
Sourcepub fn pick_time(
&mut self,
then: impl FnOnce(PluginResponse) -> E + Send + 'static,
)
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).
Sourcepub fn now(&mut self, then: impl FnOnce(PluginResponse) -> E + Send + 'static)
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.