Implementation:AI QL Tuui Commander
| Knowledge Sources | |
|---|---|
| Domains | Command_Picker, Automation, Electron |
| Last Updated | 2026-10-24 00:00 GMT |
Overview
Concrete tool for initializing the platform automator and executing the command picker shortcut flow to grab selected text and open the popup, provided by the tuui Electron application.
Description
The Commander class has two static methods. init() creates a platform-dispatching Automator instance to verify nut-js is available. initCommand() is the shortcut callback: it creates an Automator, grabs the selected text via Automation.grabSelectedText (falling back to clipboard), caches it via putCachedText (returns a UUID), gets the foremost app, and opens the command picker popup with the text ID and source app. In Mac App Store (MAS) builds, it shows a limitations dialog instead.
Usage
Import Commander when bootstrapping the global shortcut system (call init() to verify automator, then bind initCommand as the shortcut callback).
Code Reference
Source Location
- Repository: tuui
- File: src/main/aid/commander.ts
Signature
export default class Commander {
static init: () => Promise<boolean>
static initCommand: (timeout?: number) => Promise<void>
}
Import
import Commander from './aid/commander'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| timeout | number | No (initCommand, default 1000) | Text grab polling timeout in ms |
Outputs
| Name | Type | Description |
|---|---|---|
| init | Promise<boolean> | True if automator initialized; false on error |
| initCommand | Promise<void> | Opens command picker popup; no return value |
| side effect | putCachedText | Grabbed text cached with UUID key |
| side effect | openCommandPicker | Popup window shown at cursor |
Usage Examples
Bootstrap the Command Picker
import Commander from './aid/commander'
import * as shortcuts from './aid/shortcuts'
const initState = await Commander.init()
if (initState) {
shortcuts.registerShortcuts({
command: () => Commander.initCommand()
})
}
// Ctrl+Alt+T now triggers the command picker
initCommand Flow
// When Ctrl+Alt+T is pressed:
// 1. Create Automator (platform-dispatching)
// 2. Grab selected text (poll clipboard after copy command)
// 3. Fall back to clipboard.readText() if selection empty
// 4. Cache text with putCachedText() → returns UUID textId
// 5. Get foremost app via automator.getForemostApp()
// 6. Open command picker with { textId, sourceApp, startTime }
Related Pages
Implements Principle
- Principle:AI_QL_Tuui_Global_Shortcut_Command_Picker
- Principle:AI_QL_Tuui_Platform_Automator_Dispatch