Plugin Settings
Plugin settings are defined as an array in the mobro_plugin_config.json file.
For detailed information, refer to In Depth: Plugin Configuration. By defining settings in the
configuration file, MoBro automatically:
- Exposes the settings to the user.
- Validates the entered values.
- Persists the settings values.
Provide sensible default values for your plugin settings whenever possible.
This enables the plugin to work immediately after installation without requiring users to configure it first.
Settings Fields
MoBro supports several types of settings fields. All fields share a set of common attributes:
| Field | Type | Default | Restrictions | Description |
|---|---|---|---|---|
type | string | - | Required Options: checkbox, number, select, string | Type of the settings field. |
name | string | - | Required Length: 1 - 64Pattern: ^[\w-]+$ | Key identifier of the field. |
label | string | - | Required Length: 1 - 64 | Display name of the field. |
description | string? | - | Max length: 256 | Optional tooltip or field description. |
required | boolean | false | Whether a value is mandatory. |
Checkbox
A checkbox for toggling a boolean value. Read its value as bool.
| Field | Type | Description |
|---|---|---|
defaultValue | boolean? | Optional default value for the field. |
Number
A field for numeric input. Read its value as double, or as int if only whole numbers are allowed.
| Field | Type | Description |
|---|---|---|
defaultValue | double? | Optional default value. |
min | double? | Optional minimum value for validation. |
max | double? | Optional maximum value for validation. |
String
A field for text input. Read its value as string.
| Field | Type | Description |
|---|---|---|
defaultValue | string? | Optional default value. |
regex | string? | Optional regular expression for value validation. |
Select
A dropdown with predefined options. Read the value of the selected option as string.
| Field | Type | Description |
|---|---|---|
defaultValue | string? | Optional default selection value. |
options | array | Array of predefined selectable options. |
Options
| Field | Type | Restrictions | Description |
|---|---|---|---|
label | string | Required Length: 1 - 64 | Visible name of the select option. |
value | string | Required Length: 1 - 64Pattern: ^[\w-]+$ | Internal value of the select option. |
Accessing Settings
The current values of the plugin settings are accessed using
the IMoBroSettings service, which is injected into the plugin's constructor.
public class Plugin : IMoBroPlugin
{
private readonly IMoBroSettings _settings;
public Plugin(IMoBroSettings settings)
{
_settings = settings;
}
public void Init()
{
// Throws a PluginSettingsException if the setting has no value
var updateFrequency = _settings.GetValue<int>("update_frequency");
// Falls back to the given default value if the setting has no value
var showProcesses = _settings.GetValue("show_processes", false);
}
}
When Settings Change
When the user changes the settings, MoBro re-creates the plugin: the current instance is shut down and a new
instance is created and initialized with the new settings values. The plugin therefore doesn't need to watch for
changes; it simply reads the settings in Init().
See Plugin Lifecycle for the exact sequence.
Example Configuration
Below is an example configuration file from the MoBroHardwareMonitor plugin. It demonstrates how to define various settings, such as:
- Update Frequency
A dropdown (select) field to choose polling intervals. - Monitoring Categories
Checkbox fields to enable/disable categories of metrics. - Process Monitoring
A number field to specify how many processes to include, and a dropdown to define the sorting order.
This configuration also uses localization for user-facing text.
{
"name": "modbros_mobrohardwaremonitor",
"displayName": "MoBro Hardware Monitor",
"author": "ModBros",
"description": "A basic hardware monitoring plugin covering the most basic metrics",
"assembly": "Plugin.MoBroHardwareMonitor.dll",
"localization": "Resources/Localization",
"settings": [
{
"type": "select",
"name": "update_frequency",
"label": "settings.update.title",
"description": "settings.update.desc",
"required": false,
"defaultValue": "1000",
"options": [
{
"label": "500 ms",
"value": "500"
}, {
"label": "750 ms",
"value": "750"
}, {
"label": "1000 ms",
"value": "1000"
}, {
"label": "1500 ms",
"value": "1500"
}, {
"label": "2000 ms",
"value": "2000"
}, {
"label": "3000 ms",
"value": "3000"
}, {
"label": "4000 ms",
"value": "4000"
}, {
"label": "5000 ms",
"value": "5000"
}
]
}, {
"type": "checkbox",
"name": "cpu_metrics",
"label": "settings.cpu.title",
"description": "settings.cpu.desc",
"defaultValue": true,
"required": false
}, {
"type": "checkbox",
"name": "gpu_metrics",
"label": "settings.gpu.title",
"description": "settings.gpu.desc",
"defaultValue": true,
"required": false
}, {
"type": "checkbox",
"name": "ram_metrics",
"label": "settings.ram.title",
"description": "settings.ram.desc",
"defaultValue": true,
"required": false
}, {
"type": "number",
"name": "num_processes",
"label": "settings.num_processes.title",
"description": "settings.num_processes.desc",
"defaultValue": 0,
"min": 0,
"max": 20
}, {
"type": "select",
"name": "processes_sort",
"label": "settings.processes_sort.title",
"description": "settings.processes_sort.desc",
"required": false,
"defaultValue": "cpu",
"options": [
{
"label": "settings.processes_sort.option_cpu",
"value": "cpu"
}, {
"label": "settings.processes_sort.option_ram",
"value": "ram"
}
]
}
]
}