(onChange: (themes: CustomTheme[]) => void)
| 382 | /** Watch the themes dir (incl. one level into each theme folder) and call |
| 383 | * `onChange` (debounced) with the fresh list. */ |
| 384 | export function startWatchingCustomThemes(onChange: (themes: CustomTheme[]) => void): void { |
| 385 | const dir = getCustomThemesDir() |
| 386 | void watcher?.close() |
| 387 | let timer: ReturnType<typeof setTimeout> | null = null |
| 388 | const fire = (): void => { |
| 389 | if (timer) clearTimeout(timer) |
| 390 | timer = setTimeout(() => { |
| 391 | timer = null |
| 392 | void listCustomThemes().then(onChange) |
| 393 | }, 200) |
| 394 | } |
| 395 | const w = chokidar.watch(dir, { |
| 396 | ignoreInitial: true, |
| 397 | depth: 1, |
| 398 | awaitWriteFinish: { stabilityThreshold: 200, pollInterval: 50 } |
| 399 | }) |
| 400 | watcher = w |
| 401 | w.on('add', fire) |
| 402 | .on('change', fire) |
| 403 | .on('unlink', fire) |
| 404 | .on('addDir', fire) |
| 405 | .on('unlinkDir', fire) |
| 406 | } |
| 407 | |
| 408 | /** What to reveal in the file manager: a theme's `theme.css` when the slug is |
| 409 | * valid and exists, otherwise its folder, otherwise the themes dir. */ |
no test coverage detected