new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Tauri · Develop · all subjects

calling frontend from rust

10 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Global events delivered to all listeners with Emitter#emit

Global events are triggered using the Emitter#emit function and are delivered to all listeners. Example: app.emit("download-started", &url).unwrap();

Webview-specific events delivered with Emitter#emit_to

Webview-specific events are triggered using the Emitter#emit_to function and are delivered only to listeners matching a specified webview label. Example: app.emit_to("login", "login-result", result).unwrap();

Filter events to multiple webviews with Emitter#emit_filter

You can trigger events to a filtered list of webviews using the Emitter#emit_filter function with a closure that matches target webview labels. Example: app.emit_filter("open-file", path, |target| match target { EventTarget::WebviewWindow { label } => label == "main" || label == "file-viewer", _ => false, }).unwrap();

Webview-specific events do not trigger global event listeners

Webview-specific events (emitted with emit_to or emit_filter) do not trigger regular global event listeners. To listen to all events regardless of scope, use the listen_any function instead of listen.

Event payloads must be serializable and optionally cloneable

Event payloads can be any serializable type (implementing the Serialize trait) and can also implement the Clone trait. This allows sending complex data structures as event payloads.

Channels for high-speed ordered data streaming

Channels are designed to deliver data quickly and in order. They are used internally for streaming operations like download progress, subprocess output, and WebSocket messages. Channels should be used instead of events for large data transfers.

Channel command parameter receives streamed events

In Tauri commands, you can accept a Channel<T> parameter to receive events from JavaScript. The JavaScript side creates a Channel instance and passes it as a command argument, then listens via onmessage callback. Rust side sends data using channel.send(event).unwrap().

Create and listen to channels from JavaScript

JavaScript code creates a Channel instance with type parameter, sets an onmessage callback to receive events, and passes the channel as an argument to invoke. Example: const onEvent = new Channel<DownloadEvent>(); onEvent.onmessage = (message) => { console.log(message.event); }; await invoke('download', { url: '...', onEvent });

Execute JavaScript directly in webview context with WebviewWindow#eval

Use the WebviewWindow#eval function to directly execute JavaScript code in the webview context. Example: let webview = app.get_webview_window("main").unwrap(); webview.eval("console.log('hello from Rust')")?;

Use serialize-to-javascript crate for complex Rust-to-JS serialization

For complex scripts that require input from Rust objects, the serialize-to-javascript crate is recommended for safely serializing Rust objects to JavaScript code.

Give your agent this brain