From 39adaef4c4c6394d54e3182fc396ee4f3094819b Mon Sep 17 00:00:00 2001 From: sam Date: Wed, 1 Oct 2025 18:50:34 +0700 Subject: [PATCH 1/4] while any project session is 'busy', keep the favicon spinning --- src/App.tsx | 16 ++-- src/components/DynamicFavicon.tsx | 151 ++++++++++++++++++++++++++++++ src/hooks/useAnyProjectBusy.ts | 35 +++++++ 3 files changed, 195 insertions(+), 7 deletions(-) create mode 100644 src/components/DynamicFavicon.tsx create mode 100644 src/hooks/useAnyProjectBusy.ts diff --git a/src/App.tsx b/src/App.tsx index 45b189bf..bd3cd3eb 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -19,6 +19,7 @@ import { FSProvider } from '@/components/FSProvider'; import { ConsoleErrorProvider } from '@/components/ConsoleErrorProvider'; import { LightningFSAdapter } from '@/lib/LightningFSAdapter'; import { cleanupTmpDirectory } from '@/lib/tmpCleanup'; +import { DynamicFavicon } from '@/components/DynamicFavicon'; import AppRouter from './AppRouter'; @@ -80,13 +81,14 @@ export function App() { - - - - - - - + + + + + + + + diff --git a/src/components/DynamicFavicon.tsx b/src/components/DynamicFavicon.tsx new file mode 100644 index 00000000..8a2af7eb --- /dev/null +++ b/src/components/DynamicFavicon.tsx @@ -0,0 +1,151 @@ +import { useEffect, useRef } from 'react'; +import { useAnyProjectBusy } from '@/hooks/useAnyProjectBusy'; + +/** + * Component that dynamically updates the favicon when any project is busy with AI + * 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); + + // 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'); + } + + // 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); + } + } + + // Cancel any ongoing animation + if (animationRef.current !== null) { + cancelAnimationFrame(animationRef.current); + } + }; + }, []); + + // 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; + } + + const canvas = canvasRef.current; + const ctx = canvas.getContext('2d'); + if (!ctx) return; + + const img = originalImageRef.current; + + const animate = () => { + if (!ctx || !canvas) return; + + // Clear canvas + ctx.clearRect(0, 0, canvas.width, canvas.height); + + // Save context state + ctx.save(); + + // Translate to center for rotation + ctx.translate(canvas.width / 2, canvas.height / 2); + + // Rotate counter-clockwise + ctx.rotate(-rotationRef.current); + + // Draw the image centered + ctx.drawImage( + img, + -canvas.width / 2, + -canvas.height / 2, + canvas.width, + canvas.height + ); + + // Restore context state + ctx.restore(); + + // 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')); + } + + // Continue animation + animationRef.current = requestAnimationFrame(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; + } + + // 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); + } + } + } + + 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; +} diff --git a/src/hooks/useAnyProjectBusy.ts b/src/hooks/useAnyProjectBusy.ts new file mode 100644 index 00000000..24b3aae6 --- /dev/null +++ b/src/hooks/useAnyProjectBusy.ts @@ -0,0 +1,35 @@ +import { useState, useEffect } from 'react'; +import { useSessionManager } from './useSessionManager'; + +/** + * Hook to check if any project has running AI sessions + * @returns {boolean} True if any project has a running AI session + */ +export function useAnyProjectBusy(): boolean { + const sessionManager = useSessionManager(); + const [anyProjectBusy, setAnyProjectBusy] = useState(false); + + useEffect(() => { + const updateStatus = () => { + const sessions = sessionManager.getAllSessions(); + const hasBusyProject = sessions.some(session => session.isLoading); + setAnyProjectBusy(hasBusyProject); + }; + + // Initial update + updateStatus(); + + // Subscribe to session changes + sessionManager.on('sessionCreated', updateStatus); + sessionManager.on('sessionDeleted', updateStatus); + sessionManager.on('loadingChanged', updateStatus); + + return () => { + sessionManager.off('sessionCreated', updateStatus); + sessionManager.off('sessionDeleted', updateStatus); + sessionManager.off('loadingChanged', updateStatus); + }; + }, [sessionManager]); + + return anyProjectBusy; +} From 7abb0ace5a9662aca79432ca93bd8789ed9ce2ba Mon Sep 17 00:00:00 2001 From: sam Date: Fri, 3 Oct 2025 12:42:13 +0700 Subject: [PATCH 2/4] define lint spec for spaces > tabs and complete vscode/cursor setup for auto linting lint drop over zealous rule --- .vscode/settings.json | 8 +- src/components/DynamicFavicon.tsx | 234 +++++++++++++++--------------- 2 files changed, 123 insertions(+), 119 deletions(-) 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; } From 3f5667d62a8d3045c7ad0b1deae8171d85229c55 Mon Sep 17 00:00:00 2001 From: sam Date: Fri, 3 Oct 2025 15:01:23 +0700 Subject: [PATCH 3/4] warn but don't fail on lint errors --- eslint.config.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/eslint.config.js b/eslint.config.js index 1e1fc7fd..b5b839f5 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -40,6 +40,8 @@ export default tseslint.config( "ignoreRestSiblings": true, }, ], + "indent": ["warn", 2], + "no-tabs": "warn", "custom/no-placeholder-comments": "error", "no-warning-comments": [ "error", From b419f88571c5bc9921288f8a72dfaf7faec19718 Mon Sep 17 00:00:00 2001 From: sam Date: Fri, 3 Oct 2025 15:01:30 +0700 Subject: [PATCH 4/4] lint --- src/hooks/useAnyProjectBusy.ts | 42 +++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/hooks/useAnyProjectBusy.ts b/src/hooks/useAnyProjectBusy.ts index 24b3aae6..1ff33004 100644 --- a/src/hooks/useAnyProjectBusy.ts +++ b/src/hooks/useAnyProjectBusy.ts @@ -6,30 +6,30 @@ import { useSessionManager } from './useSessionManager'; * @returns {boolean} True if any project has a running AI session */ export function useAnyProjectBusy(): boolean { - const sessionManager = useSessionManager(); - const [anyProjectBusy, setAnyProjectBusy] = useState(false); + const sessionManager = useSessionManager(); + const [anyProjectBusy, setAnyProjectBusy] = useState(false); - useEffect(() => { - const updateStatus = () => { - const sessions = sessionManager.getAllSessions(); - const hasBusyProject = sessions.some(session => session.isLoading); - setAnyProjectBusy(hasBusyProject); - }; + useEffect(() => { + const updateStatus = () => { + const sessions = sessionManager.getAllSessions(); + const hasBusyProject = sessions.some(session => session.isLoading); + setAnyProjectBusy(hasBusyProject); + }; - // Initial update - updateStatus(); + // Initial update + updateStatus(); - // Subscribe to session changes - sessionManager.on('sessionCreated', updateStatus); - sessionManager.on('sessionDeleted', updateStatus); - sessionManager.on('loadingChanged', updateStatus); + // Subscribe to session changes + sessionManager.on('sessionCreated', updateStatus); + sessionManager.on('sessionDeleted', updateStatus); + sessionManager.on('loadingChanged', updateStatus); - return () => { - sessionManager.off('sessionCreated', updateStatus); - sessionManager.off('sessionDeleted', updateStatus); - sessionManager.off('loadingChanged', updateStatus); - }; - }, [sessionManager]); + return () => { + sessionManager.off('sessionCreated', updateStatus); + sessionManager.off('sessionDeleted', updateStatus); + sessionManager.off('loadingChanged', updateStatus); + }; + }, [sessionManager]); - return anyProjectBusy; + return anyProjectBusy; }