wry_cmd

Crates.iowry_cmd
lib.rswry_cmd
version0.1.3
created_at2025-07-25 14:45:50.499867+00
updated_at2025-07-25 19:11:41.683348+00
descriptionFacade crate combining wry_cmd_core (runtime) and wry_cmd_macro (IPC-command registration) for Wry.
homepagehttps://github.com/KitsuneDev/wry_cmd
repositoryhttps://github.com/KitsuneDev/wry_cmd
max_upload_size
id1767727
size82,500
Kitsune (KitsuneDev)

documentation

https://docs.rs/wry_cmd

README

wry_cmd

Tauri-style #[command] macro and command system for wry, supporting async Rust functions and front-end integration via a custom protocol.

🚀 Features

  • #[command] macro for both async fn and fn
  • Auto-registers via inventory
  • Uses Wry’s with_asynchronous_custom_protocol
  • JSON-over-POST interface
  • CORS preflight support

🔧 Usage


use wry_cmd::{command, use_wry_cmd_protocol};

#[derive(serde::Deserialize, Default)]
struct GreetArgs {
    name: String,
}

#[derive(serde::Serialize, Default)]
struct GreetReply {
    message: String,
}

#[command]
fn greet(args: GreetArgs) -> GreetReply {
    println!("Greet command called with: {:?}", args.name);
    GreetReply {
        message: format!("Hello, {}!", args.name),
    }
}

let wv = WebViewBuilder::new()
        .with_asynchronous_custom_protocol("proto".to_string(), use_wry_cmd_protocol!("proto"))
        .build(&window)
        .expect("Failed to build WebView");

Then in JS:

async function sendGreet() {
  const name = document.getElementById("name").value;
  // You can use `http://proto.greet` for Windows compatibility
  // or `proto://greet` for other platforms.
  const res = await fetch(`http://proto.greet`, {
    method: "POST",
    body: JSON.stringify({ name }),
    headers: { "Content-Type": "application/json" },
  });
  const data = await res.json();
  document.getElementById("response").textContent = data.error
    ? "Error: " + data.error
    : data.message;
}

AI Usage Disclaimer

Please note that AI has been used in order to properly document this crate.

Commit count: 0

cargo fmt