Add get-or-create-store

This commit is contained in:
Tony
2024-10-03 13:34:38 +08:00
parent 17d910b381
commit 7ffd769240
7 changed files with 96 additions and 3 deletions
+14
View File
@@ -77,6 +77,19 @@ async fn get_store<R: Runtime>(app: AppHandle<R>, path: PathBuf) -> Option<Resou
stores.get(&path).copied()
}
#[tauri::command]
async fn get_or_create_store<R: Runtime>(
app: AppHandle<R>,
path: PathBuf,
auto_save: Option<AutoSave>,
) -> Result<ResourceId> {
if let Some(rid) = get_store(app.clone(), path.clone()).await {
Ok(rid)
} else {
create_store(app, path, auto_save).await
}
}
#[tauri::command]
async fn set<R: Runtime>(
app: AppHandle<R>,
@@ -232,6 +245,7 @@ impl<R: Runtime> Builder<R> {
.invoke_handler(tauri::generate_handler![
create_store,
get_store,
get_or_create_store,
set,
get,
has,