MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / startWatchingCustomThemes

Function startWatchingCustomThemes

apps/desktop/src/main/custom-themes.ts:384–406  ·  view source on GitHub ↗
(onChange: (themes: CustomTheme[]) => void)

Source from the content-addressed store, hash-verified

382/** Watch the themes dir (incl. one level into each theme folder) and call
383 * `onChange` (debounced) with the fresh list. */
384export 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. */

Callers 1

index.tsFile · 0.90

Calls 3

getCustomThemesDirFunction · 0.85
closeMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected