Files
shakespeare/ELECTRON_CLEANUP.md
T

5.3 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 - Fixed asset import (removed ?url, kept import)

3. ✅ src/components/AppShowcaseCard.tsx - Fixed asset import (removed ?url, kept import)

Initial (broken):

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

Attempted fix (still broken):

<img src="/shakespeare.svg" />  // Breaks in Electron - absolute path

Final solution:

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

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

Reason:

  • The ?url suffix was unnecessary (Vite handles SVG imports without it)
  • But we do need imports - absolute paths like /shakespeare.svg don't work in Electron's file:// protocol
  • Importing assets lets Vite transform paths at build time with base: './'
  • Works in both browser (https://...) and Electron (file://...)

Same fix applied to:

  • src/components/AppShowcaseCard.tsx - import badgeSvg from '/badge.svg'

See PUBLIC_ASSETS_EXPLANATION.md for detailed explanation.

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

Documentation Cleanup

Removed development/debugging artifacts from electron/ directory (1,401 lines):

  • ❌ .electron-build-summary.md - AI build summary
  • ❌ BUGFIX-ERROR-CODES.md - Specific bug fix notes
  • ❌ COMPLETE_FIX_SUMMARY.md - More bug fix notes
  • ❌ ERROR-CODE-FLOW.md - Debug diagrams
  • ❌ CHANGELOG.md - Development changelog
  • ❌ INDEX.md - Just listed other docs
  • ❌ ARCHITECTURE.md - Internal implementation details (456 lines)

Kept essential user/developer documentation (1,750 lines):

  • ✅ README.md - Main technical reference
  • ✅ QUICKSTART.md - Build/run instructions
  • ✅ QUICKSTART_FILESYSTEM.md - Quick filesystem guide
  • ✅ FEATURES.md - Feature overview
  • ✅ FILESYSTEM.md - Detailed filesystem docs
  • ✅ REAL_TERMINAL.md - Terminal details
  • ✅ INTEGRATION.md - Developer integration guide
  • ✅ TROUBLESHOOTING.md - User troubleshooting

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)