Skip to content

Auto populating user settings

BarRaider edited this page Mar 24, 2021 · 4 revisions

By following a very basic convention, the StreamDeck-Tools can handle populating all the settings between the PropertyInspector and your plugin. All the Stream-Deck Tools samples use this convention so you can see it in the samples too:

  1. In your Plugin create a private class that will hold your plugin's settings. In the samples and in this example, we will call the private class PluginSettings
  2. For each setting in your class, create a public property
  3. For each one of the public properties add a JsonPropery attribute. The PropertyName field should be identical to the name of the setting's field/Id in the PropertyInspector's payload.
private class PluginSettings
{
    [JsonProperty(PropertyName = "title")]
    public String Title { get; set; }
}

In the example above, we created a property named Title, and added a JsonProperty attribute with the PropertyName of title. This means in our Payload we should have a field with the name title

  1. Inside your plugin implementation create an object named settings which is of the type PluginSettings:

  2. If you followed this for all your other properties, use the Tools.AutoPopulateSettings() method to Auto-populate all the properties inside your ReceivedSettings function:

public override void ReceivedSettings(ReceivedSettingsPayload payload) 
{
    Tools.AutoPopulateSettings(settings, payload.Settings);
}

Full Example:

public class MyPlugin : PluginBase
{
    private class PluginSettings
    {
        [JsonProperty(PropertyName = "title")]
        public String Title { get; set; }
    }

    private PluginSettings settings;

    ...
    ...

    public override void ReceivedSettings(ReceivedSettingsPayload payload) 
    {
        Tools.AutoPopulateSettings(settings, payload.Settings);
    }

You settings object should now auto-update every time a user changes settings in the Property Inspector

Receiving file names from the Property Inspector

If you're using the filepicker, it's a little bit trickier to get the file name from the Property Inspector. Luckily, we simplified that too. See the next section for details.

Next Topic: Receiving a filename