Skip to main content

ScriptCommand

Enum ScriptCommand 

Source
pub enum ScriptCommand {
Show 59 variants Print(String), AddClicks(i32), SetString { key: String, value: String, }, SetText { target_id: String, text: String, }, SetSrc { target_id: String, path: String, }, SetTimer { name: String, millis: u64, repeat: bool, }, CancelTimer { name: String, }, Fetch { url: String, tag: String, }, Http { method: String, url: String, headers: Vec<(String, String)>, body: Option<String>, timeout_ms: Option<u64>, credentials: Credentials, tag: String, }, SetResponseStatus { status: u16, }, SetResponseHeader { name: String, value: String, }, Redirect { location: String, }, SetSignal { name: String, value: String, }, SetProperty { key: PropertyKey, value: PropertyValue, }, SetArray { name: String, items: Vec<HashMap<String, String>>, }, Notify { title: String, body: String, }, NotifyEx { id: String, title: String, body: String, options: String, actions: String, }, ClipboardWrite { text: String, }, ClipboardRead { tag: String, }, OpenUrl { url: String, }, OpenPath { path: String, }, RevealPath { path: String, }, KeepAwake { name: String, reason: String, }, AllowSleep { name: String, }, CopyImageToClipboard { path: String, }, SaveClipboardImage { path: String, }, RegisterTrayIcon { id: String, icon_path: String, tooltip: Option<String>, menu: String, template: bool, }, UnregisterTrayIcon { id: String, }, SetClasses { target_id: String, classes: String, }, SetColorScheme { name: String, }, OpenFileDialog { kind: FileDialogKind, tag: String, filters: Vec<(String, Vec<String>)>, default_name: Option<String>, }, RegisterHotkey { name: String, accelerator: String, }, UnregisterHotkey { name: String, }, SetAttr { node: u64, name: String, value: String, }, RemoveAttr { node: u64, name: String, }, SetNodeText { node: u64, text: String, }, ClassAdd { node: u64, class: String, }, ClassRemove { node: u64, class: String, }, ClassToggle { node: u64, class: String, }, SetStyleProp { node: u64, name: String, value: String, }, RemoveStyleProp { node: u64, name: String, }, Spawn { tag: String, reserved: u64, }, Insert { parent: u64, node: u64, before: u64, }, ReplaceWith { old: u64, new: u64, }, RemoveNode { node: u64, }, CloneNode { source: u64, reserved: u64, }, SetInnerMarkup { node: u64, markup: String, }, SpawnFragment { key: String, args: Vec<(String, String)>, children: Vec<(String, u64)>, reserved: u64, }, BindEvent { node: u64, event_type: String, capture: bool, token: u64, }, UnbindEvent { token: u64, }, WindowSetTitle { title: String, }, WindowSetSize { width: f32, height: f32, }, AddRecentFile { path: String, label: String, }, ListRecentFiles { tag: String, }, ClearRecentFiles, SetAutostart { on: bool, }, QueryAutostart { tag: String, }, RequestFrame, SetLocale { tag: String, },
}
Expand description

One side-effect a script wants to apply to the app this tick.

V1 is intentionally small: just enough to demo end-to-end. Future variants will cover SetComponent, SpawnEntity, DespawnEntity, RegisterTimer, etc., keyed by an entity id type that’s stable across the script ABI boundary.

Variants are append-only; see SCRIPT_WIRE_VERSION.

Variants§

§

Print(String)

Append a line to the app’s diagnostic output.

§

AddClicks(i32)

Add n to the app’s click counter (consumed in app-defined ways - the host doesn’t know about Clicks, it just emits this token).

§

SetString

Free-form key/value the app can interpret. Strings only for now.

Fields

§key: String

Key (e.g. "title", "label").

§value: String

Value.

§

SetText

Replace the TextContent of the entity whose LumenId matches target_id (set in markup via id="...").

Fields

§target_id: String

Target entity id.

§text: String

New text content.

§

SetSrc

Replace the asset path on an <image> entity. The runtime strips the old LoadedImage / LoadedSvg / ImageLoadFailed component, installs a fresh ImageSource, and the asset pipeline re-decodes on the next tick. Used by scripts to swap icons in response to runtime state (e.g. weather code -> icons/sun.png).

