Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ertanic/tauri-typed-invoke
A small utility that generates a typescript declaration file for the invoke function from functions found in code by Tauri commands. Thanks to this, there is no mistaking the name of the command.
https://github.com/ertanic/tauri-typed-invoke
rust tauri utils
Last synced: 14 days ago
JSON representation
A small utility that generates a typescript declaration file for the invoke function from functions found in code by Tauri commands. Thanks to this, there is no mistaking the name of the command.
- Host: GitHub
- URL: https://github.com/ertanic/tauri-typed-invoke
- Owner: Ertanic
- License: mit
- Created: 2024-04-12T03:47:46.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-04-12T03:50:16.000Z (10 months ago)
- Last Synced: 2024-12-20T00:13:27.991Z (about 2 months ago)
- Topics: rust, tauri, utils
- Language: Rust
- Homepage: https://crates.io/crates/tauri-named-invoke
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# About
`tauri-named-invoke` is a small utility that generates a typescript declaration file for the [`invoke`](https://tauri.app/v1/api/js/tauri/#invoke) function from functions found in code by Tauri [commands](https://docs.rs/tauri/1.6.1/tauri/command/index.html).
Thanks to this, there is no mistaking the name of the command.# Example
**main.rs:**
```rust
fn main() {
tauri::Builder::default()
.invoke_handler(generate_handler![get_weather, get_config])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}#[tauri::command]
fn get_weather() -> String {
"sunny".to_string()
}
// or
use tauri::command;
#[command]
fn get_config() -> String {
"config".to_string()
}
```**build.rs:**
```rust
fn main() {
tauri_named_invoke::build("ui").unwrap();
tauri_build::build();
}
```The file will be generated at the following path:
```shell
project root
├── ui
│ └── invoke.d.ts
├── src
│ └── main.rs
└── Cargo.toml
```The generated file will contain:
```typescript
import * as tauri from '@tauri-apps/api/tauri';
declare module '@tauri-apps/api' {
type Commands =
'get_weather'
| 'get_config';function invoke(cmd: Commands, args?: InvokeArgs): Promise;
}
```