tauri-async-handler

Crates.iotauri-async-handler
lib.rstauri-async-handler
version0.4.0
sourcesrc
created_at2020-06-13 12:08:54.635705
updated_at2021-01-11 17:23:37.315234
descriptionA async handler for tauri
homepage
repositoryhttps://github.com/spacemeowx2/tauri-async-handler
max_upload_size
id253528
size6,559
imspace (spacemeowx2)

documentation

https://docs.rs/tauri-async-handler

README

tauri-async-handler

Usage

Cargo.toml:

[dependencies]
tauri-async-handler = "0.1"

src-tauri/main.rs:

mod cmd;

use serde_json::json;
use tauri_async_handler::*;

fn main() {
  tauri::AppBuilder::new()
    .async_handler(None, |cmd: cmd::Cmd| async {
      use cmd::Cmd::*;
      Ok(match cmd {
        MyCustomCommand{ argument } => {
          println!("arg {}", argument);
          let world = "world";
          json!({
            "hello": world
          })
        }
      })
    })
    .build()
    .run();
}

JavaScript:

const myCustomCommand = (argument) => {
  return window.tauri.promisified({
    cmd: 'myCustomCommand',
    argument,
  })
}
myCustomCommand.then((r) => console.log('myCustomCommand', r))
Commit count: 12

cargo fmt