mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-27 11:56:05 +02:00
Add close store
This commit is contained in:
@@ -26,7 +26,7 @@ export type StoreOptions = {
|
||||
* @param path: Path to save the store in `app_data_dir`
|
||||
* @param options: Store configuration options
|
||||
*
|
||||
* Throws if the store at that path already exists
|
||||
* @throws If a store at that path already exists
|
||||
*/
|
||||
export async function createStore(
|
||||
path: string,
|
||||
|
||||
@@ -463,6 +463,18 @@ impl<R: Runtime> Store<R> {
|
||||
self.store.lock().unwrap().save()
|
||||
}
|
||||
|
||||
pub fn close_store(self) {
|
||||
let store = self.store.lock().unwrap();
|
||||
let app = store.app.clone();
|
||||
let collection = app.state::<StoreCollection>();
|
||||
let stores = collection.stores.lock().unwrap();
|
||||
if let Some(rid) = stores.get(&store.path).copied() {
|
||||
drop(store);
|
||||
drop(stores);
|
||||
let _ = app.resources_table().take::<Store<R>>(rid);
|
||||
}
|
||||
}
|
||||
|
||||
fn trigger_auto_save(&self) -> crate::Result<()> {
|
||||
let Some(auto_save_delay) = self.auto_save else {
|
||||
return Ok(());
|
||||
|
||||
Reference in New Issue
Block a user