Closed bicarlsen closed 6 months ago
I can't provide in-depth explanation, but feel free to look at my tauri-leptos-example
repo. I'm using there event::once
and event::listen
(to continuously subscribe to stream of events).
One thing I've noticed is that you can only consume window-specific events (emitted from Window
). It seems to be like that because window_label
is required for events in this crate. And it's only being send for window-specific events (by Tauri).
A code snippet that I got running:
use wasm_bindgen_futures::spawn_local;
use futures::stream::StreamExt;
use yew::prelude::*;
#[function_component(MyComponent)]
pub fn my_component() -> Html
use_effect_with_deps(
move |_| {
spawn_local(async move {
let mut events = tauri_sys::event::listen::<i32>("tauri://file-drop")
.await
.expect("could not create `tauri://file-drop` listener");
while let Some(event) = events.next().await {
web_sys::console::log_1(&event.payload.into());
}
});
}
)
html! {}
}
closing this as it seems to not be an issue anymore?
Yeah, thanks!
I am trying to use
event::listener
to react to events coming from the tauri backend in the frontend, but am having trouble actually consuming the result ofevent::listen
.Would it be possible to provide a more in-depth example or explanation than the one provided in the docs to help me understand how to use it?