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