When to Use a Background Module
Use a background module when you need to:- Expose an HTTP API to your UI module (via Express routes)
- Handle IPC messages from the renderer
- Maintain a persistent connection (WebSocket, database, etc.)
- Run background polling or scheduled work
- Access Node.js APIs not available in the renderer
Declaring a Background Module
Add thebackground entry to your Vite config:
background entry — keep react() in the plugins array. createPluginConfig does not inject it for you, and the dev server’s Fast Refresh preamble fails without it. See Getting Started for details.
The shell discovers background modules automatically by checking for the compiled background/index.js in your plugin’s install directory — no plugin.json configuration is needed.
The PluginBackgroundModule Contract
Your background entry module must export onStart and onStop. Use the createPlugin helper for type safety and validation:
createPlugin helper validates your module at import time and gives you full type inference on ctx — no manual type imports needed. The shell requires this default export pattern; named exports are not supported.
The Plugin Context
BothonStart() and onStop() receive a ctx object that gives scoped access to shell infrastructure, live flight state, and the pilot. Each accessor is documented on its own page under Plugin Context:
- Services —
logger,config,ipc,auth,airline,database,server. - Flight & Pilot —
flight(state, log, start guards),notify,dialog,prompt.
Lifecycle Summary
- Shell starts and initialises auth
- Shell calls
onStart(ctx)for each plugin with a background module - If
onStart()throws, the plugin is marked errored — other plugins still load - On shutdown, shell calls
onStop(ctx)for each running background module - After an OTA update, the shell calls
onStop(ctx)thenonStart(ctx)fresh