| 1 | import { useEffect, useRef } from 'react' |
| 2 | import { ipc, type HtmlThumbnailTask } from '@renderer/lib/ipc' |
| 3 | import type { HtmlThumbnailResourceType } from '@shared/thumbnail' |
| 4 | |
| 5 | export function useThumbnailUpdates( |
| 6 | resourceType: HtmlThumbnailResourceType, |
| 7 | onCompleted: (task: HtmlThumbnailTask) => void |
| 8 | ): void { |
| 9 | const onCompletedRef = useRef(onCompleted) |
| 10 | onCompletedRef.current = onCompleted |
| 11 | |
| 12 | useEffect(() => { |
| 13 | const unsubscribe = ipc.onHtmlThumbnailChanged((task) => { |
| 14 | if (task.resourceType !== resourceType || task.status !== 'completed') return |
| 15 | onCompletedRef.current(task) |
| 16 | }) |
| 17 | return unsubscribe |
| 18 | }, [resourceType]) |
| 19 | } |
| 20 |