Fields

§target_id: String

Target entity id.

§path: String

New asset path. Resolved relative to the app directory at load time on the parser side; runtime mutations pass paths through verbatim, so authors should compose relative paths against their own app root (e.g. "icons/sun.png").

§

SetTimer

Schedule a named timer. The runtime calls the script’s on_timer(name) handler when it fires.

Fields

§name: String

Timer name, also passed as the on_timer argument.

§millis: u64

Delay until first fire, in milliseconds.

§repeat: bool

If true, reschedule with the same interval after each fire.

§

CancelTimer

Cancel a pending or repeating timer by name. No-op if absent.

Fields

§name: String

Timer name to cancel.

§

Fetch

Issue an HTTP GET. The runtime spawns the request off-thread and fires on_fetch(tag, body) when the response arrives.

This is the simple sugar; Self::Http is the general form and shares the same off-thread transport and completion channel.

Fields

§url: String

URL to GET.

§tag: String

Identifier the script gets back in on_fetch(tag, body).

§

Http

Issue a general HTTP request. The runtime performs it off-thread (one worker per request) and, once the reply is marshalled back onto the ECS/UI thread, fires on_http(tag, response) where response is a map #{ ok, status, headers, body, error }.

Request/reply shape is modeled on Qt’s QNetworkRequest/QNetworkReply (method + url + headers + body in; status + headers + body + error out); the worker->UI-thread marshalling before any signal is touched mirrors Slint’s invoke_from_event_loop discipline. web-fetch-like: a 4xx / 5xx is a completed reply the script can branch on (via response.ok / response.status), not an error.

Fields

§method: String

HTTP method (GET, POST, PUT, DELETE, …). Case-insensitive.

§url: String

Target URL.

§headers: Vec<(String, String)>

Request headers as ordered key/value pairs.

§body: Option<String>

Optional request body. None sends no body.

§timeout_ms: Option<u64>

Optional per-request timeout in milliseconds (None = no client-imposed deadline).

§credentials: Credentials

Whether the request carries the page’s credentials. Only a browser transport acts on it.

§tag: String

Identifier echoed back in on_http(tag, response).

§

SetResponseStatus

Set the status code of the response the document is being rendered for.

A page rendered per request answers with more than markup: a page for a record nobody has says so with a 404, and a form that rejects what it was sent says so with a 422. Nothing outside a server render reads this.

Fields

§status: u16

HTTP status code.

§

SetResponseHeader

Set a header on the response the document is being rendered for.

Setting the same name twice replaces the value. The renderer decides what a script may set: a name that would rewrite how the body is framed, or one carrying a line break, is refused and reported.

Fields

§name: String

Header name.

§value: String

Header value.

§

Redirect

Answer the request with a redirect instead of a document.

The render stops where it is: whatever the app had rendered is dropped, because a visitor being sent elsewhere never sees it.

Fields

§location: String

Where the visitor is sent, as a path or an absolute URL.

§

SetSignal

Write value into the named slot of the reactive [Signals] map. Any entity carrying a Bind* component pointing at this name re-renders next tick. Strings only at this layer; numeric / bool signals are stringified before storage.

Fields

§name: String

Signal name.

§value: String

New value.

§

SetProperty

Typed write into lumen_core::property_store::PropertyStore. Unlike Self::SetSignal, this variant carries a typed [PropertyValue] (i64 / f64 / bool / color / vec2 / arc-str / custom) and lands directly in the typed cell - no stringify, no [Signals] mirror. Used by typed Rhai builtins (signal_set_int / _float / _bool / _color) and the C FFI typed setters when they want to enqueue through the script command bus instead of the cross-thread push_external_property channel. The Rhai host today prefers the channel path (immediate, no tick round-trip); this variant is the equivalent for hosts that want to defer until the next apply_script_commands drain (gives the system one frame to coalesce typed writes).

Fields

§key: PropertyKey

Property key (global or entity-scoped).

§value: PropertyValue

New typed value. A Custom payload cannot be encoded; see crate::wire::property_value.

§

SetArray

