Implementation:AI QL Tuui aid createWindow
| Knowledge Sources | |
|---|---|
| Domains | Window_Management, Electron |
| Last Updated | 2026-10-24 00:00 GMT |
Overview
Concrete tool for creating Electron BrowserWindows with consistent defaults, loading URLs with hash routes and query params, and managing window focus and screen placement, provided by the tuui Electron application.
Description
The createWindow function creates a BrowserWindow with default web preferences, ready-to-show handling, window lifecycle listeners, and console message routing. loadWindowUrl builds a dev or production URL with hash routes and encoded query params. ensureOnCurrentScreen moves a window to the current screen if it's on a different display. releaseFocus returns focus to the source app (macOS: AppleScript focus; Windows: activateApp or dummy window trick).
Usage
Import these functions when: creating popup or auxiliary windows, loading URLs with hash routes, ensuring windows are on the correct screen, or releasing focus after closing a popup.
Code Reference
Source Location
- Repository: tuui
- File: src/main/aid/index.ts
Signature
export const createWindow: (opts?: CreateWindowOpts) => BrowserWindow
export function loadWindowUrl(
window: BrowserWindow,
opts: BrowserWindowCommandOptions
): void
export const ensureOnCurrentScreen: (window: BrowserWindow) => void
export const releaseFocus: (opts?: ReleaseFocusOpts) => Promise<void>
export const undockWindow: (window: BrowserWindow, preventQuit?: boolean) => void
export const getCurrentScreen: () => Display
export const getCenteredCoordinates: (w: number, h: number) => { x: number, y: number }
Import
import {
createWindow,
loadWindowUrl,
ensureOnCurrentScreen,
releaseFocus
} from './aid/index'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| opts | CreateWindowOpts | No | Window options (hash, title, x, y, width, height, frame, etc.) |
| opts.queryParams | Record<string, any> | No | URL query parameters |
| opts.hash | string | No | Hash route (e.g. '/popup') |
| opts.keepHidden | boolean | No | If true, don't show on ready-to-show |
| opts.sourceApp | Application | No (releaseFocus) | App to return focus to |
Outputs
| Name | Type | Description |
|---|---|---|
| createWindow | BrowserWindow | New Electron window with listeners attached |
| releaseFocus | Promise<void> | Focus returned to source app or OS |
Usage Examples
Create a Popup Window
import { createWindow, ensureOnCurrentScreen } from './aid/index'
const win = createWindow({
hash: '/popup',
title: 'My Popup',
width: 300,
height: 320,
frame: false,
alwaysOnTop: true,
skipTaskbar: true,
keepHidden: true,
queryParams: { textId: 'uuid', sourceApp: 'Terminal' }
})
ensureOnCurrentScreen(win)
win.show()
Release Focus to Source App
import { releaseFocus } from './aid/index'
await releaseFocus({
sourceApp: { id: 'com.apple.Terminal', window: 'Terminal' },
delay: 500
})
// On macOS: AppleScript focuses the source app
// On Windows: activateApp focuses the window