> ## Documentation Index
> Fetch the complete documentation index at: https://klyx.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Services

> How to access Klyx services from your extension

Klyx provides services to extensions through property delegates. Services fall into two categories: global plugin services and per-plugin runtime services.

## Plugin services (global)

Global services are singletons shared across all plugins. Access them with `by plugin()`:

```kotlin theme={null}
private val screens: ScreenRegistry by plugin()
private val toolbar: ToolbarRegistry by plugin()
private val navigator: Navigator by plugin()
private val fileSystem: FileSystem by plugin()
private val openers: FileOpenerRegistry by plugin()
private val settings: Settings by plugin()
private val fonts: Fonts by plugin()
private val tabs: Tabs by plugin()
private val terminalManager: TerminalManager by plugin()
private val languageServers: LanguageServerRegistry by plugin()
```

These delegates work from anywhere in your `KlyxPlugin` implementation, including `init` blocks.

## Runtime services (per-plugin)

Runtime services are scoped to your specific plugin instance. Access them with `by runtime()`:

```kotlin theme={null}
private val info: PluginInfo by runtime()
private val context: PluginContext by runtime()
private val lifecycleOwner: PluginLifecycleOwner by runtime()
```

`PluginInfo` gives you access to the plugin's descriptor and file paths:

```kotlin theme={null}
info.descriptor.name       // "Sample Plugin"
info.descriptor.version    // "1.0.0"
info.descriptor.id         // "com.klyx.sampleplugin"
info.apkPath               // Path to the installed APK
info.bundlePath            // Path to the .klyx bundle (if available)
```

## Accessing services from PluginContext

If you have a `PluginContext` (e.g., from `currentPluginContext()`), you can resolve services inline:

```kotlin theme={null}
val screenService = context.service<ScreenRegistry>()
```

## Accessing from coroutine context

In a coroutine, access the plugin context through the current coroutine context:

```kotlin theme={null}
launch {
    val ctx = currentPluginContext()
    val bus = ctx.eventBus
    bus.publish(MyCustomEvent())
}
```

Available functions:

| Function                       | Returns                | Description                                              |
| ------------------------------ | ---------------------- | -------------------------------------------------------- |
| `currentPluginContext()`       | `PluginContext`        | Current plugin context (throws if not in plugin context) |
| `currentPluginContextOrNull()` | `PluginContext?`       | Current plugin context or null                           |
| `currentLifecycleOwner()`      | `PluginLifecycleOwner` | Current lifecycle owner                                  |

## Complete service list

| Service                  | Type                   | Description                                  |
| ------------------------ | ---------------------- | -------------------------------------------- |
| `ScreenRegistry`         | `PluginService`        | Register/unregister composable screens       |
| `ToolbarRegistry`        | `PluginService`        | Register/unregister toolbar actions          |
| `Navigator`              | `PluginService`        | Navigate between destinations                |
| `FileSystem`             | `PluginService`        | File operations (list, read, write, delete)  |
| `FileOpenerRegistry`     | `PluginService`        | Register/unregister custom file openers      |
| `Settings`               | `PluginService`        | Read and update app settings                 |
| `Fonts`                  | `PluginService`        | Load font families                           |
| `Tabs`                   | `PluginService`        | Manage workspace tabs                        |
| `TerminalManager`        | `PluginService`        | Create and manage terminal sessions          |
| `LanguageServerRegistry` | `PluginService`        | Register language server providers           |
| `PluginInfo`             | `PluginRuntimeService` | Current plugin's descriptor and paths        |
| `PluginContext`          | `PluginRuntimeService` | Current plugin's app reference and event bus |
| `PluginLifecycleOwner`   | `PluginRuntimeService` | Lifecycle and coroutine scope                |
