Skip to content
Discussion options

You must be logged in to vote

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;
    }
}

invoke is op…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@thejawker
Comment options

Answer selected by thejawker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants