-
|
I'm am working on an idea where I'd like to share progress for a few situations:
It's important that the the progress is entity scoped, eg there might be a list of uploads/audio files and they should individually update. What is the preferred way to get this type of progress data back to the client? My first thought is the following:
I'm thinking this should work, but I feel that there might be a better/cleaner/easier/more tauri type of approach, hence this question. So far really digging tauri, thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
It's in the docs and its called Events. Here is another simple example of it: In your JavaScript: import {listen} from '@tauri-apps/api/event';
import {invoke} from '@tauri-apps/api/tauri';
// Set it to a variable if you want to unlisten later
listen('stuff-happened', (event) => {
console.log(event);
});
invoke('do_stuff');And then emit the event as much as you want in rust: // Don't forget the required includes/definitions
#[tauri::command(async)]
fn do_stuff(window: Window) {
let mut progress: u8 = 0;
loop {
window.emit("stuff-happened", Payload {message: progress.to_string()}).unwrap();
if progress > 20 {break;};
progress += 1;
}
}
You can separate them by id, event name and even window. |
Beta Was this translation helpful? Give feedback.
It's in the docs and its called Events. Here is another simple example of it:
In your JavaScript:
And then emit the event as much as you want in rust:
invokeis op…