Skip to main content

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.
tip

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:

FieldTypeDefaultRestrictionsDescription
typestring-Required
Options: checkbox, number, select, string
Type of the settings field.
namestring-Required
Length: 1 - 64
Pattern: ^[\w-]+$
Key identifier of the field.
labelstring-Required
Length: 1 - 64
Display name of the field.
descriptionstring?-Max length: 256Optional tooltip or field description.
requiredbooleanfalseWhether a value is mandatory.

Checkbox

A checkbox for toggling a boolean value. Read its value as bool.

FieldTypeDescription
defaultValueboolean?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.

FieldTypeDescription
defaultValuedouble?Optional default value.
mindouble?Optional minimum value for validation.
maxdouble?Optional maximum value for validation.

String

A field for text input. Read its value as string.

FieldTypeDescription
defaultValuestring?Optional default value.
regexstring?Optional regular expression for value validation.

Select

A dropdown with predefined options. Read the value of the selected option as string.

FieldTypeDescription
defaultValuestring?Optional default selection value.
optionsarrayArray of predefined selectable options.

Options

FieldTypeRestrictionsDescription
labelstringRequired
Length: 1 - 64
Visible name of the select option.
valuestringRequired
Length: 1 - 64
Pattern: ^[\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.

Plugin.cs
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:

  1. Update Frequency
    A dropdown (select) field to choose polling intervals.
  2. Monitoring Categories
    Checkbox fields to enable/disable categories of metrics.
  3. 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.

Plugin.MoBroHardwareMonitor/mobro_plugin_config.json
{
"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"
}
]
}
]
}