Implementation:AI QL Tuui MainRunner
| Knowledge Sources | |
|---|---|
| Domains | Window_Management, Electron, App_Lifecycle |
| Last Updated | 2026-10-24 00:00 GMT |
Overview
Concrete tool for creating the splash, main, and error BrowserWindow instances and bootstrapping IPC and MCP handlers, provided by the tuui Electron application.
Description
The MainRunner module exports three async factory functions and an exit helper. createSplashWindow builds a frameless, transparent, always-on-top 400×300 window that loads the splash page. createMainWindow assembles the main BrowserWindow from Constants with platform-specific hidden title-bar and overlay styling, wires the system tray via createTray, initializes the IPC registry (IPCs.initialize), loads MCP config (loadConfig), registers per-server IPC handlers (registerIpcHandlers) and MCP features (IPCs.initializeMCP), then loads the dev or production URL. createErrorWindow loads the #/error route and destroys the main window in production. exitApp hides and destroys the main window and calls app.exit.
Usage
Import these functions when bootstrapping the Electron app: the main-process entry point (index.ts) calls createSplashWindow on app.on('ready'), then createMainWindow once the splash window is ready; createErrorWindow is invoked from the render-process-gone handler.
Code Reference
Source Location
- Repository: tuui
- File: src/main/MainRunner.ts
- Lines: 1-201
Signature
export const createSplashWindow = async (): Promise<BrowserWindow>
export const createMainWindow = async (): Promise<BrowserWindow>
export const createErrorWindow = async (
errorWindow: BrowserWindow,
mainWindow: BrowserWindow,
_details?: RenderProcessGoneDetails
): Promise<BrowserWindow>
const exitApp = (mainWindow: BrowserWindow): void
Import
import {
createSplashWindow,
createMainWindow,
createErrorWindow
} from './MainRunner'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| errorWindow | BrowserWindow | Yes (createErrorWindow) | Placeholder window to reuse for the error screen |
| mainWindow | BrowserWindow | Yes (createErrorWindow, exitApp) | The main window to hide/destroy |
| _details | RenderProcessGoneDetails | No (createErrorWindow) | Crash details (currently unused) |
| options.width | number | No | Window width (1500 dev / 1280 prod) |
| options.height | number | No | Window height (900) |
| options.tray | TrayOptions | No | Tray configuration (enabled, menu, trayWindow) |
Outputs
| Name | Type | Description |
|---|---|---|
| createSplashWindow | Promise<BrowserWindow> | Frameless transparent splash window |
| createMainWindow | Promise<BrowserWindow> | Main window with tray, IPC, and MCP handlers wired |
| createErrorWindow | Promise<BrowserWindow> | Error window showing the #/error route |
| side effect | IPC channels | IPCs.initialize + per-server handlers registered |
| side effect | MCP clients | loadConfig + initializeMCP called |
Usage Examples
Bootstrap on App Ready
import { app } from 'electron'
import { createSplashWindow, createMainWindow, createErrorWindow } from './MainRunner'
let mainWindow: any
app.on('ready', async () => {
// 1. Show splash while the main window boots
const splash = await createSplashWindow()
// 2. Create the main window (wires tray, IPC, MCP)
mainWindow = await createMainWindow()
// 3. Close the splash once the main window is ready
splash.close()
})
// 4. On renderer crash, show the error window
app.on('render-process-gone', async (_event, _webContents, details) => {
await createErrorWindow(null, mainWindow, details)
})
Tray-Window Mode
// When options.tray.trayWindow is true, createMainWindow builds a
// frameless, always-on-top, non-resizable floating window attached
// to the tray icon and calls hideWindow/showWindow accordingly.
//
// The default options object in MainRunner.ts controls this:
// tray: { enabled: true, menu: true, trayWindow: false }