The WindowsController is responsible for creating, tracking, and managing all types of windows in Flow Browser. It uses specialized type managers to handle different window types with type-safe APIs.
Import: import { windowsController } from '@/controllers/windows-controller'The controller is a singleton instance exported as windowsController.
Each window type has a dedicated WindowTypeManager that provides type-safe methods:
class WindowsController { public browser: WindowTypeManager<typeof BrowserWindow>; public settings: WindowTypeManager<typeof SettingsWindow>; public onboarding: WindowTypeManager<typeof OnboardingWindow>; public extensionPopup: WindowTypeManager<typeof ExtensionPopupWindow>;}
// Get all browser windowsconst allBrowserWindows = windowsController.browser.getAll();// Get focused browser windowconst focusedBrowser = windowsController.browser.getFocused();// Get browser window by IDconst browserById = windowsController.browser.getById(windowId);// Get browser window from WebContentsconst browserFromWC = windowsController.browser.getFromWebContents(webContents);
Settings is a singleton window - only one can be open at a time.
// Get existing settings window or create new oneconst settingsWindow = windowsController.settings.getSingletonWindow();// Check if settings window existsconst existingSettings = windowsController.settings.getExistingSingletonWindow();if (!existingSettings) { console.log('Settings window is not open');}
Find the window containing a specific WebContents.
public getWindowFromWebContents(webContents: WebContents): BaseWindow | null
Example:
// In an IPC handleripcMain.handle('some-action', (event) => { const window = windowsController.getWindowFromWebContents(event.sender); if (window) { console.log(`Request from window ${window.id}`); }});
class BrowserWindow extends BaseWindow { public browserWindowType: 'normal' | 'popup'; public viewManager: ViewManager; public coreWebContents: WebContents[]; public omnibox: Omnibox;}
const window = windowsController.getFocused();if (windowsController.browser.isInstanceOf(window)) { // TypeScript knows this is a BrowserWindow console.log(window.browserWindowType);}if (windowsController.settings.isInstanceOf(window)) { // TypeScript knows this is a SettingsWindow console.log('Settings window is focused');}
const window = windowsController.getWindowById(someId);// Returns BrowserWindow or nullconst browserWindow = windowsController.browser.filterInstance(window);if (browserWindow) { // Safe to use as BrowserWindow console.log(browserWindow.viewManager);}
Don’t call _addWindow() or _removeWindow() directly. These are internal methods used by window type managers.
Use type managers instead of direct window creation to maintain type safety and proper lifecycle management.
// Goodconst window = windowsController.browser.new('normal');// Bad - loses type safety and lifecycle trackingconst window = new BrowserWindow('normal');