From cbf41c0e495367bb3f582ea22aabdc03bd2d046d Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Thu, 9 Apr 2026 20:09:47 +0900 Subject: show caching progress --- src/App.svelte | 22 ++++++++++++++++++++-- src/lib/cache/autoCacheService.ts | 15 +++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index 7d99875..03cd5c1 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -13,6 +13,21 @@ let isDark = $state(false); let deleting = $state(false); let showDeleteConfirm = $state(false); + let isAutoCaching = $state(false); + let cachedCount = $state(0); + let totalCount = $state(0); + + $effect(() => { + const unsubscribe = autoCacheService.subscribe(() => { + isAutoCaching = autoCacheService.isActive; + cachedCount = autoCacheService.cachedCount; + totalCount = autoCacheService.totalCount; + }); + isAutoCaching = autoCacheService.isActive; + cachedCount = autoCacheService.cachedCount; + totalCount = autoCacheService.totalCount; + return unsubscribe; + }); $effect(() => { document.documentElement.setAttribute('data-theme', isDark ? 'black' : 'cmyk'); @@ -118,8 +133,11 @@
-
- Photos ({images.length}) +
+ Photos {cachedCount}/{totalCount > 0 ? totalCount : images.length} + {#if isAutoCaching} + + {/if}
diff --git a/src/lib/cache/autoCacheService.ts b/src/lib/cache/autoCacheService.ts index 04dc92b..e5a6584 100644 --- a/src/lib/cache/autoCacheService.ts +++ b/src/lib/cache/autoCacheService.ts @@ -76,6 +76,21 @@ class AutoCacheService { return this._progressMap.get(path); } + /** Whether the service is actively caching (running and not finished). */ + get isActive(): boolean { + return this._running && (this._downloading || this._nextIndex < this._images.length); + } + + /** Number of images confirmed cached so far. */ + get cachedCount(): number { + return this._cachedPaths.size; + } + + /** Total number of images in the work queue. */ + get totalCount(): number { + return this._images.length; + } + /** Check if a path has been confirmed fully cached. */ isCached(path: string): boolean { return this._cachedPaths.has(path); -- cgit v1.2.3