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 recognizes them and handles the following tasks:

  • Exposes settings to the user.
  • Performs validation.
  • Handles persistence of settings values.
tip

Provide sensible default values for your plugin settings whenever possible.
This enables the plugin to function 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 configuration attributes outlined below:

FieldTypeDefaultRestrictionsDescription
typestring-Required
Options: checkbox, number, select, string
Type of the settings field.
namestring-Required
Length: 1–128
Pattern: ^[\\w-]+$
Key identifier for the field.
labelstring-Required
Length: 1–128
Display name for the field.
descriptionstring?-Optional tooltip or field description.
requiredbooleanfalseIndicates if the field is mandatory.

Types of Settings Fields

Below are the supported types of settings fields and their configurations:


Checkbox

A checkbox allows toggling a boolean value.

Additional Fields for Checkbox

FieldTypeDescription
defaultValueboolean?Optional default value for the field.

Number

A numeric field for number-based inputs.

Additional Fields for Number

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

String

A field for plain text or string-based inputs.

Additional Fields for String

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

Select

A dropdown menu with predefined options for user selection.

Additional Fields for Select

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

Configuration for Options in Select

FieldTypeRestrictionsDescription
labelstringRequired
Length: 1–128
Visible name of the select option.
valuestringRequired
Length: 1–128
Pattern: ^[\\w-]+$
Internal value of the select option.

Accessing Settings

To access the current values of plugin settings, use the IMoBroSettings service.
This service can be injected into your plugin constructor. For a detailed guide, see In Depth: Using Services.

Example usage of IMoBroSettings:

Plugin.cs
public class Plugin : IMoBroPlugin
{
private readonly IMoBroService _mobro;
private readonly IMoBroSettings _settings;

public Plugin(IMoBroService mobro, IMoBroSettings settings)
{
_mobro = mobro;
_settings = settings;
}

public void Init()
{
// Accessing the value of the "update_frequency" setting
var updateFrequencySetting = _settings.GetValue<int>("update_frequency");
}
}

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 combination of:
  • A number field to specify how many processes to include.
  • 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"
}
]
}
]
}