Skip to content

Tauri

Desktop

tauri commands

Calling Rust from the frontend | Tauri Apps

从 JS 模组中调用 tauri 函数

传递参数

#[tauri::command]
fn my_custom_command(invoke_message: String) {
  println!("I was invoked from JS, with this message: {}", invoke_message);
}
invoke("my_custom_command", { invokeMessage: "Hello!" });

返回数据

#[tauri::command]
fn my_custom_command() -> String {
  "Hello from Rust!".into()
}
invoke("my_custom_command").then((message) => console.log(message));

issues

WebView2Loader.dll not found

提示 WebView2Loader 缺失的问题

不支持 gnu toolchain MinGW 可选择切换到 msvc toolchain 需要已安装 visualstudio2019buildtoolsvisualstudio2019-workload-vctools

rustup toolchain install stable-msvc
rustup default stable-msvc
  • 不同平台的 Command::new() 执行
Command::new("cmd")
    .args(["-C"], ["copy"])
Command::new("cp")

Mobile (Alpha)

Configuration | Tauri Apps

Prerequisites

NDK_HOME set to the directory of NDK

sdkmanager "ndk;version"

cargo tauri android init install Android toolchain