Add ability to listen to node events from the frontend

This commit is contained in:
Sebastian Martinez
2024-09-18 12:25:28 +02:00
parent 797a64b8d7
commit ff6b7aa5dc
7 changed files with 95 additions and 1 deletions
+12
View File
@@ -2,9 +2,11 @@
import { onMount } from "svelte";
import { invoke } from "@tauri-apps/api/core";
import { listen } from "@tauri-apps/api/event";
import * as router from "@app/lib/router";
import { theme } from "@app/components/ThemeSwitch.svelte";
import { subscribeToNodeEvents } from "@app/lib/events";
import { unreachable } from "@app/lib/utils";
import AuthenticationError from "@app/views/AuthenticationError.svelte";
@@ -12,6 +14,16 @@
import Issues from "@app/views/repo/Issues.svelte";
import Patches from "@app/views/repo/Patches.svelte";
subscribeToNodeEvents();
void listen("event", event => {
console.log(event.payload);
});
void listen("node_status", event => {
console.log(`Node: ${event.payload}`);
});
const activeRouteStore = router.activeRouteStore;
onMount(async () => {
+12
View File
@@ -0,0 +1,12 @@
import { emit } from "@tauri-apps/api/event";
let interval: ReturnType<typeof setInterval> | undefined = undefined;
export function subscribeToNodeEvents() {
if (interval === undefined) {
interval = setInterval(() => {
// In case there is a running subscription this won't launch a new one.
void emit("subscribe_events");
}, 10_000);
}
}