Skip to content

Commit 64ca9c7

Browse files
committed
Make it more snappy
1 parent affed82 commit 64ca9c7

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

frontend/src/lib/components/slider/WallpaperSlider.svelte

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
2020
let previewDataUrls = $state<Record<string, string>>({});
2121
let previewPending = new Set<string>();
22+
let previewTick = $state(0);
2223
2324
async function loadPreview(path: string) {
2425
if (previewDataUrls[path] || previewPending.has(path)) return;
@@ -27,11 +28,17 @@
2728
const app = await getApp();
2829
const previewPath = await app.GetPreview(path);
2930
const dataUrl = await app.ReadImageAsDataURL(previewPath);
30-
previewDataUrls = {...previewDataUrls, [path]: dataUrl};
31+
previewDataUrls[path] = dataUrl;
32+
previewTick++;
3133
} catch {}
3234
previewPending.delete(path);
3335
}
3436
37+
function hasPreview(path: string): string | undefined {
38+
void previewTick;
39+
return previewDataUrls[path];
40+
}
41+
3542
let _appModule: Awaited<
3643
typeof import('../../../../wailsjs/go/main/App')
3744
> | null = null;
@@ -122,7 +129,7 @@
122129
123130
if (uncached.length === 0) return;
124131
125-
const CONCURRENCY = 4;
132+
const CONCURRENCY = 8;
126133
cacheTotal = uncached.length;
127134
cacheProgress = 0;
128135
isCaching = true;
@@ -502,6 +509,7 @@
502509
: CARD_MAX_HEIGHT}px;
503510
transform: skewX(-{SKEW}deg);
504511
opacity: {slideOpacity(i)};
512+
contain: layout style paint;
505513
transition: width 0.2s ease, height 0.2s ease, opacity 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
506514
border-color: {i === currentIndex
507515
? accentColor
@@ -515,9 +523,9 @@
515523
aria-selected={i === currentIndex}
516524
onclick={() => goTo(i)}
517525
>
518-
{#if item.imagePath && previewDataUrls[item.imagePath]}
526+
{#if item.imagePath && hasPreview(item.imagePath)}
519527
<img
520-
src={previewDataUrls[item.imagePath]}
528+
src={hasPreview(item.imagePath)}
521529
alt={item.name}
522530
class="pointer-events-none h-full w-full object-cover"
523531
style="transform: skewX({SKEW}deg) scale(1.15)"

0 commit comments

Comments
 (0)