wry_cmd 0.1.3

Facade crate combining wry_cmd_core (runtime) and wry_cmd_macro (IPC-command registration) for Wry.
Documentation

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.