diff --git a/src/lib/components/PreferencesPanel.svelte b/src/lib/components/PreferencesPanel.svelte index a088463..4e8ef6b 100644 --- a/src/lib/components/PreferencesPanel.svelte +++ b/src/lib/components/PreferencesPanel.svelte @@ -6,6 +6,8 @@ setCookieSource, type CookieSource, } from '$lib/stores/preferences.svelte'; + import { getCacheStats, clearAllCache } from '$lib/bindings/cache'; + import type { CacheStats } from '$lib/bindings/cache'; let { onClose }: { onClose: () => void } = $props(); @@ -13,6 +15,34 @@ let cookieFilePath = $state( preferences.cookieSource.type === 'file' ? preferences.cookieSource.path : '' ); + let cacheStats = $state(null); + let clearingCache = $state(false); + + $effect(() => { + getCacheStats().then((stats) => { + cacheStats = stats; + }); + }); + + function formatBytes(bytes: number): string { + if (bytes === 0) return '0 B'; + const units = ['B', 'KB', 'MB', 'GB']; + const i = Math.floor(Math.log(bytes) / Math.log(1024)); + const val = bytes / Math.pow(1024, i); + return `${val.toFixed(i > 0 ? 1 : 0)} ${units[i]}`; + } + + async function handleClearAllCache() { + clearingCache = true; + try { + await clearAllCache(); + cacheStats = { entryCount: 0, totalBytes: 0 }; + } catch (err) { + console.error('Failed to clear cache:', err); + } finally { + clearingCache = false; + } + } async function pickOutputDirectory() { const selected = await open({ @@ -128,6 +158,23 @@ +
+

Cache

+ {#if cacheStats} +

+ {formatBytes(cacheStats.totalBytes)} used across {cacheStats.entryCount} video{cacheStats.entryCount === 1 ? '' : 's'} +

+ {:else} +

Loading…

+ {/if} + +
+
@@ -207,6 +254,12 @@ margin-left: 20px; } + .cache-info { + font-size: 13px; + color: var(--text-secondary); + margin-bottom: 8px; + } + .actions { display: flex; justify-content: flex-end;