1use crate::collection::{StoreCollection, RESOURCE_ID};
2use crate::error::Result;
3use crate::store::Store;
4use std::sync::Arc;
5use tauri::{AppHandle, Manager, Runtime, WebviewWindow, Window};
6
7pub trait ManagerExt<R: Runtime>: Manager<R> {
11 fn store_collection(&self) -> Arc<StoreCollection<R>> {
21 let rid = RESOURCE_ID
22 .get()
23 .expect("missing store collection resource id");
24
25 self
26 .resources_table()
27 .get::<StoreCollection<R>>(*rid)
28 .expect("store collection is not in the resources table")
29 }
30
31 fn with_store<F, T>(&self, id: impl AsRef<str>, f: F) -> Result<T>
33 where
34 F: FnOnce(&mut Store<R>) -> T,
35 {
36 self.store_collection().with_store(id, f)
37 }
38}
39
40impl<R: Runtime> ManagerExt<R> for AppHandle<R> {}
41impl<R: Runtime> ManagerExt<R> for WebviewWindow<R> {}
42impl<R: Runtime> ManagerExt<R> for Window<R> {}