Replace the named entry in the reactive ArraySignals map with a fresh ordered vector of records. Each record’s field values are pre-stringified at the script boundary so the receiving system doesn’t need to deserialize per-frame. Any <for each="<name>"> reconciler then spawns / despawns child markup to match.

Fields

§name: String

Array name.

§items: Vec<HashMap<String, String>>

Items, each a flat map of field -> stringified value.

§

Notify

Show a native desktop notification. Cross-platform via notify-rust (libnotify on Linux, NSUserNotification on macOS, Toast on Windows).

Fields

§title: String

Notification summary / title.

§body: String

Body text.

§

NotifyEx

Show a native desktop notification carrying an icon, an urgency, and action buttons. Pressing a button fires on_notification_action(id, action_id).

Fields

§id: String

Stable id echoed back in on_notification_action.

§title: String

Notification summary / title.

§body: String

Body text.

§options: String

Settings as "icon:name-or-path|urgency:critical". Unknown keys are ignored; empty means no icon and normal urgency.

§actions: String

Buttons as "id:Label|id2:Label2". Empty means no buttons.

§

ClipboardWrite

Put text on the system clipboard.

Fields

§text: String

Text to copy.

§

ClipboardRead

Request the system clipboard’s text. The runtime reads it and fires on_clipboard(tag, text).

Fields

§tag: String

Identifier the script gets back in the event handler.

§

OpenUrl

Open a URL with the user’s default handler (browser, mail client).

Fields

§url: String

Absolute URL, including its scheme.

§

OpenPath

Open a filesystem path with the platform’s default application. Relative paths resolve against the app directory.

Fields

§path: String

Path to open.

§

RevealPath

Show a file in the platform’s file manager. Relative paths resolve against the app directory.

Fields

§path: String

Path to reveal.

§

KeepAwake

Hold off the screensaver and system sleep under name until a matching ScriptCommand::AllowSleep. Repeating a live name replaces its request rather than stacking a second one.

Fields

§name: String

Identifier used to release the request later.

§reason: String

Human-readable reason shown by the platform’s power settings.

§

AllowSleep

Release the sleep inhibit registered under name. No-op when the name is unknown.

Fields

§name: String

Identifier matching the previous KeepAwake call.

§

CopyImageToClipboard

Reads the PNG at path and writes its pixels to the system clipboard. path is resolved relative to the app directory by the runtime handler.

Fields

§path: String

Source PNG path.

§

SaveClipboardImage

Pulls the current clipboard image (when present) and writes it as PNG to path. Failures log to stderr.

Fields

§path: String

Destination PNG path.

§

RegisterTrayIcon

Registers or replaces a system tray icon on macOS, Windows, and Linux. icon_path resolves relative to the app dir.

Fields

§id: String

Stable id; clicks fire on_tray(id).

§icon_path: String

Path to a PNG icon.

§tooltip: Option<String>

Optional hover tooltip.

§menu: String

Context-menu items as "id:Label|-|id2:Label2", where - is a separator. Picking one fires on_menu(id). Empty means no menu.

§template: bool

macOS template-image flag: treat a monochrome icon as a template and recolour it for the active menu-bar theme.

§

UnregisterTrayIcon

Drops a previously-registered tray icon by id.

Fields

§id: String

Matching id from RegisterTrayIcon.

§

SetClasses

Replace the LumenClasses of the entity whose LumenId matches target_id (or the root entity when target_id is "<root>"). Triggers a runtime CSS re-apply (K9) - the downstream system detects Changed<LumenClasses> on the root and re-spawns the tree with the new class set.

Fields

§target_id: String

Target entity id, or the sentinel <root> to address the markup root.

§classes: String

Whitespace-separated class names - same shape as class="..." markup attr.

§

SetColorScheme

Switch the app’s color scheme. The runtime parses name into a lumen_core::components::ColorScheme and hands it to the style manager, which re-resolves every theme token. An unknown name is logged and ignored.

Fields

§name: String

One of "default", "force-light", "force-dark", "prefer-light", "prefer-dark". "default" follows the OS.

§

OpenFileDialog

