use crate::collection::StoreCollection;
use crate::error::Result;
use crate::store::Store;
use crate::{CollectionMarker, DefaultMarker};
use tauri::{Manager, Runtime, State};
pub trait ManagerExt<R: Runtime>: Manager<R> {
fn store_collection(&self) -> State<'_, StoreCollection<R, DefaultMarker>> {
self.store_collection_with_marker::<DefaultMarker>()
}
fn store_collection_with_marker<C>(&self) -> State<'_, StoreCollection<R, C>>
where
C: CollectionMarker,
{
self.app_handle().state::<StoreCollection<R, C>>()
}
fn with_store<F, T>(&self, id: impl AsRef<str>, f: F) -> Result<T>
where
F: FnOnce(&mut Store<R, DefaultMarker>) -> T,
{
self.store_collection().with_store(id, f)
}
}
impl<R: Runtime, T: Manager<R>> ManagerExt<R> for T {}