Skip to content

Commit 299764e

Browse files
committed
Refactor
1 parent 1a97d76 commit 299764e

1 file changed

Lines changed: 20 additions & 12 deletions

File tree

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161
let cacheProgress = $state(0);
6262
let cacheTotal = $state(0);
6363
let isExtracting = $state(false);
64-
let accentColor = $state('#89b4fa');
6564
let extractedPalette = $state<string[]>([]);
65+
let accentColor = $derived(extractedPalette[4] ?? '#89b4fa');
6666
let extractionGen = 0;
6767
let extractTimer: ReturnType<typeof setTimeout> | null = null;
6868
@@ -143,26 +143,38 @@
143143
isCaching = false;
144144
}
145145
146-
async function loadWallpapers() {
146+
async function loadWallpapers(): Promise<SlideItem[]> {
147147
const app = await getApp();
148148
const wps = await app.ScanLocalWallpapers();
149-
return wps.map((wp: any) => ({
149+
return wps.map(wp => ({
150150
path: wp.path,
151151
name: wp.name,
152152
imagePath: wp.path,
153153
}));
154154
}
155155
156-
async function loadThemes() {
156+
function pickPrimaryWallpaper(wallpapers: string[]): string {
157+
if (!wallpapers?.length) return '';
158+
for (const prefix of ['0-', '1-', '2-']) {
159+
const match = wallpapers.find(wp => {
160+
const name = wp.split('/').pop() ?? '';
161+
return name.startsWith(prefix);
162+
});
163+
if (match) return match;
164+
}
165+
return wallpapers[0];
166+
}
167+
168+
async function loadThemes(): Promise<SlideItem[]> {
157169
const app = await getApp();
158170
const themes = await app.LoadOmarchyThemes();
159171
if (!Array.isArray(themes)) return [];
160172
return themes
161-
.filter((t: any) => t.colors?.length >= 16)
162-
.map((t: any) => ({
173+
.filter(t => t.colors?.length >= 16)
174+
.map(t => ({
163175
path: t.path,
164176
name: t.name,
165-
imagePath: t.wallpapers?.[0] ?? '',
177+
imagePath: pickPrimaryWallpaper(t.wallpapers),
166178
colors: t.colors,
167179
}));
168180
}
@@ -219,13 +231,10 @@
219231
if (!item) return;
220232
221233
if (mode === 'themes' && item.colors) {
222-
// Themes already have colors - use them directly
223-
setPalette(item.colors);
234+
setPalette(item.colors, true);
224235
extractedPalette = [...item.colors];
225-
accentColor = item.colors[4];
226236
if (item.imagePath) setWallpaperPath(item.imagePath);
227237
} else {
228-
// Wallpapers need extraction
229238
extractForIndex(idx);
230239
}
231240
}
@@ -249,7 +258,6 @@
249258
setAdjustments({...DEFAULT_ADJUSTMENTS});
250259
setPalette(colors);
251260
extractedPalette = [...colors];
252-
accentColor = colors[4];
253261
} catch {
254262
if (gen === extractionGen) {
255263
showToast('Color extraction failed');

0 commit comments

Comments
 (0)