Open a native file dialog (open, multi-open, save, or folder pick). The runtime serves the dialog on the main thread via rfd, then fires on_file_picked(tag, path) / on_files_picked(tag, paths_joined_by_pipe) / on_folder_picked(tag, path) (or the per-id on() route) once the user closes it.

Fields

§kind: FileDialogKind

What kind of dialog to show.

§tag: String

Identifier the script gets back in the event handler.

§filters: Vec<(String, Vec<String>)>

Filter list: (label, extensions) pairs. Empty = no filter (show all files).

§default_name: Option<String>

Default filename suggestion for Save. Ignored for the other kinds.

§

RegisterHotkey

Register an OS-level global hotkey. Accelerator strings follow the keyboard-types/Electron convention ("CommandOrControl+S", "Alt+Space", "F11"). on_hotkey(name) fires every time the OS dispatches the chord regardless of window focus.

Fields

§name: String

Identifier the script gets back in on_hotkey(name).

§accelerator: String

Accelerator string. See global-hotkey::HotKey::from_str.

§

UnregisterHotkey

Unregister a previously-registered hotkey by name. No-op if the name is unknown.

Fields

§name: String

Identifier matching the previous RegisterHotkey call.

§

SetAttr

Set an attribute on a node addressed by packed handle. KNOWN attrs (id, class, src, text, disabled, …) route to their typed component; everything else lands in the generic lumen_core::components::LumenAttributes map.

Fields

§node: u64

Target node (packed handle or reserved spawn token).

§name: String

Attribute name.

§value: String

New value.

§

RemoveAttr

Remove an attribute from a node addressed by packed handle.

Fields

§node: u64

Target node.

§name: String

Attribute name to clear.

§

SetNodeText

Replace a node’s text content (node.set_text).

Fields

§node: u64

Target node.

§text: String

New text.

§

ClassAdd

Add one class to a node’s class list (incremental, idempotent).

Fields

§node: u64

Target node.

§class: String

Class name to add.

§

ClassRemove

Remove one class from a node’s class list.

Fields

§node: u64

Target node.

§class: String

Class name to remove.

§

ClassToggle

Toggle one class on a node’s class list.

Fields

§node: u64

Target node.

§class: String

Class name to toggle.

§

SetStyleProp

Set an inline style property (element.style), the highest cascade tier the runtime re-apply reads.

Fields

§node: u64

Target node.

§name: String

CSS property name.

§value: String

CSS value.

§

RemoveStyleProp

Remove an inline style property.

Fields

§node: u64

Target node.

§name: String

CSS property name to clear.

§

Spawn

Create a fresh detached element with markup tag tag. reserved is the token the host minted synchronously so the same tick’s chained mutations address the node; the applier maps it onto the entity it spawns.

Fields

§tag: String

Markup tag (div, button, …).

§reserved: u64

Reserved spawn token (see lumen_core::node::reserve_node_token).

§

Insert

Attach node under parent. before (when non-zero) is a reference child to insert ahead of (insert_before); zero appends at the end (append / set_parent / move_to / reparent all route here).

Fields

§parent: u64

Parent node.

§node: u64

Node to attach (detaching it from any current parent).

§before: u64

Reference child to insert before, or 0 to append.

§

ReplaceWith

Replace old with new in old’s parent, then despawn old’s subtree (replaceWith).

Fields

§old: u64

Node being replaced (removed after).

§new: u64

Replacement node, moved into old’s slot.

§

RemoveNode

Detach and despawn a node and its whole subtree (node.remove).

Fields

§node: u64

Node to remove.

§

CloneNode

Deep-clone source’s subtree into a fresh detached node. reserved is the token the host minted for the clone root.

Fields

§source: u64

Node to clone (with descendants).

§reserved: u64

Reserved spawn token for the clone root.

§

SetInnerMarkup

Replace node’s children with the subtree parsed from markup (element.innerHTML = ...). The markup is parsed by the injected front-end and spawned through the same path the <for> reconciler uses, so layout / style / paint stay consistent.

Guarded: parsing needs the injected markup front-end (SourceParser is a runtime concept), which is present on the dev / from-source run path but absent in the precompiled-artifact path; there it is a no-op. Do not feed untrusted content; this injects live markup (XSS-adjacent).

Fields

§node: u64

Target node whose children are replaced.

