From 16a5a79ddb971873f2164a0a291c75455007f21d Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 25 Oct 2025 00:16:38 -0500 Subject: [PATCH] Condense electron md files --- electron/FILESYSTEM.md | 153 ---------- electron/GUIDE.md | 582 ++++++++++++++++++++++++++++++++++++ electron/QUICKSTART.md | 141 --------- electron/README.md | 297 +++++++++--------- electron/REAL_TERMINAL.md | 214 ------------- electron/TROUBLESHOOTING.md | 399 ------------------------ 6 files changed, 740 insertions(+), 1046 deletions(-) delete mode 100644 electron/FILESYSTEM.md create mode 100644 electron/GUIDE.md delete mode 100644 electron/QUICKSTART.md delete mode 100644 electron/REAL_TERMINAL.md delete mode 100644 electron/TROUBLESHOOTING.md diff --git a/electron/FILESYSTEM.md b/electron/FILESYSTEM.md deleted file mode 100644 index 7562dda9..00000000 --- a/electron/FILESYSTEM.md +++ /dev/null @@ -1,153 +0,0 @@ -# Electron Filesystem Configuration - -## Overview - -When running Shakespeare as an Electron desktop app, the filesystem is configured to use your local OS filesystem at `~/shakespeare` instead of the browser's IndexedDB-backed virtual filesystem. - -## Filesystem Root - -- **Location**: `~/shakespeare` (expands to your home directory) - - macOS/Linux: `/Users/username/shakespeare` or `/home/username/shakespeare` - - Windows: `C:\Users\username\shakespeare` - -- **Automatic Creation**: The directory is automatically created when the Electron app starts if it doesn't exist - -## How It Works - -### Architecture - -1. **Browser Mode**: Uses `LightningFSAdapter` with IndexedDB storage -2. **Electron Mode**: Uses `NodeFSAdapter` with Node.js `fs` module - -The filesystem adapter is selected automatically in `src/App.tsx`: - -```typescript -const fs = window.electron?.isElectron - ? new NodeFSAdapter() - : new LightningFSAdapter(new LightningFS('shakespeare-fs').promises); -``` - -### Path Resolution - -All paths used within Shakespeare are relative to the filesystem root: - -- `/projects/my-app/` → `~/shakespeare/projects/my-app/` -- `/tmp/upload.txt` → `~/shakespeare/tmp/upload.txt` -- `/config/ai.json` → `~/shakespeare/config/ai.json` - -The path resolution happens in `electron/main.js` via the `resolvePath()` function, which: -1. Normalizes the path -2. Removes leading slashes -3. Joins with `SHAKESPEARE_ROOT` - -### IPC Communication - -Filesystem operations are handled via Electron IPC: - -1. **Renderer Process** (`src/lib/NodeFSAdapter.ts`): - - Calls `window.electron.fs.*` methods - - Converts data types for IPC serialization (Uint8Array ↔ Array) - -2. **Preload Script** (`electron/preload.js`): - - Exposes filesystem API to renderer via `contextBridge` - - Provides type-safe interface - -3. **Main Process** (`electron/main.js`): - - Handles IPC calls with `ipcMain.handle()` - - Performs actual filesystem operations using Node.js `fs/promises` - - Ensures parent directories exist for write operations - -## Supported Operations - -All standard filesystem operations are supported: - -- **File Operations**: `readFile`, `writeFile`, `unlink`, `rename` -- **Directory Operations**: `readdir`, `mkdir`, `rmdir` -- **Metadata**: `stat`, `lstat` -- **Symlinks**: `readlink`, `symlink` - -## Benefits - -### Advantages of Local Filesystem - -1. **No Storage Limits**: Unlike IndexedDB, your filesystem is only limited by disk space -2. **Direct File Access**: Use your favorite code editor, file manager, or command-line tools -3. **Version Control**: Easy to use Git clients outside of Shakespeare -4. **Backup/Sync**: Use standard backup tools or cloud sync (Dropbox, iCloud, etc.) -5. **Performance**: Faster for large projects and files - -### Data Portability - -Your projects are stored in a standard directory structure: - -``` -~/shakespeare/ -├── projects/ -│ ├── my-react-app/ -│ │ ├── package.json -│ │ ├── src/ -│ │ └── ... -│ └── another-project/ -│ └── ... -├── config/ -│ ├── ai.json -│ └── git.json -└── tmp/ - └── ... -``` - -You can: -- Copy projects between machines -- Share projects with others -- Use external tools to work on projects -- Migrate to/from browser version by copying files - -## Security - -- **Sandboxed Access**: Only the `~/shakespeare` directory is accessible -- **Path Validation**: All paths are normalized and validated -- **IPC Security**: Context isolation enabled, no direct Node.js access from renderer - -## Troubleshooting - -### Directory Permissions - -If you encounter permission errors, ensure your user has read/write access to `~/shakespeare`: - -```bash -# Check permissions -ls -la ~/shakespeare - -# Fix permissions if needed -chmod -R u+rw ~/shakespeare -``` - -### Finding Your Files - -To open the Shakespeare directory in your file manager: - -- **macOS**: `open ~/shakespeare` -- **Linux**: `xdg-open ~/shakespeare` or `nautilus ~/shakespeare` -- **Windows**: `explorer %USERPROFILE%\shakespeare` - -### Switching Between Browser and Electron - -The browser and Electron versions use different storage: - -- **Browser**: IndexedDB (not directly accessible) -- **Electron**: `~/shakespeare` directory - -To migrate projects: -1. Export from browser as ZIP -2. Import ZIP in Electron version - -Or vice versa. - -## Development - -When running in development mode (`npm run electron:dev`): - -- Filesystem still uses `~/shakespeare` -- DevTools are automatically opened -- Hot reload works via Vite dev server -- Same filesystem behavior as production build diff --git a/electron/GUIDE.md b/electron/GUIDE.md new file mode 100644 index 00000000..f1b35efc --- /dev/null +++ b/electron/GUIDE.md @@ -0,0 +1,582 @@ +# Shakespeare Electron - Complete Guide + +This guide provides comprehensive documentation for developing, building, and troubleshooting the Shakespeare Electron desktop application. + +## Table of Contents + +1. [Filesystem Architecture](#filesystem-architecture) +2. [Terminal Integration](#terminal-integration) +3. [Development Workflow](#development-workflow) +4. [Building for Distribution](#building-for-distribution) +5. [Troubleshooting](#troubleshooting) + +--- + +## Filesystem Architecture + +### Overview + +The Electron version uses your local OS filesystem at `~/shakespeare` instead of IndexedDB, providing direct file access and unlimited storage. + +### Path Resolution + +All paths are relative to `~/shakespeare`: +- `/projects/my-app/` → `~/shakespeare/projects/my-app/` +- `/tmp/upload.txt` → `~/shakespeare/tmp/upload.txt` +- `/config/ai.json` → `~/shakespeare/config/ai.json` + +### Implementation + +**Automatic Adapter Selection** (`src/App.tsx`): +```typescript +const fs = window.electron?.isElectron + ? new NodeFSAdapter() // Real filesystem + : new LightningFSAdapter(new LightningFS('shakespeare-fs').promises); +``` + +**IPC Communication Flow:** +1. **Renderer** (`NodeFSAdapter.ts`) - Calls `window.electron.fs.*` methods +2. **Preload** (`preload.js`) - Exposes API via `contextBridge` +3. **Main** (`main.js`) - Handles IPC with `ipcMain.handle()`, performs filesystem operations + +### Supported Operations + +All standard filesystem operations are supported: +- **Files**: `readFile`, `writeFile`, `unlink`, `rename` +- **Directories**: `readdir`, `mkdir`, `rmdir` +- **Metadata**: `stat`, `lstat` +- **Symlinks**: `readlink`, `symlink` + +### Benefits + +✅ **No storage limits** - Only limited by disk space +✅ **Direct access** - Use any editor, file manager, or Git client +✅ **Easy backup** - Standard backup tools work +✅ **Better performance** - Faster for large projects +✅ **Data portability** - Copy projects between machines + +### Data Migration + +**Browser to Electron:** +1. Export project as ZIP from browser +2. Import ZIP in Electron version + +**Electron to Browser:** +1. Export project as ZIP from Electron +2. Import ZIP in browser version + +--- + +## Terminal Integration + +### Overview + +The Electron version uses the **real OS terminal** instead of the virtual terminal, providing access to all system commands. + +### Architecture + +**ShellTool Detection** (`src/lib/tools/ShellTool.ts`): +```typescript +if (window.electron?.shell) { + // Use real OS shell + const result = await window.electron.shell.exec(command, workingDir); +} else { + // Use virtual command system + const result = await executeCommand(command, workingDir, fs); +} +``` + +**Shell Execution** (`electron/main.js`): +- Uses `child_process.spawn()` to execute commands +- Windows: Uses `cmd.exe` +- macOS/Linux: Uses `/bin/sh` +- Executes in project directory: `~/shakespeare/projects/{projectId}` + +### Features + +**All OS Commands Available:** +```bash +# Package managers +$ npm install +$ yarn add lodash +$ pnpm update + +# Build tools +$ vite build +$ webpack --config webpack.config.js +$ tsc --noEmit + +# Git operations +$ git commit -m "Update" +$ git push origin main + +# System utilities +$ grep -r "TODO" src/ +$ curl https://api.example.com +$ python script.py +``` + +**Native Shell Features:** +- Pipes: `ls | grep ".ts$"` +- Redirection: `echo "test" > file.txt` +- Environment variables: `$PATH`, `$HOME` +- Command chaining: `npm install && npm run build` + +### ANSI Code Stripping + +Output from shell commands is cleaned for AI consumption: +- Color codes removed (e.g., `\u001b[31m`) +- Cursor control sequences stripped +- Text formatting removed (bold, italic) +- Newlines preserved + +**Example:** +``` +Input: \u001b[1m\u001b[32madded 142 packages\u001b[39m\u001b[22m in 3s +Output: added 142 packages in 3s +``` + +Terminal UI still shows colored output for users. + +### Platform Support + +| Platform | Shell | Notes | +|----------|-------|-------| +| macOS | `/bin/sh` | All Unix commands available | +| Linux | `/bin/sh` | Standard Linux utilities | +| Windows | `cmd.exe` | Windows commands, consider Git Bash for Unix tools | + +### Security + +- Commands run with user permissions (no sudo/elevation) +- Working directory sandboxed to `~/shakespeare` +- Environment variables inherited from Electron process + +--- + +## Development Workflow + +### Running in Development Mode + +```bash +npm run electron:dev +``` + +This will: +1. Start Vite dev server on http://localhost:5173 +2. Wait for server to be ready +3. Launch Electron with hot reload +4. Open DevTools automatically + +### Testing Shell Execution + +Use the provided test script to verify shell functionality: + +```bash +# Start Electron in dev mode +npm run electron:dev + +# Open DevTools (View > Toggle Developer Tools) +# Paste contents of electron/test-terminal.js into console +``` + +The test script verifies: +- Basic command execution +- File listing +- Node.js version check +- Error handling +- Working directory + +### Debugging + +**Renderer Process:** +- DevTools open automatically in dev mode +- Or press `Cmd+Option+I` (macOS) / `Ctrl+Shift+I` (Windows/Linux) + +**Main Process:** +```bash +# Enable verbose logging +ELECTRON_ENABLE_LOGGING=1 npm run electron:dev +``` + +**Check Configuration:** +```bash +node electron/test-config.js +``` + +### File Watching + +In development mode: +- Vite provides hot module replacement +- Changes to React components reload instantly +- Electron process restarts on main.js changes (via `nodemon` in the script) + +--- + +## Building for Distribution + +### Prerequisites + +- Node.js 18+ installed +- All dependencies installed: `npm install` +- Web build completed: `npm run build` + +### Build Commands + +**Current Platform:** +```bash +npm run electron:build +``` + +**Specific Platforms:** +```bash +npm run electron:build:mac # macOS (DMG + ZIP) +npm run electron:build:win # Windows (NSIS + Portable) +npm run electron:build:linux # Linux (AppImage, DEB, RPM) +npm run electron:build:all # All platforms +``` + +### Build Output + +``` +electron-dist/ +├── mac/ +│ ├── Shakespeare.app # macOS application bundle +│ ├── Shakespeare.dmg # DMG installer +│ └── Shakespeare-mac.zip # ZIP archive +├── win-unpacked/ +│ └── Shakespeare.exe # Windows executable +├── Shakespeare Setup.exe # NSIS installer +├── Shakespeare Portable.exe # Portable executable +├── shakespeare-*.AppImage # Linux AppImage +├── shakespeare_*.deb # Debian package +└── shakespeare-*.rpm # RPM package +``` + +### Platform-Specific Notes + +**macOS:** +- Builds for Intel (x64) and Apple Silicon (arm64) +- Code signing optional for development +- For distribution: Requires Apple Developer account + +**Windows:** +- Builds for x64 and ARM64 +- No code signing required for development +- For distribution: EV certificate recommended for SmartScreen + +**Linux:** +- Builds for x64 and ARM64 +- AppImage requires FUSE: `sudo apt-get install fuse` +- DEB/RPM packages can be installed with package managers + +### Cross-Platform Limitations + +- **macOS builds require macOS** (for code signing) +- Windows/Linux can be built from any platform +- Use GitHub Actions or CI/CD for multi-platform builds + +### Code Signing + +**Development (Disable Signing):** + +Edit `electron/builder.config.js`: +```javascript +mac: { + identity: null, // Disable code signing +} +``` + +**Production (macOS):** +1. Obtain Apple Developer account +2. Create certificates in Xcode +3. Configure signing in builder.config.js +4. See: https://www.electron.build/code-signing + +**Production (Windows):** +1. Obtain EV code signing certificate +2. Configure in builder.config.js +3. Builds reputation with SmartScreen over time + +--- + +## Troubleshooting + +### Development Issues + +#### Port 5173 Already in Use + +**Solution:** +```bash +# Find and kill the process +lsof -i :5173 # macOS/Linux +netstat -ano | findstr :5173 # Windows + +# Or change the port in vite.config.ts +export default defineConfig({ + server: { port: 5174 }, +}); +``` + +#### Blank Screen on Launch + +**Browser Mode:** +1. Check Vite server is running: http://localhost:5173 +2. Check Electron console for errors +3. Verify URL in `electron/main.js` matches Vite server +4. Clear cache: Delete `node_modules/.vite` + +**Production Build:** +1. Ensure `base: './'` is set in `vite.config.ts` +2. Check `dist/` directory contains all files +3. Look for "Failed to load resource" errors in console +4. Verify file:// protocol is used in loadURL + +#### Assets Fail to Load: "net::ERR_FILE_NOT_FOUND" + +**Problem:** CSS/JS fail to load with `file:///assets/npm/...` errors + +**Solution:** Add to `vite.config.ts`: +```typescript +export default defineConfig(() => ({ + base: './', // Required for Electron + // ... rest of config +})) +``` + +Then rebuild: `npm run build` + +#### 404 Error: Page Not Found + +**Problem:** App shows "404: Oops! Page not found" on launch + +**Solution:** Verify `HashRouter` is used in Electron. + +Check `src/AppRouter.tsx`: +```typescript +const Router = window.electron?.isElectron ? HashRouter : BrowserRouter; +``` + +Rebuild: `npm run build && npm run electron:build` + +#### Service Worker Errors + +**Solution:** Service workers don't work with `file://` protocol. + +Check `src/main.tsx`: +```typescript +if ('serviceWorker' in navigator && !window.electron?.isElectron) { + // Only register in web environment +} +``` + +#### CSP Font Errors + +**Solution:** Update CSP in `index.html`: +```html + +``` + +#### Broken SVG Images + +**Problem:** Logo/SVG files show as broken + +**Solution:** Import SVG files properly: +```typescript +// ❌ Wrong +Logo + +// ✅ Correct +import logo from '/shakespeare.svg?url'; +Logo +``` + +#### Preload Script ESM Errors + +**Solution:** Requires `sandbox: false` in webPreferences. + +Check `electron/main.js`: +```javascript +webPreferences: { + preload: path.join(__dirname, 'preload.js'), + nodeIntegration: false, + contextIsolation: true, // Still enabled + sandbox: false, // Disabled for ESM + webSecurity: true, +} +``` + +### Build Issues + +#### Build Fails with "Cannot find module" + +**Solutions:** +1. Install dependencies: `npm install` +2. Clear and reinstall: `rm -rf node_modules package-lock.json && npm install` +3. Build web first: `npm run build` +4. Verify `dist/` exists +5. Check config: `node electron/test-config.js` + +#### Icons Not Appearing + +**Solution:** Should work automatically with `public/shakespeare-512x512.png`. + +If not: +1. Verify PNG exists +2. Check build output for icon errors +3. Try: `npm run electron:icons` (requires ImageMagick) +4. Check paths in `electron/builder.config.js` + +#### Code Signing Errors (macOS) + +**Development:** Disable signing: +```javascript +mac: { + identity: null, +} +``` + +**Production:** Requires Apple Developer account and certificates. + +#### App Won't Launch After Build + +**Solutions:** +1. Check console/terminal for errors +2. Try unpacked version first +3. macOS: Check Security & Privacy settings +4. Windows: Check Windows Defender logs +5. Verify `dist/` contains valid files + +### Runtime Issues + +#### App Crashes on Startup + +**Solutions:** +1. Check crash logs: + - macOS: `~/Library/Logs/Shakespeare/` + - Windows: `%APPDATA%\Shakespeare\logs\` + - Linux: `~/.config/Shakespeare/logs/` +2. Run from terminal to see errors +3. Test web build in browser first + +#### Shell Execution Error: "spawn /bin/sh ENOENT" + +**Problem:** Terminal commands fail with spawn error + +**Root Cause:** Working directory doesn't exist + +**Solution:** Should be fixed - main.js creates directories automatically. + +**Debug:** +1. Open DevTools +2. Check console for "Shell exec in directory: ..." +3. Verify directory exists: `ls -la ~/shakespeare/projects/` +4. Manually create if needed: `mkdir -p ~/shakespeare/projects` + +#### External Links Not Opening + +**Solution:** Should open in default browser automatically. + +Check `electron/main.js` has: +```javascript +mainWindow.webContents.setWindowOpenHandler(({ url }) => { + shell.openExternal(url); + return { action: 'deny' }; +}); +``` + +### Platform-Specific Issues + +#### macOS: "App is damaged and can't be opened" + +**Solutions:** +1. Development: `xattr -cr /path/to/Shakespeare.app` +2. Distribution: Requires code signing +3. Users: Right-click → Open (instead of double-click) + +#### Windows: "Windows protected your PC" + +**Solutions:** +1. Testing: Click "More info" → "Run anyway" +2. Distribution: Requires EV code signing +3. Build reputation over time + +#### Linux: "Permission denied" + +**Solutions:** +1. Make executable: `chmod +x Shakespeare*.AppImage` +2. Install FUSE: `sudo apt-get install fuse` +3. Try DEB/RPM package instead + +### Performance Issues + +#### App Feels Slow + +**Solutions:** +1. Close DevTools +2. Check system resources +3. Use production build +4. Disable hardware acceleration in `main.js`: + ```javascript + app.disableHardwareAcceleration(); + ``` + +#### High Memory Usage + +**Solutions:** +1. Normal for Chromium-based apps +2. Close unused projects +3. Restart app periodically +4. Check for memory leaks in web code + +--- + +## Getting Help + +If issues persist: + +1. **Check existing issues:** https://gitlab.com/soapbox-pub/shakespeare/-/issues +2. **Create new issue** with: + - OS and version + - Electron version: `npm list electron` + - Steps to reproduce + - Error messages/logs + - Screenshots +3. **Community support:** Check project README for links + +## Useful Commands + +**Complete rebuild:** +```bash +rm -rf node_modules dist electron-dist package-lock.json +npm install +npm run build +npm run electron:build +``` + +**Check versions:** +```bash +npm list electron +node --version +npm --version +``` + +**Verbose logging:** +```bash +ELECTRON_ENABLE_LOGGING=1 npm run electron:dev +``` + +**Check build contents:** +```bash +npm run electron:build -- --dir +ls -la electron-dist/[platform]-unpacked/ +``` + +## Additional Resources + +- [Electron Documentation](https://www.electronjs.org/docs) +- [electron-builder Documentation](https://www.electron.build/) +- [Electron Security](https://www.electronjs.org/docs/latest/tutorial/security) +- [Debugging Electron](https://www.electronjs.org/docs/latest/tutorial/debugging-main-process) +- [Shakespeare Main Docs](../README.md) diff --git a/electron/QUICKSTART.md b/electron/QUICKSTART.md deleted file mode 100644 index 26f7d46d..00000000 --- a/electron/QUICKSTART.md +++ /dev/null @@ -1,141 +0,0 @@ -# Electron Quick Start Guide - -## Prerequisites - -- Node.js 18+ installed -- npm or yarn package manager - -## Development - -To run Shakespeare as an Electron desktop app in development mode: - -```bash -npm run electron:dev -``` - -This will: -1. Start the Vite development server on http://localhost:5173 -2. Launch Electron with hot-reload support -3. Open DevTools automatically for debugging - -## Building for Distribution - -### Build for Your Current Platform - -```bash -npm run electron:build -``` - -This will create an installer/package for your current operating system in the `electron-dist/` directory. - -### Build for Specific Platforms - -**macOS:** -```bash -npm run electron:build:mac -``` -Produces: `.dmg` installer and `.zip` archive for both Intel and Apple Silicon - -**Windows:** -```bash -npm run electron:build:win -``` -Produces: NSIS installer and portable `.exe` for both x64 and ARM64 - -**Linux:** -```bash -npm run electron:build:linux -``` -Produces: AppImage, `.deb`, and `.rpm` packages for both x64 and ARM64 - -### Build for All Platforms - -```bash -npm run electron:build:all -``` - -⚠️ **Note:** Cross-platform builds have limitations: -- Building for macOS requires macOS (for code signing) -- Building Windows `.exe` from macOS/Linux works but may have limitations -- Building for Linux works from any platform - -## Icon Setup - -**Good news!** No icon setup is required. The build automatically uses `public/shakespeare-512x512.png` and converts it to the appropriate format for each platform. - -If you want to customize the icons: -1. Run `npm run electron:icons` (requires ImageMagick) -2. Or manually place custom icons in `electron/resources/` -3. Update `electron/builder.config.js` to use the custom icons - -But for most users, the default setup works perfectly! - -## Output Location - -All built applications will be in the `electron-dist/` directory: - -``` -electron-dist/ -├── mac/ # macOS builds -│ ├── Shakespeare.app # Application bundle -│ └── Shakespeare.dmg # DMG installer -├── win-unpacked/ # Windows unpacked -│ └── Shakespeare.exe # Executable -├── Shakespeare Setup.exe # Windows NSIS installer -├── Shakespeare Portable.exe # Windows portable -└── shakespeare-*.AppImage # Linux AppImage -``` - -## Troubleshooting - -### Port 5173 Already in Use - -If you get an error that port 5173 is already in use: -1. Stop any running Vite dev servers -2. Or change the port in `vite.config.ts` - -### Build Fails - -If the build fails: -1. Ensure you've run `npm run build` successfully first -2. Check that all dependencies are installed: `npm install` -3. Clear the dist folder: `rm -rf dist electron-dist` -4. Try building again - -### Icons Not Showing - -If icons don't appear in the built app: -1. Verify icon files exist in `electron/resources/` -2. Check file names match the builder config -3. Ensure icons are in the correct format (icns for Mac, ico for Windows, png for Linux) - -## What's Different in Electron? - -When running in Electron, the app has access to: - -- `window.electron.isElectron` - Boolean flag (always `true` in Electron) -- `window.electron.platform()` - Returns platform: 'darwin', 'win32', or 'linux' -- `window.electron.version()` - Returns app version from package.json - -You can use these in your code to detect the Electron environment: - -```javascript -if (window.electron?.isElectron) { - console.log('Running in Electron!'); - const platform = await window.electron.platform(); - console.log('Platform:', platform); -} -``` - -## Next Steps - -- Customize the window size and appearance in `electron/main.js` -- Add native menus, dialogs, or other Electron features -- Configure auto-updates (see `electron/README.md`) -- Set up code signing for distribution (required for macOS) - -## Resources - -- [Electron Documentation](https://www.electronjs.org/docs) -- [electron-builder Documentation](https://www.electron.build/) -- [Shakespeare Documentation](../README.md) diff --git a/electron/README.md b/electron/README.md index ee79208f..f51451b0 100644 --- a/electron/README.md +++ b/electron/README.md @@ -1,176 +1,195 @@ -# Shakespeare Electron Build +# Shakespeare Electron Desktop App -This directory contains the Electron-specific files for building Shakespeare as a desktop application. +Shakespeare can run as a native desktop application on macOS, Windows, and Linux using Electron. The desktop version provides enhanced features over the browser version, including real OS filesystem access and native terminal execution. -## Key Features - -### Real OS Filesystem - -When running as an Electron app, Shakespeare uses your **local OS filesystem** at `~/shakespeare` instead of the browser's IndexedDB storage. This provides: - -- Direct file access with your favorite tools -- No storage limits (only disk space) -- Easy version control and backup -- Better performance for large projects - -See [FILESYSTEM.md](./FILESYSTEM.md) for complete details. - -### Real Terminal - -The Electron version uses your **real OS terminal** instead of the virtual terminal in the browser. This means: - -- All OS commands available (not just built-in commands) -- Native shell features (pipes, redirection, etc.) -- Package managers work (`npm`, `yarn`, `pnpm`) -- Full access to system utilities and build tools - -See [REAL_TERMINAL.md](./REAL_TERMINAL.md) for complete details. - -## Structure - -``` -electron/ -├── main.js # Electron main process (ESM) -├── preload.js # Preload script for secure IPC (ESM) -├── builder.config.js # electron-builder configuration (ESM) -├── resources/ # Build resources (icons, etc.) -├── FILESYSTEM.md # Filesystem configuration details -└── README.md # This file -``` - -## UI Configuration - -The Electron build has been configured for a clean, minimal interface: - -- **No default menu bar**: The standard File/Edit/View/Window/Help menu is removed -- **Frameless app**: Shakespeare's UI is the entire window -- **Native window controls**: Standard minimize/maximize/close buttons remain - -This provides a more app-like experience focused on the Shakespeare interface. - -## Development - -Run Shakespeare in Electron development mode: +## Quick Start +### Development Mode ```bash npm run electron:dev ``` -This will: -1. Start the Vite dev server -2. Wait for it to be ready -3. Launch Electron pointing to the dev server - -## Building - -Build Shakespeare for your current platform: - +### Build for Distribution ```bash +# Build for your current platform npm run electron:build + +# Build for specific platforms +npm run electron:build:mac # macOS (DMG + ZIP) +npm run electron:build:win # Windows (NSIS + Portable) +npm run electron:build:linux # Linux (AppImage, DEB, RPM) +npm run electron:build:all # All platforms ``` -Build for specific platforms: - -```bash -npm run electron:build:mac -npm run electron:build:win -npm run electron:build:linux -``` - -Build for all platforms: - -```bash -npm run electron:build:all -``` - -## Output - Built applications will be in the `electron-dist/` directory. -## Platform-Specific Notes +## Key Features -### macOS +### 1. Real OS Filesystem -- Requires `.icns` icon file in `electron/resources/icon.icns` -- Builds both Intel (x64) and Apple Silicon (arm64) versions -- Creates DMG installer and ZIP archive +Projects are stored at `~/shakespeare` on your local filesystem instead of browser IndexedDB: -### Windows +- **No storage limits** - Only limited by disk space +- **Direct file access** - Use any code editor, file manager, or Git client +- **Easy backup** - Standard filesystem backup tools work +- **Better performance** - Faster for large projects -- Requires `.ico` icon file in `electron/resources/icon.ico` -- Builds both x64 and ARM64 versions -- Creates NSIS installer and portable executable +**Directory Structure:** +``` +~/shakespeare/ +├── projects/ # Your Shakespeare projects +├── config/ # AI and Git settings +└── tmp/ # Temporary files +``` -### Linux +**Opening the directory:** +- macOS: `open ~/shakespeare` +- Linux: `xdg-open ~/shakespeare` +- Windows: `explorer %USERPROFILE%\shakespeare` -- Requires PNG icons in `electron/resources/icons/` (multiple sizes) -- Builds both x64 and ARM64 versions -- Creates AppImage, DEB, and RPM packages +### 2. Real OS Terminal -## Icon Resources +All OS commands are available, not just built-in commands: -The build is configured to use `public/shakespeare-512x512.png` as the icon source. electron-builder will automatically convert this PNG to the appropriate format for each platform: +- **Package managers**: `npm`, `yarn`, `pnpm` work directly +- **Build tools**: `vite`, `webpack`, `tsc`, etc. +- **Git CLI**: Full Git command-line interface +- **Native shell features**: Pipes, redirection, environment variables +- **System utilities**: All your favorite command-line tools + +Commands execute in the project directory at `~/shakespeare/projects/{projectId}` with your user's permissions. + +### 3. Clean UI + +- **No menu bar** - Frameless interface focused on Shakespeare +- **Native window controls** - Standard minimize/maximize/close buttons +- **Auto-updates ready** - Can be configured for automatic updates + +## Project Structure + +``` +electron/ +├── main.js # Main process (window management, IPC) +├── preload.js # Secure IPC bridge +├── builder.config.js # Build configuration +├── resources/ # Icons and build assets +├── test-config.js # Configuration validator +├── test-terminal.js # Terminal testing script +├── generate-icons.sh # Icon generation script +├── README.md # This file +└── GUIDE.md # Detailed guide and troubleshooting +``` + +## Icons + +No icon setup required! The build automatically uses `public/shakespeare-512x512.png` and converts it for each platform: - **macOS**: Converts to `.icns` -- **Windows**: Converts to `.ico` -- **Linux**: Uses the PNG directly (generates multiple sizes) +- **Windows**: Converts to `.ico` +- **Linux**: Uses PNG directly -**No additional icon preparation is needed!** The existing Shakespeare logo will be used automatically. +For custom icons, run `npm run electron:icons` (requires ImageMagick) or place platform-specific icons in `electron/resources/`. -If you want to use custom icons instead, you can: -1. Place platform-specific icons in `electron/resources/`: - - `icon.icns` for macOS - - `icon.ico` for Windows - - `icons/*.png` for Linux (multiple sizes) -2. Update `electron/builder.config.js` to point to these files +## Platform-Specific Builds + +### macOS +- Creates DMG installer and ZIP archive +- Builds for both Intel (x64) and Apple Silicon (arm64) +- Requires macOS for code signing (optional for development) + +### Windows +- Creates NSIS installer and portable executable +- Builds for both x64 and ARM64 +- No code signing required for development + +### Linux +- Creates AppImage, DEB, and RPM packages +- Builds for both x64 and ARM64 +- Works from any platform ## Security -The Electron build implements several security best practices: +The Electron build follows security best practices: -- **Context Isolation**: Enabled to prevent renderer from accessing Node.js -- **Sandbox**: Disabled to support ESM in preload (context isolation still provides security) -- **Web Security**: Enabled to enforce same-origin policy -- **Navigation Protection**: Prevents navigation to external sites -- **Window Opening**: External links open in default browser -- **Preload Script**: Minimal API exposure through contextBridge +- **Context Isolation**: Enabled to prevent renderer access to Node.js +- **Web Security**: Enforces same-origin policy +- **Navigation Protection**: Blocks navigation to external sites +- **Minimal IPC API**: Only essential functionality exposed +- **Sandboxed Execution**: Commands run with user permissions + +## API Exposed to Renderer + +The preload script exposes a minimal API via `window.electron`: + +```typescript +window.electron.isElectron // Boolean: true in Electron +window.electron.platform() // Returns: 'darwin' | 'win32' | 'linux' +window.electron.version() // Returns app version +window.electron.fs.* // Filesystem operations +window.electron.shell.exec() // Execute shell commands +``` ## Customization -### Main Process (`main.js`) +### Window Configuration +Edit `electron/main.js` to customize: +- Window size and position +- Minimum/maximum dimensions +- Background color +- Title bar style -The main process handles: -- Window creation and management -- App lifecycle events -- Security policies -- IPC communication - -### Preload Script (`preload.js`) - -The preload script exposes a minimal API to the renderer: -- `window.electron.isElectron` - Flag to detect Electron environment -- `window.electron.platform()` - Get platform information -- `window.electron.version()` - Get app version - -Add additional IPC handlers here if you need Electron-specific features. - -### Builder Configuration (`builder.config.js`) - -Customize the build process: +### Build Settings +Edit `electron/builder.config.js` to configure: - App metadata (ID, name, category) -- Platform-specific settings -- Installer options -- Auto-update configuration (if needed) +- Platform-specific options +- Installer settings +- Auto-update configuration -## Future Enhancements +### Additional Features +Add to `electron/main.js` and `electron/preload.js`: +- Native menus +- System tray icon +- File associations +- Custom URL schemes +- Native dialogs -Potential features to add: +## Development vs Production -- **Auto-updates**: Configure publish settings in builder.config.js -- **Native menus**: Add custom application menu -- **Tray icon**: Add system tray support -- **File associations**: Associate file types with the app -- **Deep linking**: Handle custom URL schemes -- **Native dialogs**: Use Electron's native file/message dialogs -- **Offline mode**: Enhanced offline capabilities -- **Local storage**: Use Electron's native storage APIs +**Development Mode** (`npm run electron:dev`): +- Loads from Vite dev server (http://localhost:5173) +- Hot reload enabled +- DevTools open automatically +- Faster iteration + +**Production Build** (`npm run electron:build`): +- Loads from built files (file:// protocol) +- Optimized and minified +- No DevTools by default +- Ready for distribution + +## Common Issues + +See [GUIDE.md](./GUIDE.md) for detailed troubleshooting, including: +- Port conflicts +- Blank screen issues +- Asset loading errors +- Build failures +- Platform-specific problems + +## Next Steps + +1. **Try it out**: Run `npm run electron:dev` to test locally +2. **Build it**: Create a distributable with `npm run electron:build` +3. **Customize**: Modify window settings, add native features +4. **Distribute**: Set up code signing and auto-updates for production + +## Resources + +- [Electron Documentation](https://www.electronjs.org/docs) +- [electron-builder Documentation](https://www.electron.build/) +- [Shakespeare Main Documentation](../README.md) +- [Detailed Guide](./GUIDE.md) + +--- + +**Note:** For comprehensive documentation including filesystem details, terminal usage, and troubleshooting, see [GUIDE.md](./GUIDE.md). diff --git a/electron/REAL_TERMINAL.md b/electron/REAL_TERMINAL.md deleted file mode 100644 index 94c04dd5..00000000 --- a/electron/REAL_TERMINAL.md +++ /dev/null @@ -1,214 +0,0 @@ -# Real Terminal in Electron - -When Shakespeare runs in Electron, it automatically uses the **real OS terminal** instead of the virtual terminal used in the browser version. - -## How It Works - -### Architecture - -1. **Electron Main Process** (`electron/main.js`): - - Added `shell:exec` IPC handler that spawns real shell processes - - Uses `child_process.spawn()` to execute commands - - Automatically detects platform (Windows uses `cmd.exe`, Unix uses `/bin/sh`) - - All commands execute in the context of `~/shakespeare` directory - -2. **Preload Script** (`electron/preload.js`): - - Exposes `window.electron.shell.exec()` to renderer process - - Provides secure bridge between renderer and main process - -3. **TypeScript Definitions** (`electron/electron.d.ts`): - - Added `ElectronShellAPI` interface - - Defines `ShellExecResult` type with stdout, stderr, and exitCode - -4. **ShellTool** (`src/lib/tools/ShellTool.ts`): - - Detects if `window.electron.shell` is available - - If in Electron, bypasses virtual command system and uses real shell - - Falls back to virtual commands in browser mode - -5. **Terminal Component** (`src/components/Terminal.tsx`): - - Detects Electron environment - - Routes commands to real shell when available - - Shows "Real Terminal (OS Shell)" in welcome message - - Maintains command history and UI features in both modes - -## Features - -### Real Shell Execution -- **All OS commands available**: Not limited to Shakespeare's built-in commands -- **Native shell features**: Pipes, redirection, environment variables all work natively -- **Package managers**: Run `npm`, `yarn`, `pnpm`, etc. directly -- **Build tools**: Execute `vite`, `webpack`, `tsc`, etc. -- **Git operations**: Full Git CLI available -- **System utilities**: Access to all system commands (`grep`, `sed`, `awk`, etc.) - -### Working Directory -- Commands execute in the project directory: `~/shakespeare/{projectsPath}/{projectId}` -- The `projectsPath` is configurable (default: `projects`) -- Paths are automatically resolved relative to this directory -- Full access to the OS filesystem within the Shakespeare directory - -### Platform Support -- **macOS/Linux**: Uses `/bin/sh` for command execution -- **Windows**: Uses `cmd.exe` for command execution -- Commands are platform-aware and work naturally on each OS - -## Usage - -### In Browser Mode -```bash -# Limited to built-in commands -$ ls -$ cat file.txt -$ git status -``` - -### In Electron Mode -```bash -# All OS commands available -$ npm install -$ npm run build -$ python script.py -$ make -$ docker ps -$ curl https://api.example.com -$ any-other-command -``` - -## Security Considerations - -### Sandboxing -- Commands execute with the permissions of the Electron app -- Limited to the `~/shakespeare` directory by default -- No special elevation or sudo access - -### Command Execution -- Commands run through the platform's default shell -- Environment variables from the Electron process are inherited -- Standard input/output/error streams are captured - -## AI Integration - -The ShellTool used by AI assistants automatically uses real shell execution in Electron: - -```typescript -// AI can execute any OS command -await shellTool.execute({ - command: "npm install lodash" -}); - -await shellTool.execute({ - command: "git commit -m 'Update dependencies'" -}); -``` - -### ANSI Code Stripping - -Output from real shell commands is automatically cleaned for AI consumption: -- **ANSI color codes** are stripped (e.g., `\u001b[31m` for red text) -- **Cursor control sequences** are removed -- **Text formatting codes** are stripped (bold, italic, etc.) -- **Newlines and whitespace** are preserved - -This ensures AI receives clean, parseable text without terminal formatting noise. - -**Example:** -``` -Input: \u001b[1m\u001b[32madded 142 packages\u001b[39m\u001b[22m in 3s -Output: added 142 packages in 3s -``` - -The Terminal UI still displays colored output for users - only AI tool output is stripped. - -## Differences from Browser Mode - -| Feature | Browser Mode | Electron Mode | -|---------|-------------|---------------| -| Available Commands | Built-in only (~30 commands) | All OS commands | -| Shell Features | Simulated | Native | -| Package Managers | Not available | Full support | -| Build Tools | Limited | Full support | -| File System | Virtual (IndexedDB) | Real OS filesystem | -| Performance | JavaScript execution | Native shell | -| Platform Commands | Emulated | Native to OS | - -## Terminal UI Features - -Both modes share the same terminal UI features: -- Command history (up/down arrows) -- Output formatting with ANSI color support -- Copy to clipboard -- Auto-scroll -- Command execution state -- Error highlighting - -## Example Session - -```bash -$ pwd -/Users/username/shakespeare/projects/my-app - -$ npm install -added 142 packages, and audited 143 packages in 3s - -$ npm run build -> my-app@1.0.0 build -> vite build -✓ built in 1.2s - -$ git status -On branch main -Your branch is up to date with 'origin/main'. - -nothing to commit, working tree clean -``` - -## Troubleshooting - -### Commands Not Found -- Ensure the command is installed on your system -- Check your system's PATH environment variable -- Verify the command works in your regular terminal - -### Permission Errors -- Electron runs with your user's permissions -- Some commands may require additional permissions -- Use absolute paths if relative paths don't work - -### Platform-Specific Issues -- Windows: Some Unix commands may not be available (use Git Bash or WSL) -- macOS: Some commands may require Xcode Command Line Tools -- Linux: Ensure required packages are installed - -## Development - -To test real terminal execution: - -```bash -# Run Electron in development mode -npm run electron:dev - -# Open the terminal in a project -# Try executing real OS commands -``` - -The terminal will show "Real Terminal (OS Shell)" in the welcome message when running in Electron mode. - -### Testing the Shell API - -A test script is provided in `electron/test-terminal.js` to verify the shell execution works correctly: - -```bash -# Start Electron in development mode -npm run electron:dev - -# Open DevTools (View > Toggle Developer Tools) -# Copy and paste the contents of electron/test-terminal.js into the console -# The script will run 5 tests to verify shell execution -``` - -The test script verifies: -1. Basic echo command execution -2. File listing commands -3. Node.js version check -4. Error handling for non-existent commands -5. Working directory verification diff --git a/electron/TROUBLESHOOTING.md b/electron/TROUBLESHOOTING.md deleted file mode 100644 index b28aecc3..00000000 --- a/electron/TROUBLESHOOTING.md +++ /dev/null @@ -1,399 +0,0 @@ -# Electron Troubleshooting Guide - -## Common Issues and Solutions - -### Development Issues - -#### Port 5173 Already in Use - -**Problem:** Error message: `Port 5173 is already in use` - -**Solution:** -1. Check if Vite is already running: `lsof -i :5173` (macOS/Linux) or `netstat -ano | findstr :5173` (Windows) -2. Kill the existing process or stop the dev server -3. Alternatively, change the port in `vite.config.ts`: - ```typescript - export default defineConfig({ - server: { - port: 5174, // Use a different port - }, - }); - ``` -4. Update the URL in `electron/main.js` to match - -#### Electron Window Opens But Shows Blank Screen - -**Problem:** Electron window opens but displays a blank white screen - -**Solutions:** -1. Check the Vite dev server is running: Open http://localhost:5173 in your browser -2. Check the Electron console for errors: DevTools should open automatically in dev mode -3. Verify the URL in `electron/main.js` matches your Vite server -4. Try clearing the cache: Delete `node_modules/.vite` and restart - -**In production builds:** -1. Check console.log for "Failed to load resource" errors -2. Verify the file:// protocol is used in loadURL -3. Ensure dist/ directory contains all built files -4. Check that assets are loading from the correct path -5. Ensure `base: './'` is set in vite.config.ts for relative paths - -#### Assets Fail to Load: "net::ERR_FILE_NOT_FOUND" - -**Problem:** All CSS and JS assets fail to load with `file:///assets/npm/...` errors - -**Root Cause:** Vite builds with absolute paths (`/assets/...`) by default, but Electron needs relative paths (`./assets/...`) - -**Solution:** -Add `base: './'` to `vite.config.ts`: - -```typescript -export default defineConfig(() => ({ - base: './', // Use relative paths for assets (required for Electron) - // ... rest of config -})) -``` - -Then rebuild: `npm run build` - -This makes all asset references relative to the HTML file, which is required for Electron's `file://` protocol to work correctly. - -#### 404 Error: Page Not Found in Electron - -**Problem:** App shows "404: Oops! Page not found" immediately on launch - -**Root Cause:** `BrowserRouter` uses the actual URL path for routing. In Electron with `file://` protocol, the path is the filesystem path (e.g., `/tmp/.mount_ShakesXXX/resources/app.asar/dist/index.html`), which gets treated as a route. - -**Solution:** -The app should already use `HashRouter` in Electron. Verify in `src/AppRouter.tsx`: - -```typescript -const Router = window.electron?.isElectron ? HashRouter : BrowserRouter; -``` - -If you see a 404 error, check: -1. The router is using `HashRouter` when `window.electron?.isElectron` is true -2. The preload script is working (check `window.electron` exists in console) -3. Rebuild the app: `npm run build && npm run electron:build` - -#### Service Worker Errors in Electron - -**Problem:** Console shows service worker registration errors - -**Solution:** -Service workers don't work with `file://` protocol. The app should skip registration in Electron: - -```typescript -// In src/main.tsx -if ('serviceWorker' in navigator && !window.electron?.isElectron) { - // Only register in web environment -} -``` - -#### CSP Font Errors: "Refused to load the font" - -**Problem:** Console shows CSP errors about blocking base64 fonts - -**Solution:** -Update the Content Security Policy in `index.html` to allow `data:` URIs: - -```html - -``` - -#### Broken Images: SVG Files Not Loading - -**Problem:** Logo or other SVG images show as broken, console shows `net::ERR_FILE_NOT_FOUND` for `.svg` files - -**Root Cause:** Hardcoded absolute paths like `/shakespeare.svg` don't work with Vite's relative base path in Electron - -**Solution:** -Import SVG files properly using Vite's `?url` import: - -```typescript -// ❌ Wrong: Hardcoded path -Logo - -// ✅ Correct: Import with ?url -import logo from '/shakespeare.svg?url'; -Logo -``` - -This ensures Vite processes the asset and generates the correct relative path for both web and Electron builds. - -#### Preload Script Errors: "Cannot use import statement outside a module" - -**Problem:** Error loading preload script with ESM syntax - -**Solution:** -This happens when sandbox mode is enabled. The preload script uses ESM, which requires `sandbox: false` in webPreferences. The main.js file should have: - -```javascript -webPreferences: { - preload: path.join(__dirname, 'preload.js'), - nodeIntegration: false, - contextIsolation: true, // Still enabled for security - sandbox: false, // Disabled to support ESM - webSecurity: true, -} -``` - -Context isolation remains enabled as the primary security boundary. - -#### DevTools Not Opening - -**Problem:** Developer tools don't open automatically in development mode - -**Solution:** -- Press `Cmd+Option+I` (macOS) or `Ctrl+Shift+I` (Windows/Linux) -- Or add this to `electron/main.js` in the `createWindow()` function: - ```javascript - mainWindow.webContents.openDevTools({ mode: 'detach' }); - ``` - -### Build Issues - -#### Build Fails with "Cannot find module" - -**Problem:** Build fails with errors about missing modules - -**Solutions:** -1. Ensure all dependencies are installed: `npm install` -2. Clear node_modules and reinstall: `rm -rf node_modules package-lock.json && npm install` -3. Ensure the web build completes first: `npm run build` -4. Check that `dist/` directory exists and contains built files -5. Verify configuration: `node electron/test-config.cjs` - -#### Module/Import Errors in Electron Files - -**Problem:** Errors related to imports or module system - -**Solution:** -The project uses ESM (ES Modules) throughout, including Electron files. All files use `import`/`export` syntax: -- `main.js` - ESM -- `preload.js` - ESM -- `builder.config.js` - ESM -- `test-config.js` - ESM - -Electron 28+ fully supports ESM, so everything is consistent with the rest of the Shakespeare codebase. - -#### Icons Not Appearing in Built App - -**Problem:** Built application shows default Electron icon instead of Shakespeare icon - -**Solution:** -The build is configured to automatically use `public/shakespeare-512x512.png` and convert it to the appropriate format. This should work out of the box. - -If icons still don't appear: -1. Verify `public/shakespeare-512x512.png` exists -2. Check the console output during build for icon conversion errors -3. Try generating platform-specific icons: `npm run electron:icons` (requires ImageMagick) -4. Verify paths in `electron/builder.config.js` are correct - -#### Linux Build Fails with Icon Error - -**Problem:** `npm run electron:build:linux` fails with icon-related errors - -**Solution:** -This was a common issue in earlier versions. The configuration now uses `public/shakespeare-512x512.png` directly, which electron-builder converts automatically. - -If you still see errors: -1. Ensure `public/shakespeare-512x512.png` exists -2. Update `electron/builder.config.js` to use the PNG icon (should already be set) -3. Don't specify a directory for Linux icons - use a single PNG file - -#### Code Signing Errors (macOS) - -**Problem:** Build fails with code signing errors on macOS - -**Solutions:** -1. For development/testing, disable code signing in `electron/builder.config.js`: - ```javascript - mac: { - identity: null, // Disable code signing - } - ``` -2. For distribution, you need an Apple Developer account and certificates -3. See: https://www.electron.build/code-signing - -#### Build Succeeds But App Won't Launch - -**Problem:** Build completes but the application won't start - -**Solutions:** -1. Check the console/terminal for error messages -2. Try the unpacked version first (in `electron-dist/[platform]-unpacked/`) -3. On macOS, check Security & Privacy settings if app is blocked -4. On Windows, check Windows Defender or antivirus logs -5. Verify the `dist/` directory contains valid built files before running electron-builder - -### Runtime Issues - -#### App Crashes on Startup - -**Problem:** Application crashes immediately after launching - -**Solutions:** -1. Check crash logs: - - macOS: `~/Library/Logs/Shakespeare/` - - Windows: `%APPDATA%\Shakespeare\logs\` - - Linux: `~/.config/Shakespeare/logs/` -2. Try running from terminal to see error messages: - - macOS: `./electron-dist/mac/Shakespeare.app/Contents/MacOS/Shakespeare` - - Windows: `.\electron-dist\win-unpacked\Shakespeare.exe` - - Linux: `./electron-dist/linux-unpacked/shakespeare` -3. Ensure the web build is working: Test in browser first at http://localhost:5173 - -#### IndexedDB/Storage Issues - -**Problem:** App can't save projects or settings - -**Solutions:** -1. Check available disk space -2. Clear Electron's cache: - - macOS: `~/Library/Application Support/Shakespeare/` - - Windows: `%APPDATA%\Shakespeare\` - - Linux: `~/.config/Shakespeare/` -3. Check browser console for storage quota errors -4. Verify permissions on the application support directory - -#### External Links Not Opening - -**Problem:** Clicking external links does nothing - -**Solution:** -This is by design for security. External links should open in the default browser. -If they're not: -1. Check `electron/main.js` has the `setWindowOpenHandler` code -2. Verify the link uses `target="_blank"` -3. Check console for errors - -#### Shell Execution Error: "spawn /bin/sh ENOENT" - -**Problem:** Terminal or AI shell commands fail with error: -``` -Error: Error invoking remote method 'shell:exec': Error: Failed to execute command: spawn /bin/sh ENOENT -``` - -**Root Cause:** The working directory doesn't exist on the OS filesystem when the shell command is executed. - -**Solution:** -This should be fixed in the latest version. The `shell:exec` handler now automatically creates the working directory before spawning the shell process. - -**If the issue persists:** -1. Check the Electron console logs to see which directory is being used -2. Verify the directory path is correct (should be under `~/shakespeare/`) -3. Check filesystem permissions on the Shakespeare directory -4. Try manually creating the project directory: `mkdir -p ~/shakespeare/projects/{projectId}` - -**Debug Steps:** -1. Open DevTools in Electron (View → Toggle Developer Tools) -2. Look for console logs showing: - - `Shell exec in directory: ...` - - `Command: ...` -3. Check for any filesystem errors in the console -4. Verify the directory exists: `ls -la ~/shakespeare/projects/` - -**Workaround:** -If the issue continues, you can manually create the directory structure: -```bash -mkdir -p ~/shakespeare/projects -``` - -Then restart the Electron app. - -### Platform-Specific Issues - -#### macOS: "App is damaged and can't be opened" - -**Problem:** macOS Gatekeeper blocks the app - -**Solutions:** -1. For development builds, run: `xattr -cr /path/to/Shakespeare.app` -2. For distribution, you need proper code signing -3. Users can bypass temporarily: Right-click app → Open (instead of double-clicking) - -#### Windows: "Windows protected your PC" - -**Problem:** Windows SmartScreen blocks the app - -**Solutions:** -1. Click "More info" → "Run anyway" (for testing) -2. For distribution, you need code signing with an EV certificate -3. Build reputation by having many users download and run the app - -#### Linux: "Permission denied" - -**Problem:** AppImage or executable can't be run - -**Solutions:** -1. Make the file executable: `chmod +x Shakespeare*.AppImage` -2. For AppImage, you may need FUSE: `sudo apt-get install fuse` -3. Try the .deb or .rpm package instead - -### Performance Issues - -#### App Feels Slow or Unresponsive - -**Solutions:** -1. Close DevTools if open (they impact performance) -2. Check system resources (CPU, RAM) -3. Try the production build instead of dev mode -4. Disable hardware acceleration in `electron/main.js`: - ```javascript - app.disableHardwareAcceleration(); - ``` - -#### High Memory Usage - -**Solutions:** -1. This is normal for Chromium-based apps -2. Close unused projects in the app -3. Restart the app periodically -4. Check for memory leaks in the web app code - -## Getting Help - -If you're still experiencing issues: - -1. **Check existing issues:** https://gitlab.com/soapbox-pub/shakespeare/-/issues -2. **Create a new issue:** Include: - - Operating system and version - - Electron version (`npm list electron`) - - Steps to reproduce - - Error messages or logs - - Screenshots if applicable -3. **Ask in the community:** Link to Discord/Matrix/forum if available - -## Useful Commands - -**Clear all caches and rebuild:** -```bash -rm -rf node_modules dist electron-dist package-lock.json -npm install -npm run build -npm run electron:build -``` - -**Check Electron version:** -```bash -npm list electron -``` - -**Run with verbose logging:** -```bash -ELECTRON_ENABLE_LOGGING=1 npm run electron:dev -``` - -**Check what files are included in build:** -```bash -npm run electron:build -- --dir -# Check electron-dist/[platform]-unpacked/ directory -``` - -## Additional Resources - -- [Electron Documentation](https://www.electronjs.org/docs) -- [electron-builder Documentation](https://www.electron.build/) -- [Electron Security Best Practices](https://www.electronjs.org/docs/latest/tutorial/security) -- [Debugging Electron Apps](https://www.electronjs.org/docs/latest/tutorial/debugging-main-process)