5
5
![ License] ( https://img.shields.io/crates/l/tauri-interop.svg )
6
6
7
7
What this crate tries to achieve:
8
- - generate a equal wasm-function for your defined ` tauri::command `
8
+ - generate an equal wasm-function for your defined ` tauri::command `
9
9
- collecting all defined ` tauri::command ` s without adding them manually
10
- - a way to sending events from tauri and receiving them in the frontend
10
+ - a convenient way to send events from tauri and receiving them in the frontend
11
11
12
12
13
13
## Basic usage:
@@ -17,6 +17,52 @@ What this crate tries to achieve:
17
17
> Some examples in this documentation can't be executed with doctests due to
18
18
> required wasm target and tauri modified environment (see [ withGlobalTauri] ( https://tauri.app/v1/api/config/#buildconfig.withglobaltauri ) )
19
19
20
+ ### QOL macros
21
+
22
+ This crate also adds some quality-of-life macros. These are intended to ease the drawbacks of compiling to
23
+ multiple architectures.
24
+
25
+ #### Conditional ` use `
26
+ Because most crates are not intended to be compiled to wasm and most wasm crates are not intended to be compiled to
27
+ the host-triplet they have to be excluded in each others compile process. The usual process to exclude uses for a certain
28
+ architecture would look something like this:
29
+
30
+ ``` rust
31
+ #[cfg(not(target_family = " wasm" ))]
32
+ use tauri :: AppHandle ;
33
+
34
+ #[tauri_interop:: command]
35
+ pub fn empty_invoke (_handle : AppHandle ) {}
36
+ ```
37
+
38
+ ** General usage:**
39
+
40
+ With the help of ` tauri_interop::host_usage!() ` and ` tauri_interop::wasm_usage!() ` we don't need to remember which
41
+ attribute we have to add and can just convert the above to the following:
42
+
43
+ ``` rust
44
+ tauri_interop :: host_usage! {
45
+ use tauri :: AppHandle ;
46
+ }
47
+
48
+ #[tauri_interop:: command]
49
+ pub fn empty_invoke (_handle : AppHandle ) {}
50
+ ```
51
+
52
+ ** Multiple ` use ` usage:**
53
+
54
+ When multiple ` use ` should be excluded, they need to be separated by a single pipe (` | ` ). For example:
55
+
56
+ ``` rust
57
+ tauri_interop :: host_usage! {
58
+ use tauri :: State ;
59
+ | use std :: sync :: RwLock ;
60
+ }
61
+
62
+ #[tauri_interop:: command]
63
+ pub fn empty_invoke (_state : State <RwLock <String >>) {}
64
+ ```
65
+
20
66
### Command (Frontend => Backend Communication)
21
67
> For more examples see [ cmd.rs] ( ./test-project/api/src/cmd.rs ) in test-project
22
68
0 commit comments