Initialization Flow
The application starts insrc/main/index.ts:1 with a carefully orchestrated initialization:
src/main/index.ts:20
Once the lock is acquired, the browser module loads (src/main/browser.ts:1):
Core Controllers
Controllers are singleton classes managing specific domains. They use TypedEventEmitter for internal communication.TabsController
Purpose: Manages all tab instances, lifecycle, grouping, and state. File:src/main/controllers/tabs-controller/index.ts:45
Key Responsibilities
Key Responsibilities
- Tab Creation:
createTab()- Creates Tab instances with WebContentsView - Tab Groups: Manages glance and split view groups
- Active Tab Tracking: Per window-space active tab mapping
- Lifecycle Management: Sleep, archive, destroy operations
- Position Management: Tab ordering within spaces
tabs: Map<number, Tab>- All active tabs indexed by IDwindowActiveSpaceMap: Map<number, string>- Current space per windowspaceActiveTabMap: Map<WindowSpaceReference, Tab | TabGroup>- Active tab/group per window-spacetabGroups: Map<string, TabGroup>- All tab groups (glance, split)
Each Tab has three associated managers:
- TabLifecycleManager - Sleep/wake, fullscreen, navigation state
- TabLayoutManager - Show/hide, bounds calculation
- TabBoundsController - Geometry and positioning
src/main/controllers/tabs-controller/index.ts:243WindowsController
Purpose: Manages all application windows and window types. File:src/main/controllers/windows-controller/index.ts:22
Window Types
Window Types
BrowserWindow (
src/main/controllers/windows-controller/types/browser.ts)- Main browser windows with tabs
- Includes WebContentsViews for web pages
- Portal component windows for omnibox, popups
- Custom window controls integration
src/main/controllers/windows-controller/types/settings.ts)- Singleton settings/preferences window
- Frameless with custom titlebar
src/main/controllers/windows-controller/types/onboarding.ts)- First-run onboarding wizard
- Singleton, shown once per installation
src/main/controllers/windows-controller/types/extension-popup.ts)- Extension popup windows
- Managed by electron-chrome-extensions
- Type-safe window creation
- Singleton enforcement (settings, onboarding)
- Lifecycle management
- Type-specific configurations
SessionsController
Purpose: Manages Electron sessions for different profiles. File:src/main/controllers/sessions-controller/index.ts:10
Session Setup
Session Setup
When creating a profile session (
src/main/controllers/sessions-controller/index.ts:18):- Create Session:
session.fromPath(profilePath) - Register Protocols:
flow://,flow-external://,flow-internal:// - Setup Handlers: Permission handlers, certificate validation
- Register Preload: Inject preload scripts to all WebContents
- Intercept Rules: User-agent transformer, CORS bypass, PDF viewer
- Store Session: Cache in sessions Map
SpacesController & ProfilesController
Purpose: Manage workspaces and user profiles. Files:src/main/controllers/spaces-controller/index.tssrc/main/controllers/profiles-controller/index.ts
- Session storage
- Cookies
- Cache
- Extensions
- Settings
Tab Management Deep Dive
Tab Class
Each tab is an instance of theTab class.
File: src/main/controllers/tabs-controller/tab.ts
- Sleep Mode: Tabs can be put to sleep to save memory (
src/main/controllers/tabs-controller/tab-lifecycle.ts) - Archive: Inactive tabs are archived after threshold
- Tab Groups: Glance (stacked) and Split view groups
- State Persistence: All state saved to SQLite
Tab Lifecycle
Creation
tabsController.createTab() creates Tab instance with WebContentsViewsrc/main/controllers/tabs-controller/index.ts:146Sleep (Optional)
After inactivity threshold, destroy WebContentsView but keep state
src/main/controllers/tabs-controller/tab-lifecycle.tsArchive
After longer inactivity, completely destroy tab (state persisted to DB)
src/main/controllers/tabs-controller/index.ts:102Data Persistence
Flow uses SQLite for all persistent data. Schema:src/main/saving/db/schema.ts
Tab Persistence
Manager:tabPersistenceManager (src/main/saving/tabs/index.ts)
- Tabs marked dirty when state changes
- Every 2 seconds, dirty tabs written to SQLite
- On app quit, final flush before database close
- On restore, tabs loaded from database
Recently closed tabs are tracked separately for “Reopen Closed Tab” functionality.See
src/main/saving/tabs/recently-closed.tsExtension System
Flow supports Chrome extensions via electron-chrome-extensions. File:src/main/modules/extensions/main.ts
Extension Architecture
Extension Architecture
- Extensions loaded per profile (isolated between profiles)
- Extension APIs provided by electron-chrome-extensions
- Custom APIs can be added via extension handlers
- Extensions stored in profile directory
- Permissions managed through manifest parsing
Application Lifecycle
Key lifecycle events managed insrc/main/app/lifecycle.ts:
Lifecycle Events
Lifecycle Events
window-all-closed
- On macOS: Keep app running
- On Windows/Linux: Quit app
- Set
quitController.isQuitting = true - Skip all IPC and persistence operations
- Close database connection
- If no windows, create new browser window
- Focus existing window
- Process command-line URLs
Module System
Utility modules insrc/main/modules/:
| Module | Purpose |
|---|---|
extensions/ | Chrome extension support |
favicons.ts | Favicon fetching and caching |
icons.ts | App icon management |
content-blocker.ts | Ad/tracker blocking |
user-agent.ts | User-agent string handling |
shortcuts.ts | Keyboard shortcut management |
logs.ts | Logging infrastructure |
Next Steps
Renderer Process
Learn about the React UI layer
IPC Communication
Understand main ↔ renderer messaging