diff --git a/.vscode/settings.json b/.vscode/settings.json index 0a770118..0bd0fcd9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,7 @@ { - "editor.tabSize": 2 -} \ No newline at end of file + "editor.tabSize": 2, + "editor.insertSpaces": true, + "editor.codeActionsOnSave": { + "source.fixAll.eslint": true + } +} diff --git a/src/components/DynamicFavicon.tsx b/src/components/DynamicFavicon.tsx index 8a2af7eb..9e02c0f5 100644 --- a/src/components/DynamicFavicon.tsx +++ b/src/components/DynamicFavicon.tsx @@ -6,146 +6,146 @@ import { useAnyProjectBusy } from '@/hooks/useAnyProjectBusy'; * Rotates the favicon counter-clockwise when busy */ export function DynamicFavicon() { - const isBusy = useAnyProjectBusy(); - const canvasRef = useRef(null); - const animationRef = useRef(null); - const rotationRef = useRef(0); - const originalFaviconRef = useRef(null); - const originalImageRef = useRef(null); + const isBusy = useAnyProjectBusy(); + const canvasRef = useRef(null); + const animationRef = useRef(null); + const rotationRef = useRef(0); + const originalFaviconRef = useRef(null); + const originalImageRef = useRef(null); - // Initialize canvas and save original favicon - useEffect(() => { - // Create canvas element for drawing the favicon - if (!canvasRef.current) { - canvasRef.current = document.createElement('canvas'); - canvasRef.current.width = 32; - canvasRef.current.height = 32; - } + // Initialize canvas and save original favicon + useEffect(() => { + // Create canvas element for drawing the favicon + if (!canvasRef.current) { + canvasRef.current = document.createElement('canvas'); + canvasRef.current.width = 32; + canvasRef.current.height = 32; + } - // Store the original favicon URL - const faviconElement = document.querySelector('link[rel="icon"]'); - if (faviconElement && !originalFaviconRef.current) { - originalFaviconRef.current = faviconElement.getAttribute('href'); - } + // Store the original favicon URL + const faviconElement = document.querySelector('link[rel="icon"]'); + if (faviconElement && !originalFaviconRef.current) { + originalFaviconRef.current = faviconElement.getAttribute('href'); + } - // Preload the favicon image - if (!originalImageRef.current) { - const img = new Image(); - img.crossOrigin = 'anonymous'; - img.src = originalFaviconRef.current || '/shakespeare.png'; - img.onload = () => { - originalImageRef.current = img; - }; - } + // Preload the favicon image + if (!originalImageRef.current) { + const img = new Image(); + img.crossOrigin = 'anonymous'; + img.src = originalFaviconRef.current || '/shakespeare.png'; + img.onload = () => { + originalImageRef.current = img; + }; + } - return () => { - // Restore original favicon on unmount - if (originalFaviconRef.current) { - const faviconElement = document.querySelector('link[rel="icon"]'); - if (faviconElement) { - faviconElement.setAttribute('href', originalFaviconRef.current); - } - } + return () => { + // Restore original favicon on unmount + if (originalFaviconRef.current) { + const faviconElement = document.querySelector('link[rel="icon"]'); + if (faviconElement) { + faviconElement.setAttribute('href', originalFaviconRef.current); + } + } - // Cancel any ongoing animation - if (animationRef.current !== null) { - cancelAnimationFrame(animationRef.current); - } - }; - }, []); + // Cancel any ongoing animation + if (animationRef.current !== null) { + cancelAnimationFrame(animationRef.current); + } + }; + }, []); - // Handle busy state changes - useEffect(() => { - if (!canvasRef.current) return; + // Handle busy state changes + useEffect(() => { + if (!canvasRef.current) return; - // If busy, start rotation animation - if (isBusy) { - const startRotationAnimation = () => { - if (!canvasRef.current || !originalImageRef.current) { - // If image isn't loaded yet, try again in a moment - setTimeout(startRotationAnimation, 100); - return; - } + // If busy, start rotation animation + if (isBusy) { + const startRotationAnimation = () => { + if (!canvasRef.current || !originalImageRef.current) { + // If image isn't loaded yet, try again in a moment + setTimeout(startRotationAnimation, 100); + return; + } - const canvas = canvasRef.current; - const ctx = canvas.getContext('2d'); - if (!ctx) return; + const canvas = canvasRef.current; + const ctx = canvas.getContext('2d'); + if (!ctx) return; - const img = originalImageRef.current; + const img = originalImageRef.current; - const animate = () => { - if (!ctx || !canvas) return; + const animate = () => { + if (!ctx || !canvas) return; - // Clear canvas - ctx.clearRect(0, 0, canvas.width, canvas.height); + // Clear canvas + ctx.clearRect(0, 0, canvas.width, canvas.height); - // Save context state - ctx.save(); + // Save context state + ctx.save(); - // Translate to center for rotation - ctx.translate(canvas.width / 2, canvas.height / 2); + // Translate to center for rotation + ctx.translate(canvas.width / 2, canvas.height / 2); - // Rotate counter-clockwise - ctx.rotate(-rotationRef.current); + // Rotate counter-clockwise + ctx.rotate(-rotationRef.current); - // Draw the image centered - ctx.drawImage( - img, - -canvas.width / 2, - -canvas.height / 2, - canvas.width, - canvas.height - ); + // Draw the image centered + ctx.drawImage( + img, + -canvas.width / 2, + -canvas.height / 2, + canvas.width, + canvas.height + ); - // Restore context state - ctx.restore(); + // Restore context state + ctx.restore(); - // Update rotation for next frame (slower rotation) - rotationRef.current += 0.05; + // Update rotation for next frame (slower rotation) + rotationRef.current += 0.05; - // Update favicon - const faviconElement = document.querySelector('link[rel="icon"]'); - if (faviconElement) { - faviconElement.setAttribute('href', canvas.toDataURL('image/png')); - } + // Update favicon + const faviconElement = document.querySelector('link[rel="icon"]'); + if (faviconElement) { + faviconElement.setAttribute('href', canvas.toDataURL('image/png')); + } - // Continue animation - animationRef.current = requestAnimationFrame(animate); - }; + // Continue animation + animationRef.current = requestAnimationFrame(animate); + }; - // Start animation loop - animate(); - }; + // Start animation loop + animate(); + }; - startRotationAnimation(); - } else { - // If not busy, restore original favicon and stop animation - if (animationRef.current !== null) { - cancelAnimationFrame(animationRef.current); - animationRef.current = null; - } + startRotationAnimation(); + } else { + // If not busy, restore original favicon and stop animation + if (animationRef.current !== null) { + cancelAnimationFrame(animationRef.current); + animationRef.current = null; + } - // Reset rotation - rotationRef.current = 0; + // Reset rotation + rotationRef.current = 0; - // Restore original favicon - if (originalFaviconRef.current) { - const faviconElement = document.querySelector('link[rel="icon"]'); - if (faviconElement) { - faviconElement.setAttribute('href', originalFaviconRef.current); - } - } - } + // Restore original favicon + if (originalFaviconRef.current) { + const faviconElement = document.querySelector('link[rel="icon"]'); + if (faviconElement) { + faviconElement.setAttribute('href', originalFaviconRef.current); + } + } + } - return () => { - // Cancel animation on effect cleanup - if (animationRef.current !== null) { - cancelAnimationFrame(animationRef.current); - animationRef.current = null; - } - }; - }, [isBusy]); + return () => { + // Cancel animation on effect cleanup + if (animationRef.current !== null) { + cancelAnimationFrame(animationRef.current); + animationRef.current = null; + } + }; + }, [isBusy]); - // This component doesn't render anything visible - return null; + // This component doesn't render anything visible + return null; }