@@ -457,6 +457,29 @@ async fn my_custom_command(app_handle: tauri::AppHandle) {
457
457
}
458
458
```
459
459
460
+ :::tip
461
+
462
+ ` AppHandle ` and ` WebviewWindow ` both take a generic parameter ` R: Runtime ` ,
463
+ when the ` wry ` feature is enabled in ` tauri ` (which is enabled by default),
464
+ we default the generic to the ` Wry ` runtime so you can use it directly,
465
+ but if you want to use a different runtime, for example the [ mock runtime] ,
466
+ you need to write your functions like this
467
+
468
+ ``` rust title="src-tauri/src/lib.rs" ins="<R: Runtime>" ins="<R>"
469
+ use tauri :: {AppHandle , GlobalShortcutManager , Runtime , WebviewWindow };
470
+
471
+ #[tauri:: command]
472
+ async fn my_custom_command <R : Runtime >(app_handle : AppHandle <R >, webview_window : WebviewWindow <R >) {
473
+ let app_dir = app_handle . path_resolver (). app_dir ();
474
+ app_handle
475
+ . global_shortcut_manager ()
476
+ . register (" CTRL + U" , move || {});
477
+ println! (" WebviewWindow: {}" , webview_window . label ());
478
+ }
479
+ ```
480
+
481
+ :::
482
+
460
483
### Accessing Managed State
461
484
462
485
Tauri can manage state using the ` manage ` function on ` tauri::Builder ` .
@@ -700,3 +723,4 @@ To learn how to listen to events and emit events from your Rust code, see the [R
700
723
[ Rust Event System documentation ] : /develop/calling-frontend/#event-system
701
724
[ channels documentation ] : /develop/calling-frontend/#channels
702
725
[ Calling Rust from the Frontend ] : /develop/calling-rust/
726
+ [ mock runtime ] : https://docs.rs/tauri/2.0.0/tauri/test/struct.MockRuntime.html
0 commit comments