§markup: String

Markup fragment to parse and spawn as the new children.

§

SpawnFragment

Instantiate the compiled fragment key into a fresh detached subtree. reserved is the token the host minted for the instance root, so the same tick’s Insert attaches it.

args binds the fragment’s parameters, in use-site order; a parameter absent here takes its declared default, and one with neither resolves empty. Arguments substitute once, at instantiation: a value that changes while the app runs belongs in a bind-* attribute inside the fragment body.

children maps a slot name to a node that already exists, which the applier moves into that slot. Passing live handles is what keeps the applier off the script VM: a caller composing nested fragments instantiates the inner ones first and passes their roots in.

Fields

§key: String

Key of the fragment to instantiate.

§args: Vec<(String, String)>

Arguments as (parameter name, value) pairs.

§children: Vec<(String, u64)>

Slot content as (slot name, node handle) pairs.

§reserved: u64

Reserved spawn token for the instance root.

§

BindEvent

Bind an event handler to a node. token is the off token the host minted synchronously; the host holds the handler closure keyed by the same token, and the applier records (node, event_type, capture) in the host-neutral binding registry the dispatcher consults. handler_ref is the token (a host-neutral reference), consistent with the reserved-token model the structural commands use.

Fields

§node: u64

Target node (packed handle or reserved spawn token).

§event_type: String

Event type ("click", "keydown", …).

§capture: bool

true for a capture-phase listener.

§token: u64

Off / handler token (handler_ref).

§

UnbindEvent

Unbind a previously-bound event handler by its off token (removeEventListener). No-op if the token is unknown.

Fields

§token: u64

Off token returned by the matching on(...).

§

WindowSetTitle

Set the OS window title (window.set_title).

Fields

§title: String

New title string.

§

WindowSetSize

Resize the OS window to width x height logical pixels (window.set_size).

Fields

§width: f32

Logical width.

§height: f32

Logical height.

§

AddRecentFile

Record path as recently opened (move-to-front, capped list). Relative paths resolve against the app directory.

Fields

§path: String

File path to record.

§label: String

Display label; empty derives one from the path’s file name.

§

ListRecentFiles

Request the recent-files list. The runtime reads it and fires on_recent_files(tag, paths), most recent first, paths joined by |.

Fields

§tag: String

Identifier the script gets back in the event handler.

§

ClearRecentFiles

Remove every entry from the recent-files list.

§

SetAutostart

Enable or disable launching this app at login.

Fields

§on: bool

Whether the app should autostart.

§

QueryAutostart

Request the current autostart state. The runtime reads it and fires on_autostart_enabled(tag) or on_autostart_disabled(tag).

Fields

§tag: String

Identifier the script gets back in the event handler.

§

RequestFrame

Ask for one on_frame(dt) call on the next tick.

The browser’s requestAnimationFrame: one request buys one callback, and a callback that wants another asks again. An app that stops asking stops being ticked for it, so an animation costs frames only while it is running.

§

SetLocale

Switch the app to another locale. The catalogue, the locale-aware formatters and the base writing direction all move together, and every element the markup marked is rebuilt from the new catalogue on the tick the switch lands.

A locale the app has no catalogue for is not an error: every message falls back to the text the author wrote, which is what naming such a locale in lumen.toml already does. A tag that is not BCP-47 is logged and ignored.

Fields

§tag: String

BCP-47 tag, such as "de-DE".

Implementations§

Source§

impl ScriptCommand

Source

pub fn mutates_dom(&self) -> bool

Whether the command changes the tree rather than the state behind it, which is what the DOM applier answers for.

Source

pub fn builds_nodes(&self) -> bool

Whether the command adds, removes or moves a node, rather than writing onto one the markup already declares.

A node a script builds is built by running the script, so anything producing a document without running one for the full life of the app has to know that these went by: a page rendered on a server carries the markup, the state and what the run wrote onto the nodes it found, and the nodes a script went on to create arrive when the browser runs it.

Trait Implementations§

Source§

impl Clone for ScriptCommand

Source§

fn clone(&self) -> ScriptCommand

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ScriptCommand

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ScriptCommand

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ScriptCommand

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> IntoResult<T> for T

§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,