mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-05-09 12:36:07 +02:00
Fix description and create_new logic
This commit is contained in:
@@ -49,8 +49,6 @@ export type StoreOptions = {
|
||||
*
|
||||
* @param path Path to save the store in `app_data_dir`
|
||||
* @param options Store configuration options
|
||||
*
|
||||
* @throws If a store at that path is already loaded
|
||||
*/
|
||||
export async function create(
|
||||
path: string,
|
||||
@@ -75,8 +73,6 @@ export async function create(
|
||||
*
|
||||
* @param path Path to save the store in `app_data_dir`
|
||||
* @param options Store configuration options
|
||||
*
|
||||
* @throws If a store at that path is already loaded
|
||||
*/
|
||||
export async function load(
|
||||
path: string,
|
||||
@@ -232,8 +228,6 @@ export class Store extends Resource implements IStore {
|
||||
*
|
||||
* @param path Path to save the store in `app_data_dir`
|
||||
* @param options Store configuration options
|
||||
*
|
||||
* @throws If a store at that path is already loaded
|
||||
*/
|
||||
static async create(path: string, options?: StoreOptions): Promise<Store> {
|
||||
const rid = await invoke<number>('plugin:store|create_store', {
|
||||
@@ -259,8 +253,6 @@ export class Store extends Resource implements IStore {
|
||||
*
|
||||
* @param path Path to save the store in `app_data_dir`
|
||||
* @param options Store configuration options
|
||||
*
|
||||
* @throws If a store at that path is already loaded
|
||||
*/
|
||||
static async load(path: string, options?: StoreOptions): Promise<Store> {
|
||||
const rid = await invoke<number>('plugin:store|load', {
|
||||
|
||||
@@ -23,7 +23,7 @@ All operations are enabled by default.
|
||||
- `allow-values`
|
||||
- `allow-entries`
|
||||
- `allow-length`
|
||||
- `allow-load`
|
||||
- `allow-reload`
|
||||
- `allow-save`
|
||||
|
||||
## Permission Table
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use serde::{Serialize, Serializer};
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
@@ -21,9 +20,9 @@ pub enum Error {
|
||||
/// IO error.
|
||||
#[error(transparent)]
|
||||
Io(#[from] std::io::Error),
|
||||
/// Store already exists
|
||||
#[error("Store at \"{0}\" already exists")]
|
||||
AlreadyExists(PathBuf),
|
||||
// /// Store already exists
|
||||
// #[error("Store at \"{0}\" already exists")]
|
||||
// AlreadyExists(PathBuf),
|
||||
/// Serialize function not found
|
||||
#[error("Serialize Function \"{0}\" not found")]
|
||||
SerializeFunctionNotFound(String),
|
||||
|
||||
@@ -172,7 +172,7 @@ impl<R: Runtime> StoreBuilder<R> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Force create a new store even if it already exists.
|
||||
/// Force create a new store with default values even if it already exists.
|
||||
pub fn create_new(mut self) -> Self {
|
||||
self.create_new = true;
|
||||
self
|
||||
@@ -181,13 +181,22 @@ impl<R: Runtime> StoreBuilder<R> {
|
||||
pub(crate) fn build_inner(mut self) -> crate::Result<(Arc<Store<R>>, ResourceId)> {
|
||||
let stores = self.app.state::<StoreState>().stores.clone();
|
||||
let mut stores = stores.lock().unwrap();
|
||||
if let Some(rid) = stores.get(&self.path) {
|
||||
return Ok((self.app.resources_table().get(*rid).unwrap(), *rid));
|
||||
|
||||
self.path = resolve_store_path(&self.app, self.path)?;
|
||||
|
||||
if self.create_new {
|
||||
if let Some(rid) = stores.remove(&self.path) {
|
||||
let _ = self.app.resources_table().take::<Store<R>>(rid);
|
||||
}
|
||||
} else {
|
||||
if let Some(rid) = stores.get(&self.path) {
|
||||
return Ok((self.app.resources_table().get(*rid).unwrap(), *rid));
|
||||
}
|
||||
}
|
||||
|
||||
if stores.contains_key(&self.path) {
|
||||
return Err(crate::Error::AlreadyExists(self.path));
|
||||
}
|
||||
// if stores.contains_key(&self.path) {
|
||||
// return Err(crate::Error::AlreadyExists(self.path));
|
||||
// }
|
||||
|
||||
let mut store_inner = StoreInner::new(
|
||||
self.app.clone(),
|
||||
|
||||
Reference in New Issue
Block a user