From 49d50220272d87c34cd84678baf01557d4c24051 Mon Sep 17 00:00:00 2001 From: Romein van Buren Date: Sat, 1 Jul 2023 15:08:00 +0200 Subject: [PATCH] Implement logs autoreload --- .../src/organisms/connection/host/logs.svelte | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/frontend/src/organisms/connection/host/logs.svelte b/frontend/src/organisms/connection/host/logs.svelte index e5ee5bf..802b500 100644 --- a/frontend/src/organisms/connection/host/logs.svelte +++ b/frontend/src/organisms/connection/host/logs.svelte @@ -4,6 +4,7 @@ import ObjectViewer from '$components/objectviewer.svelte'; import input from '$lib/actions/input'; import { BrowserOpenURL } from '$wails/runtime/runtime'; + import { onDestroy } from 'svelte'; export let host; @@ -15,9 +16,17 @@ let copySucceeded = false; let autoReloadInterval = 0; let objectViewerData; + let interval; $: filter && refresh(); $: busy = !logs && !error && 'Requesting logsā€¦'; + $: if (autoReloadInterval) { + if (interval) { + clearInterval(interval); + } + interval = setInterval(refresh, autoReloadInterval * 1000); + } + async function refresh() { let _logs = []; ({ logs: _logs, total, error } = await host.getLogs(filter)); @@ -44,6 +53,12 @@ copySucceeded = true; setTimeout(() => copySucceeded = false, 1500); } + + onDestroy(() => { + if (interval) { + clearInterval(interval); + } + });