Files
shakespeare/ELECTRON_CLEANUP.md
T
Alex Gleason 08df445cae Clean up Electron branch: remove unnecessary changes
- Remove tsconfig.json modification (use triple-slash references instead)
- Remove Vite-specific ?url imports (base: './' handles assets correctly)
- Add triple-slash reference directives to files using window.electron
- Add cleanup documentation

This keeps source changes minimal while maintaining full Electron functionality.
2025-10-24 18:40:50 -05:00

4.2 KiB

Electron Branch Cleanup Summary

This document summarizes the cleanup performed on the electron branch before merging to main.

Changes Reverted (Unnecessary)

1. ❌ tsconfig.json - Removed Electron types from include array

Before:

"include": ["src", "electron/electron.d.ts"]

After:

"include": ["src"]

Reason: TypeScript can find the types via triple-slash reference directives (/// <reference path="..." />) in files that use window.electron. This is the standard approach and doesn't pollute the global tsconfig.

2. ❌ src/components/ShakespeareLogo.tsx - Removed Vite-specific ?url import

3. ❌ src/components/AppShowcaseCard.tsx - Removed Vite-specific ?url import

Before:

import shakespeareLogo from '/shakespeare.svg?url';

export function ShakespeareLogo({ className }: ShakespeareLogoProps) {
  return (
    <img
      src={shakespeareLogo}
      alt="Shakespeare"
      className={className}
    />
  );
}

After:

export function ShakespeareLogo({ className }: ShakespeareLogoProps) {
  return (
    <img
      src="/shakespeare.svg"
      alt="Shakespeare"
      className={className}
    />
  );
}

Reason: With base: './' in vite.config.ts, Vite correctly handles public assets for both browser and Electron. The ?url parameter was unnecessary and made the code Vite-specific. The files are already in public/ and get copied to dist/ during build.

Same fix applied to:

  • src/components/AppShowcaseCard.tsx - Changed badgeSvg import to direct path /badge.svg

Changes Added (For Type Safety)

Triple-Slash Reference Directives

Added /// <reference path="..." /> to files that use window.electron:

  1. src/App.tsx - Uses window.electron?.isElectron for FS adapter selection
  2. src/AppRouter.tsx - Uses window.electron?.isElectron for router selection
  3. src/main.tsx - Uses window.electron?.isElectron for service worker check
  4. src/lib/ElectronFSAdapter.ts - Uses window.electron API
  5. src/lib/tools/ShellTool.ts - Uses window.electron?.shell
  6. src/components/Terminal.tsx - Uses window.electron?.shell

This provides type safety without modifying tsconfig.json.

Changes Kept (Essential for Electron)

Core Electron Files

  • electron/ directory - All Electron-specific code (main.js, preload.js, builder config, docs)

Source File Modifications

  1. src/App.tsx - Conditional FS adapter (LightningFS vs Electron)
  2. src/AppRouter.tsx - Conditional router (BrowserRouter vs HashRouter)
  3. src/main.tsx - Skip service worker in Electron
  4. src/lib/ElectronFSAdapter.ts - Electron filesystem adapter (NEW)
  5. src/lib/tools/ShellTool.ts - Real OS shell support in Electron, added projectsPath param for path conversion
  6. src/components/Terminal.tsx - Electron shell integration
  7. src/components/Shakespeare/ChatPane.tsx - Pass projectsPath to ShellTool
  8. src/hooks/useProjectDeploySettings.ts - Handle null projectId gracefully
  9. src/lib/ansiToHtml.ts - Enhanced ANSI code stripping (used by ShellTool)
  10. src/lib/ansiToHtml.test.ts - Tests for ANSI code stripping (NEW)

Build Configuration

  1. vite.config.ts - Added base: './' for relative paths (required for file:// protocol)
  2. index.html - Updated CSP font-src to include data: for base64 fonts
  3. package.json - Electron scripts and dependencies

Documentation

  • .gitignore - Electron build outputs
  • README.md - Electron documentation section
  • AGENTS.md - Electron development guidelines

Result

The branch is now clean with minimal source changes:

  • ✅ No unnecessary modifications to core files
  • ✅ Proper TypeScript type safety via triple-slash references
  • ✅ Logo works correctly in both browser and Electron
  • ✅ All essential Electron functionality preserved
  • ✅ Code compiles and builds successfully

Testing Checklist

Before merging to main:

  • TypeScript compilation passes
  • Build succeeds
  • Logo displays in browser mode
  • Logo displays in Electron mode
  • Electron app builds successfully (npm run electron:build)
  • Electron app runs in dev mode (npm run electron:dev)