Project structure
The codebase is organized as follows:Electron architecture
Electron apps use a multi-process architecture:- Main Process
- Renderer Process
The main process runs Node.js and controls the application lifecycle.Location:
main.jsResponsibilities:- Creating browser windows
- Managing application lifecycle
- Handling auto-updates
- IPC (Inter-Process Communication) with renderer
Key components
main.js
Main process (main.js)
The main process is the entry point of the application.
Window creation
main.js:19-53
The window is frameless and transparent, giving gSubs its custom appearance. The UI is rendered entirely using HTML/CSS.
Auto-update system
The app checks for updates on startup:main.js:59-79
- App starts and checks for updates
- When update is downloaded, notify the renderer process
- User clicks “Install” button
- Renderer sends
quitAndInstallmessage to main process - App quits and installs the update
Renderer process (app/renderer/index.js)
The renderer process contains the application logic and UI interactions.
State management
Global state is managed using simple variables and electron-store:app/renderer/index.js:27-32
- store: Persistent storage for user preferences (language)
- globalToken: Tracks current page/operation (empty = home page)
- multiindex: Counter for multiple file operations
- deepSearchToken: Tracks deep search operations
Subtitle sources
Two subtitle sources are initialized:app/renderer/index.js:9-25
- SubDB (hash-based matching) - checked first
- OpenSubtitles (metadata and search) - fallback
Core features
Drag and drop
Drag and drop
Handled by jQuery event listeners:Supported formats:
app/renderer/index.js:217-328
.m4v, .avi, .mpg, .mp4, .webm, .mkvProcess:- Files dragged into the window
- Validate file extensions
- Create
CheckSubtitleinstance for each file - Execute subtitle search
Search functionality
Search functionality
Text search uses OpenSubtitles API:Results are displayed in a table with download buttons.
app/renderer/index.js:172-214
Language selection
Language selection
Language preference is stored persistently:Supported languages: en, es, fr, it, nl, pl, pt, ro, sv, tr
app/renderer/index.js:46-62
Subtitle download
Subtitle download
Downloads are handled via HTTPS streams:Behavior:
app/renderer/index.js:748-845
- For drag & drop: Save to video directory
- For search: Show save dialog
Subtitle checking module (app/renderer/checksub.js)
This module encapsulates the subtitle search logic:
- Try SubDB (hash-based)
- If failed, try OpenSubtitles (metadata-based)
- If multiple matches, show selection UI
UI framework
The UI is built with:- jQuery (3.3.1) - DOM manipulation and events
- jQuery UI - Additional UI components
- Semantic UI - CSS framework for styling
Transitions and animations
app/renderer/index.js:35-37
- Scale animations for showing/hiding elements
- Shake animations for errors
- Fade transitions for page changes
Data flow
Here’s how data flows through the application:IPC communication
Communication between main and renderer processes:Best practices
When working with the codebase:Use tokens
Token system prevents race conditions when switching pages quickly
Error handling
Always provide callbacks for success, failure, and error scenarios
Async operations
Use promises and callbacks properly to handle async subtitle searches
State management
Check globalToken before updating UI to prevent stale updates
Next steps
Setup
Set up your development environment
Contributing
Learn how to contribute to gSubs