mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-09-22 21:30:44 +02:00
* fix(store): Use event module instead of appWindow, fixes #282 * fmt
This commit is contained in:
@@ -5,18 +5,18 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- dev
|
- dev
|
||||||
paths:
|
paths:
|
||||||
- '.github/workflows/msrv-check.yml'
|
- ".github/workflows/msrv-check.yml"
|
||||||
- 'plugins/*/src/**'
|
- "plugins/*/src/**"
|
||||||
- '**/Cargo.toml'
|
- "**/Cargo.toml"
|
||||||
- '**/Cargo.lock'
|
- "**/Cargo.lock"
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- dev
|
- dev
|
||||||
paths:
|
paths:
|
||||||
- '.github/workflows/msrv-check.yml'
|
- ".github/workflows/msrv-check.yml"
|
||||||
- 'plugins/*/src/**'
|
- "plugins/*/src/**"
|
||||||
- '**/Cargo.toml'
|
- "**/Cargo.toml"
|
||||||
- '**/Cargo.lock'
|
- "**/Cargo.lock"
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
|||||||
@@ -64,7 +64,9 @@ await store.save(); // this manually saves the store, otherwise the store is onl
|
|||||||
```
|
```
|
||||||
|
|
||||||
### Persisting values
|
### Persisting values
|
||||||
|
|
||||||
Values added to the store are not persisted between application loads unless:
|
Values added to the store are not persisted between application loads unless:
|
||||||
|
|
||||||
1. The application is closed gracefully (plugin automatically saves)
|
1. The application is closed gracefully (plugin automatically saves)
|
||||||
2. The store is manually saved (using `store.save()`)
|
2. The store is manually saved (using `store.save()`)
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,7 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
import { invoke } from "@tauri-apps/api/tauri";
|
import { invoke } from "@tauri-apps/api/tauri";
|
||||||
import { UnlistenFn } from "@tauri-apps/api/event";
|
import { listen, UnlistenFn } from "@tauri-apps/api/event";
|
||||||
import { appWindow } from "@tauri-apps/api/window";
|
|
||||||
|
|
||||||
interface ChangePayload<T> {
|
interface ChangePayload<T> {
|
||||||
path: string;
|
path: string;
|
||||||
@@ -180,14 +179,11 @@ export class Store {
|
|||||||
key: string,
|
key: string,
|
||||||
cb: (value: T | null) => void
|
cb: (value: T | null) => void
|
||||||
): Promise<UnlistenFn> {
|
): Promise<UnlistenFn> {
|
||||||
return await appWindow.listen<ChangePayload<T>>(
|
return await listen<ChangePayload<T>>("store://change", (event) => {
|
||||||
"store://change",
|
if (event.payload.path === this.path && event.payload.key === key) {
|
||||||
(event) => {
|
cb(event.payload.value);
|
||||||
if (event.payload.path === this.path && event.payload.key === key) {
|
|
||||||
cb(event.payload.value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -198,13 +194,10 @@ export class Store {
|
|||||||
async onChange<T>(
|
async onChange<T>(
|
||||||
cb: (key: string, value: T | null) => void
|
cb: (key: string, value: T | null) => void
|
||||||
): Promise<UnlistenFn> {
|
): Promise<UnlistenFn> {
|
||||||
return await appWindow.listen<ChangePayload<T>>(
|
return await listen<ChangePayload<T>>("store://change", (event) => {
|
||||||
"store://change",
|
if (event.payload.path === this.path) {
|
||||||
(event) => {
|
cb(event.payload.key, event.payload.value);
|
||||||
if (event.payload.path === this.path) {
|
|
||||||
cb(event.payload.key, event.payload.value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user