use crate::collection::{StoreCollection, RESOURCE_ID};
use crate::error::Result;
use crate::store::Store;
use std::sync::Arc;
use tauri::{AppHandle, Manager, Runtime, WebviewWindow, Window};
pub trait ManagerExt<R: Runtime>: Manager<R> {
fn store_collection(&self) -> Arc<StoreCollection<R>> {
let rid = RESOURCE_ID
.get()
.expect("missing store collection resource id");
self
.resources_table()
.get::<StoreCollection<R>>(*rid)
.expect("store collection is not in the resources table")
}
fn with_store<F, T>(&self, id: impl AsRef<str>, f: F) -> Result<T>
where
F: FnOnce(&mut Store<R>) -> T,
{
self.store_collection().with_store(id, f)
}
}
impl<R: Runtime> ManagerExt<R> for AppHandle<R> {}
impl<R: Runtime> ManagerExt<R> for WebviewWindow<R> {}
impl<R: Runtime> ManagerExt<R> for Window<R> {}