|
61 | 61 | let cacheProgress = $state(0); |
62 | 62 | let cacheTotal = $state(0); |
63 | 63 | let isExtracting = $state(false); |
64 | | - let accentColor = $state('#89b4fa'); |
65 | 64 | let extractedPalette = $state<string[]>([]); |
| 65 | + let accentColor = $derived(extractedPalette[4] ?? '#89b4fa'); |
66 | 66 | let extractionGen = 0; |
67 | 67 | let extractTimer: ReturnType<typeof setTimeout> | null = null; |
68 | 68 |
|
|
143 | 143 | isCaching = false; |
144 | 144 | } |
145 | 145 |
|
146 | | - async function loadWallpapers() { |
| 146 | + async function loadWallpapers(): Promise<SlideItem[]> { |
147 | 147 | const app = await getApp(); |
148 | 148 | const wps = await app.ScanLocalWallpapers(); |
149 | | - return wps.map((wp: any) => ({ |
| 149 | + return wps.map(wp => ({ |
150 | 150 | path: wp.path, |
151 | 151 | name: wp.name, |
152 | 152 | imagePath: wp.path, |
153 | 153 | })); |
154 | 154 | } |
155 | 155 |
|
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[]> { |
157 | 169 | const app = await getApp(); |
158 | 170 | const themes = await app.LoadOmarchyThemes(); |
159 | 171 | if (!Array.isArray(themes)) return []; |
160 | 172 | return themes |
161 | | - .filter((t: any) => t.colors?.length >= 16) |
162 | | - .map((t: any) => ({ |
| 173 | + .filter(t => t.colors?.length >= 16) |
| 174 | + .map(t => ({ |
163 | 175 | path: t.path, |
164 | 176 | name: t.name, |
165 | | - imagePath: t.wallpapers?.[0] ?? '', |
| 177 | + imagePath: pickPrimaryWallpaper(t.wallpapers), |
166 | 178 | colors: t.colors, |
167 | 179 | })); |
168 | 180 | } |
|
219 | 231 | if (!item) return; |
220 | 232 |
|
221 | 233 | if (mode === 'themes' && item.colors) { |
222 | | - // Themes already have colors - use them directly |
223 | | - setPalette(item.colors); |
| 234 | + setPalette(item.colors, true); |
224 | 235 | extractedPalette = [...item.colors]; |
225 | | - accentColor = item.colors[4]; |
226 | 236 | if (item.imagePath) setWallpaperPath(item.imagePath); |
227 | 237 | } else { |
228 | | - // Wallpapers need extraction |
229 | 238 | extractForIndex(idx); |
230 | 239 | } |
231 | 240 | } |
|
249 | 258 | setAdjustments({...DEFAULT_ADJUSTMENTS}); |
250 | 259 | setPalette(colors); |
251 | 260 | extractedPalette = [...colors]; |
252 | | - accentColor = colors[4]; |
253 | 261 | } catch { |
254 | 262 | if (gen === extractionGen) { |
255 | 263 | showToast('Color extraction failed'); |
|
0 commit comments