mirror of
https://seed.radicle.dev/rad:z4D5UCArafTzTQpDZNQRuqswh3ury.git
synced 2026-11-02 01:50:29 +08:00
Provide a sync_status store
The `sync_status` would update every 10 seconds with the latest state of all repos, to be displayed in the repo where needed.
This commit is contained in:
+14
-1
@@ -1,13 +1,15 @@
|
||||
<script lang="ts">
|
||||
import type { UnlistenFn } from "@tauri-apps/api/event";
|
||||
import type { SyncStatus } from "@bindings/repo/SyncStatus";
|
||||
|
||||
import { SvelteMap } from "svelte/reactivity";
|
||||
import { onDestroy, onMount } from "svelte";
|
||||
|
||||
import { invoke } from "@app/lib/invoke";
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
|
||||
import * as router from "@app/lib/router";
|
||||
import { nodeRunning } from "@app/lib/events";
|
||||
import { nodeRunning, syncStatus } from "@app/lib/events";
|
||||
import { theme } from "@app/components/ThemeSwitch.svelte";
|
||||
import { unreachable } from "@app/lib/utils";
|
||||
|
||||
@@ -25,6 +27,7 @@
|
||||
|
||||
let unlistenEvents: UnlistenFn | undefined = undefined;
|
||||
let unlistenNodeEvents: UnlistenFn | undefined = undefined;
|
||||
let unlistenSyncStatus: UnlistenFn | undefined = undefined;
|
||||
|
||||
onMount(async () => {
|
||||
if (window.__TAURI_INTERNALS__) {
|
||||
@@ -32,6 +35,13 @@
|
||||
// Add handler for incoming events
|
||||
});
|
||||
|
||||
unlistenSyncStatus = await listen<Record<string, SyncStatus>>(
|
||||
"sync_status",
|
||||
event => {
|
||||
syncStatus.set(new SvelteMap(Object.entries(event.payload)));
|
||||
},
|
||||
);
|
||||
|
||||
unlistenNodeEvents = await listen<boolean>("node_running", event => {
|
||||
nodeRunning.set(event.payload);
|
||||
});
|
||||
@@ -61,6 +71,9 @@
|
||||
if (unlistenEvents) {
|
||||
unlistenEvents();
|
||||
}
|
||||
if (unlistenSyncStatus) {
|
||||
unlistenSyncStatus();
|
||||
}
|
||||
if (unlistenNodeEvents) {
|
||||
unlistenNodeEvents();
|
||||
}
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
import type { SyncStatus } from "@bindings/repo/SyncStatus";
|
||||
|
||||
import { SvelteMap } from "svelte/reactivity";
|
||||
import { writable } from "svelte/store";
|
||||
|
||||
export const nodeRunning = writable<boolean>(false);
|
||||
export const syncStatus = writable<SvelteMap<string, SyncStatus>>(
|
||||
new SvelteMap(),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user