Introduction
Tabby AI Keyboard uses Electron’s IPC (Inter-Process Communication) system to enable secure communication between the renderer process (UI) and the main process (system operations). The IPC layer is exposed through thewindow.electron API via the context bridge.
Architecture
The IPC architecture consists of three main components:- Preload Script (
preload.ts) - Exposes safe IPC methods to the renderer process - IPC Handlers (
/ipc/*-handlers.ts) - Registers listeners in the main process - Services (
/services/) - Implements the actual business logic
Communication Patterns
One-Way Messages (send)
One-way messages are fire-and-forget operations that don’t return a value:Request-Response (invoke)
Request-response operations return a Promise with the result:Event Listeners (on)
Event listeners allow the main process to push updates to the renderer:IPC Method Categories
The IPC methods are organized into several functional groups:Text Operations
Methods for text manipulation and insertion:replaceText()- Replace selected textacceptSuggestion()- Accept AI suggestiondismissSuggestion()- Dismiss current suggestion
Window Management
Methods for controlling application windows:closeMenu()- Close menu windowresizeWindow()- Resize window dimensionsmoveWindow()- Move window positionopenSettings()- Open settings windowtoggleBrainPanel()- Toggle brain panel visibility
Settings & Configuration
Methods for managing application settings:getSuggestionMode()/setSuggestionMode()- Suggestion trigger modegetTextOutputMode()/setTextOutputMode()- Text output methodgetGhostTextEnabled()/setGhostTextEnabled()- Ghost text overlaygetContentProtectionEnabled()/setContentProtectionEnabled()- Screen capture protection
Context & Memory
Methods for context capture and memory management:getContextCaptureEnabled()/setContextCaptureEnabled()- Context capture togglecaptureScreen()- Capture screenshotgetCachedMemories()/setCachedMemories()- Memory cache
Voice & Transcription
Methods for voice agent and transcription features:onVoiceAgentStart()/onVoiceAgentStop()- Voice agent eventsonTranscribeStart()/onTranscribeStop()- Transcription eventssendTranscribeAudio()- Send audio data for transcription
Security Considerations
Context Isolation
All IPC methods are exposed through Electron’scontextBridge.exposeInMainWorld(), which ensures:
- Complete isolation between renderer and main processes
- No direct access to Node.js or Electron APIs from renderer
- Type-safe communication with TypeScript
Input Validation
IPC handlers validate all incoming data:- Type checking on parameters
- Bounds checking for numeric values
- Sanitization of string inputs
TypeScript Types
The IPC API is fully typed. Access types through the globalwindow.electron object:
Error Handling
IPC operations may fail due to various reasons. Always handle errors appropriately:Source Code References
- Preload API:
frontend/electron/src/preload.ts - IPC Handlers:
frontend/electron/src/ipc/ - Services:
frontend/electron/src/services/