mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-09-26 21:41:48 +02:00
@@ -5,7 +5,6 @@
|
|||||||
const COMMANDS: &[&str] = &[
|
const COMMANDS: &[&str] = &[
|
||||||
"create_store",
|
"create_store",
|
||||||
"get_store",
|
"get_store",
|
||||||
"get_or_create_store",
|
|
||||||
"set",
|
"set",
|
||||||
"get",
|
"get",
|
||||||
"has",
|
"has",
|
||||||
|
|||||||
@@ -42,17 +42,6 @@ export async function getStore(path: string): Promise<Store | undefined> {
|
|||||||
return await Store.getStore(path)
|
return await Store.getStore(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param path: Path to save the store in `app_data_dir`
|
|
||||||
* @param options: Store configuration options
|
|
||||||
*/
|
|
||||||
export async function getOrCreateStore(
|
|
||||||
path: string,
|
|
||||||
options?: StoreOptions
|
|
||||||
): Promise<Store> {
|
|
||||||
return await Store.getOrCreateStore(path, options)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A lazy loaded key-value store persisted by the backend layer.
|
* A lazy loaded key-value store persisted by the backend layer.
|
||||||
*
|
*
|
||||||
@@ -67,7 +56,9 @@ export class LazyStore implements IStore {
|
|||||||
|
|
||||||
private get store(): Promise<Store> {
|
private get store(): Promise<Store> {
|
||||||
if (!this._store) {
|
if (!this._store) {
|
||||||
this._store = getOrCreateStore(this.path, this.options)
|
this._store = createStore(this.path, this.options).catch(
|
||||||
|
async () => (await getStore(this.path))!
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return this._store
|
return this._store
|
||||||
}
|
}
|
||||||
@@ -183,24 +174,6 @@ export class Store extends Resource implements IStore {
|
|||||||
return resourceId ? new Store(resourceId, path) : undefined
|
return resourceId ? new Store(resourceId, path) : undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param path: Path to save the store in `app_data_dir`
|
|
||||||
* @param options: Store configuration options
|
|
||||||
*/
|
|
||||||
static async getOrCreateStore(
|
|
||||||
path: string,
|
|
||||||
options?: StoreOptions
|
|
||||||
): Promise<Store> {
|
|
||||||
const resourceId = await invoke<number>(
|
|
||||||
'plugin:store|get_or_create_store',
|
|
||||||
{
|
|
||||||
path,
|
|
||||||
...options
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return new Store(resourceId, path)
|
|
||||||
}
|
|
||||||
|
|
||||||
async set(key: string, value: unknown): Promise<void> {
|
async set(key: string, value: unknown): Promise<void> {
|
||||||
await invoke('plugin:store|set', {
|
await invoke('plugin:store|set', {
|
||||||
rid: this.rid,
|
rid: this.rid,
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
# Automatically generated - DO NOT EDIT!
|
|
||||||
|
|
||||||
"$schema" = "../../schemas/schema.json"
|
|
||||||
|
|
||||||
[[permission]]
|
|
||||||
identifier = "allow-get-or-create-store"
|
|
||||||
description = "Enables the get_or_create_store command without any pre-configured scope."
|
|
||||||
commands.allow = ["get_or_create_store"]
|
|
||||||
|
|
||||||
[[permission]]
|
|
||||||
identifier = "deny-get-or-create-store"
|
|
||||||
description = "Denies the get_or_create_store command without any pre-configured scope."
|
|
||||||
commands.deny = ["get_or_create_store"]
|
|
||||||
@@ -165,32 +165,6 @@ Denies the get command without any pre-configured scope.
|
|||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
|
|
||||||
`store:allow-get-or-create-store`
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
|
|
||||||
Enables the get_or_create_store command without any pre-configured scope.
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
|
|
||||||
`store:deny-get-or-create-store`
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
|
|
||||||
Denies the get_or_create_store command without any pre-configured scope.
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
|
|
||||||
`store:allow-get-store`
|
`store:allow-get-store`
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ All operations are enabled by default.
|
|||||||
"""
|
"""
|
||||||
permissions = [
|
permissions = [
|
||||||
"allow-create-store",
|
"allow-create-store",
|
||||||
"allow-get-store",
|
|
||||||
"allow-get-or-create-store",
|
|
||||||
"allow-clear",
|
"allow-clear",
|
||||||
"allow-delete",
|
"allow-delete",
|
||||||
"allow-entries",
|
"allow-entries",
|
||||||
|
|||||||
@@ -344,16 +344,6 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"const": "deny-get"
|
"const": "deny-get"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"description": "Enables the get_or_create_store command without any pre-configured scope.",
|
|
||||||
"type": "string",
|
|
||||||
"const": "allow-get-or-create-store"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Denies the get_or_create_store command without any pre-configured scope.",
|
|
||||||
"type": "string",
|
|
||||||
"const": "deny-get-or-create-store"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"description": "Enables the get_store command without any pre-configured scope.",
|
"description": "Enables the get_store command without any pre-configured scope.",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
|||||||
@@ -77,19 +77,6 @@ async fn get_store<R: Runtime>(app: AppHandle<R>, path: PathBuf) -> Option<Resou
|
|||||||
stores.get(&path).copied()
|
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]
|
#[tauri::command]
|
||||||
async fn set<R: Runtime>(
|
async fn set<R: Runtime>(
|
||||||
app: AppHandle<R>,
|
app: AppHandle<R>,
|
||||||
@@ -245,7 +232,6 @@ impl<R: Runtime> Builder<R> {
|
|||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
create_store,
|
create_store,
|
||||||
get_store,
|
get_store,
|
||||||
get_or_create_store,
|
|
||||||
set,
|
set,
|
||||||
get,
|
get,
|
||||||
has,
|
has,
|
||||||
|
|||||||
Reference in New Issue
Block a user