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:
Sebastian Martinez
2025-02-10 11:55:14 -06:00
committed by Rūdolfs Ošiņš
parent 53d49e0bbf
commit 365674bc58
7 changed files with 136 additions and 3 deletions
+14 -1
View File
@@ -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();
}
+6
View File
@@ -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(),
);