feat(macros): add support for rename command macro in tauri-macros #14173
Related issues: https://github.com/tauri-apps/tauri/issues/14173
Preview
IDE & Rust Analyzer
Test code:
mod me {
#[tauri::command(alias = "greet_from_me")]
pub fn hello(name: &str) -> String {
format!("Hello, {}! Me hello from Rust!", name)
}
}
mod you {
#[tauri::command(alias = "greet_from_you")]
pub fn hello(name: &str) -> String {
format!("Hi, {}! You hello from Rust!", name)
}
}
#[tauri::command(alias = "salute")]
fn hello(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![hello, me::hello, you::hello])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
import { invoke } from "@tauri-apps/api/core";
import { useState } from "react";
import "./App.css";
import reactLogo from "./assets/react.svg";
function App() {
const [greetMsg, setGreetMsg] = useState("");
const [name, setName] = useState("");
async function handleGreetAll() {
const [salute, fromMe, fromYou] = await Promise.all([
invoke<string>("salute", { name }),
invoke<string>("greet_from_me", { name }),
invoke<string>("greet_from_you", { name }),
]);
setGreetMsg([salute, fromMe, fromYou].join("\n"));
}
return (
<main className="container">
<h1>Welcome to Tauri + React</h1>
<div className="row">
<a href="https://vite.dev" target="_blank">
<img src="/vite.svg" className="logo vite" alt="Vite logo" />
</a>
<a href="https://tauri.app" target="_blank">
<img src="/tauri.svg" className="logo tauri" alt="Tauri logo" />
</a>
<a href="https://react.dev" target="_blank">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
</div>
<p>Click on the Tauri, Vite, and React logos to learn more.</p>
<form
className="row"
onSubmit={(e) => {
e.preventDefault();
handleGreetAll();
}}
>
<input
id="greet-input"
onChange={(e) => setName(e.currentTarget.value)}
placeholder="Enter a name..."
/>
<button type="submit">Greet</button>
</form>
<pre>{greetMsg}</pre>
</main>
);
}
export default App;
Didn't look much into this yet, but I think if the idea is to rename the command, not having both command names valid, we should call it rename similar to #[serde(rename = "name")]
Package Changes Through 5d4430709cc6fb69f4b62ac8c74861f1826bd088
There are 3 changes which include tauri-macros with minor, tauri-macos-sign with patch, tauri-bundler with patch
Planned Package Versions
The following package releases are the planned based on the context of changes in this pull request.
| package | current | next |
|---|---|---|
| tauri-macos-sign | 2.3.1 | 2.3.2 |
| tauri-bundler | 2.7.4 | 2.7.5 |
| tauri-macros | 2.5.2 | 2.6.0 |
| tauri | 2.9.4 | 2.9.5 |
| @tauri-apps/cli | 2.9.5 | 2.9.6 |
| tauri-cli | 2.9.5 | 2.9.6 |
Add another change file through the GitHub UI by following this link.
Read about change files or the docs at github.com/jbolda/covector
Didn't look much into this yet, but I think if the idea is to rename the command, not having both command names valid, we should call it
renamesimilar to#[serde(rename = "name")]
I initially thought of using rename with #[serde(rename = "name")], but ended up keeping alias for functionality first and reference the issue. See if any review ideals I can go further.
Didn't look much into this yet, but I think if the idea is to rename the command, not having both command names valid, we should call it
renamesimilar to#[serde(rename = "name")]
It should be clearer now, changed to #[tauri::command(rename = "name")] . Since the new serde method exposed to user, might conflect with #serde(rename_all = "snake_case"), but the priority of rename_all is higher. We might need document on this behavior.