Main Process Logic
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
The Main Process Logic serves as the backbone of the Messenger Unleashed application, orchestrating the lifecycle of the Electron environment. It is responsible for window management, security policy enforcement, native system integrations (like tray icons and global shortcuts), and state persistence using electron-store. By intercepting network requests and injecting specialized CSS and JavaScript, the main process enhances the standard Messenger web experience with features like read-receipt blocking and custom themes.
Architecturally, the application follows the standard Electron pattern where a single Main Process manages one or more Renderer Processes. The Main Process handles all heavy lifting regarding the operating system, while the Preload script acts as a secure bridge, exposing specific functionalities to the web context without compromising security.
Sources: CLAUDE.md:12-16, src/main/index.ts:1-35
Application Lifecycle and Window Management
The application ensures a single-instance lock to prevent multiple instances from running simultaneously. On macOS, it manages the transition between the Dock and the Menu Bar mode.
Window Creation
The createWindow function initializes the primary BrowserWindow with specific webPreferences, including the path to the preload script and strict contextIsolation.
Sources: src/main/index.ts:1145-1163
Lifecycle Flow
The following diagram illustrates the application startup and window management flow:
The application lifecycle begins by requesting a single instance lock and proceeds to initialize state before loading the Messenger URL.
Sources: src/main/index.ts:32-45, src/main/index.ts:1282-1320
Privacy and Stealth Logic
One of the core systems within the main process is the network request blocker. It intercepts outgoing traffic to block privacy-invading signals such as read receipts and typing indicators.
Request Interception
The updateRequestBlocker function sets up session.defaultSession.webRequest.onBeforeRequest filters. It uses regex patterns to identify and cancel specific requests.
| Component | Logic Description |
|---|---|
| Read Receipt Blocker | Matches URLs like /mark_seen.php or GraphQL MarkThreadRead mutations. |
| Typing Blocker | Matches URLs like /typ.php and checks GraphQL payloads for is_typing. |
| Visibility Override | Injected via preload to force document.hidden to true and visibilityState to hidden. |
Sources: src/main/index.ts:182-252, src/preload/index.ts:503-547
WebSocket Proxy
Because Messenger uses WebSockets for real-time status updates, a simple HTTP interceptor is insufficient. The Main Process injects a WebSocketProxy script that wraps the native window.WebSocket to drop payloads containing typing or active status updates.
Sources: src/main/index.ts:321-416
Theme and UI Customization
The theme system allows for hot-swapping visual styles without a full page reload by utilizing insertCSS and removeInsertedCSS with specific keys.
Theme Application Process
The applyTheme function updates the store and triggers applyThemeCSS. The CSS is extracted from a themes.css file using regex patterns that look for specific markers (e.g., /* oled */).
Themes are applied by reading from a central CSS file and injecting the relevant slice into the browser window.
Sources: src/main/themes.ts:38-60, src/main/index.ts:602-608
Power Tools and Integration
The Main Process implements several "Power Tools" that bridge the gap between a web app and a native desktop application.
Key Features Summary
- Quick Replies: Uses
executeJavaScriptto inject text into the Messenger textbox and simulate the Enter key. - Quiet Hours: A background monitor (
startQuietHoursMonitor) runs every 60 seconds to toggle Do Not Disturb based on user-defined time ranges. - Picture-in-Picture (PiP): Spawns a frameless, always-on-top
BrowserWindowloading Messenger, with a custom close button injected via CSS/JS. - Global Shortcuts: Registers system-wide hotkeys (e.g.,
CmdOrCtrl+Shift+Ffor Focus Mode) that function even when the app is not focused.
Sources: src/main/index.ts:742-780, src/main/index.ts:1100-1143, src/main/index.ts:1531-1560
Settings and State Persistence
Settings are managed via electron-store. When a setting is updated, the Main Process handles the necessary side effects immediately.
Setting Update IPC
When the renderer (Settings Modal) sends an update-setting message, the following logic is executed:
The application reacts to setting changes by updating internal state and immediately applying relevant visual or functional changes.
Sources: src/main/index.ts:1011-1081, src/preload/settings-modal.ts:162-180
Conclusion
The Main Process Logic in Messenger Unleashed transforms a standard web view into a feature-rich desktop client. By centralizing management of network requests, CSS injection, and native API interactions, it provides a highly customizable and privacy-oriented messaging environment. Its reliance on a robust IPC bridge and state persistence ensures a seamless user experience across app restarts.
Sources: CLAUDE.md:25-38, src/main/index.ts:1601-1615