4.4 KiB
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/shakespeareor/home/username/shakespeare - Windows:
C:\Users\username\shakespeare
- macOS/Linux:
-
Automatic Creation: The directory is automatically created when the Electron app starts if it doesn't exist
How It Works
Architecture
- Browser Mode: Uses
LightningFSAdapterwith IndexedDB storage - Electron Mode: Uses
NodeFSAdapterwith Node.jsfsmodule
The filesystem adapter is selected automatically in src/App.tsx:
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:
- Normalizes the path
- Removes leading slashes
- Joins with
SHAKESPEARE_ROOT
IPC Communication
Filesystem operations are handled via Electron IPC:
-
Renderer Process (
src/lib/NodeFSAdapter.ts):- Calls
window.electron.fs.*methods - Converts data types for IPC serialization (Uint8Array ↔ Array)
- Calls
-
Preload Script (
electron/preload.js):- Exposes filesystem API to renderer via
contextBridge - Provides type-safe interface
- Exposes filesystem API to renderer via
-
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
- Handles IPC calls with
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
- No Storage Limits: Unlike IndexedDB, your filesystem is only limited by disk space
- Direct File Access: Use your favorite code editor, file manager, or command-line tools
- Version Control: Easy to use Git clients outside of Shakespeare
- Backup/Sync: Use standard backup tools or cloud sync (Dropbox, iCloud, etc.)
- 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
~/shakespearedirectory 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:
# 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 ~/shakespeareornautilus ~/shakespeare - Windows:
explorer %USERPROFILE%\shakespeare
Switching Between Browser and Electron
The browser and Electron versions use different storage:
- Browser: IndexedDB (not directly accessible)
- Electron:
~/shakespearedirectory
To migrate projects:
- Export from browser as ZIP
- 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