tauri_plugin_valtio/
manager.rs

1// This file was autogenerated and should not be edited manually.
2// Check the `codegen` command in the `tauri-store-cli` crate.
3
4use crate::valtio::Valtio;
5use tauri::{AppHandle, Manager, Runtime, State, WebviewWindow, Window};
6use tauri_store::{Result, Store};
7
8/// Extension for the [`Manager`] trait providing access to the Valtio plugin.
9///
10/// [`Manager`]: https://docs.rs/tauri/latest/tauri/trait.Manager.html
11pub trait ManagerExt<R: Runtime>: Manager<R> {
12  /// Returns a handle to the Valtio plugin.
13  ///
14  /// # Panics
15  ///
16  /// Panics if the internal [store collection] is not in the [resources table].
17  ///
18  /// This likely indicates that the method was called before the plugin was properly initialized.
19  ///
20  /// [store collection]: https://docs.rs/tauri-store/latest/tauri_store/struct.StoreCollection.html
21  /// [resources table]: https://docs.rs/tauri/latest/tauri/struct.ResourceTable.html
22  fn valtio(&self) -> State<Valtio<R>> {
23    self.app_handle().state::<Valtio<R>>()
24  }
25
26  /// Calls a closure with a mutable reference to the store with the given id.
27  fn with_store<F, T>(&self, id: impl AsRef<str>, f: F) -> Result<T>
28  where
29    F: FnOnce(&mut Store<R>) -> T,
30  {
31    self.valtio().with_store(id, f)
32  }
33}
34
35impl<R: Runtime> ManagerExt<R> for AppHandle<R> {}
36impl<R: Runtime> ManagerExt<R> for WebviewWindow<R> {}
37impl<R: Runtime> ManagerExt<R> for Window<R> {}