fix(store): Use event module instead of appWindow, fixes #282 (#283)

* fix(store): Use event module instead of appWindow, fixes #282

* fmt
pull/286/head
Fabian-Lars 2 years ago committed by GitHub
parent a4dfa62486
commit 9b70a79b2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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);
}
);
});
}
}

Loading…
Cancel
Save