Klyx manages your extension through four lifecycle methods. Each method runs as a suspend function on the plugin’s coroutine scope, so you can safely call other suspend APIs.
Lifecycle overview
onLoad()
Called when Klyx loads your extension. At this point, your plugin’s services (screens, toolbar, etc.) are available, but other plugins may not have started yet.
What to do here:
- Register screens with
ScreenRegistry
- Register toolbar actions with
ToolbarRegistry
- Subscribe to events on the event bus
- Register file openers
- Initialize lightweight state
onStart()
Called after all plugins have completed onLoad(). This is the right place to interact with other plugins, access shared resources, or start ongoing work.
What to do here:
- Register file openers (if they depend on other plugins)
- Start coroutines for background work
- Access other plugin’s registered resources
onStop()
Called when Klyx is about to unload your extension. You should release any resources acquired in onStart().
What to do here:
- Cancel ongoing operations started in
onStart()
- Close file handles or network connections
- Unregister file openers
onUnload()
Called after onStop() completes. This is your last chance to clean up before the plugin classloader is discarded.
What to do here:
- Unregister all screens
- Unregister all toolbar actions
- Cancel all coroutines
- Unsubscribe from events
If you don’t unregister screens and toolbar actions in `onUnload()’, they will leak. Klyx does not automatically clean them up.
Using the plugin scope
Your plugin has access to a CoroutineScope via pluginScope or lifecycleOwner.lifecycleScope. Coroutines launched on this scope are automatically cancelled when the plugin is unloaded.