Project structure
A well-organized extension looks like this:The entry class
Your extension’s entry point is a class that implementsKlyxPlugin. Klyx discovers this class through the entryClass field in plugin.json and loads it reflectively.
MyExtension.kt
Registering resources
Screens
Register screens duringonLoad() using ScreenRegistry. Each screen gets a unique ScreenId and a composable lambda.
Toolbar actions
Add actions to Klyx’s toolbar. Each action has an ID, label, icon, category, priority, and click handler. Higher priority values place the action first.File openers
Register aFileOpener to handle custom file types. The opener returns a WorkspaceTab if it can handle the file, or null to let other openers try.
Responding to events
Use the event bus to react to app events. Subscribe inonLoad() and unsubscribe in onUnload().
Navigation
Use theNavigator service to navigate users to different destinations:
Best practices
- Keep
onLoad()fast: Defer heavy work toonStart()or launch a coroutine - Unregister everything: Always clean up screens, toolbar actions, and subscribers in
onUnload() - Handle file openers gracefully: Return
nullfromopen()if you can’t handle the file - Use
pluginScope: Launch long-running coroutines onpluginScopeso they’re properly cancelled