Configuration Values
When developing plugins, you can expose configuration values that app developers set in napacitor.config.json to influence how the plugin behaves at runtime.
Defining Configuration Values
Configuration values live under the plugin's name in the plugins property of napacitor.config.json:
{
"appId": "com.company.app",
"appName": "My App",
"webDir": "dist",
"plugins": {
"MyCoolPlugin": {
"style": "dark",
"iconColor": "#FF0000"
}
}
}
The C# implementation reads the plugin's own section via the Config property (a JsonElement), and the whole file via AppConfig:
[NapacitorPlugin("MyCoolPlugin")]
public class MyCoolPlugin : NapacitorPluginBase
{
[NapacitorMethod]
public Task<string> GetStyle()
{
if (Config.ValueKind == JsonValueKind.Object &&
Config.TryGetProperty("style", out var style) &&
style.ValueKind == JsonValueKind.String)
{
return Task.FromResult(style.GetString()!);
}
return Task.FromResult("light"); // graceful fallback
}
}
Accessing Values
Config—plugins.<PluginName>;ValueKindisUndefinedwhen nothing is configured.AppConfig— the entirenapacitor.config.jsonroot.- Both are
System.Text.JsonJsonElements; useTryGetProperty/ValueKindchecks rather than direct casts.
You cannot enforce that consumers provide configuration values, and consumers can pass invalid data. As a plugin developer, provide adequate documentation and gracefully fall back when values are missing or malformed.
Documenting Configuration Values
Document the supported values in the plugin README, alongside the install instructions, e.g.:
## Configuration
```json
{
"plugins": {
"MyCoolPlugin": {
"style": "dark",
"iconColor": "#FF0000"
}
}
}
```
| Option | Type | Description |
| --- | --- | --- |
| `style` | `'dark' \| 'light'` | Theme override (default `'light'`). |
| `iconColor` | `string` | Icon color, `#RRGGBB` (default `#FFFFFF`). |