mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-29 02:00:31 +08:00
Add ability to listen to node events from the frontend
This commit is contained in:
@@ -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 () => {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user