-
-
Notifications
You must be signed in to change notification settings - Fork 70
Auto populating user settings
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:
- 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
- For each setting in your class, create a public property
- 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
-
Inside your plugin implementation create an object named
settings
which is of the typePluginSettings
: -
If you followed this for all your other properties, use the
Tools.AutoPopulateSettings()
method to Auto-populate all the properties inside yourReceivedSettings
function:
public override void ReceivedSettings(ReceivedSettingsPayload payload)
{
Tools.AutoPopulateSettings(settings, payload.Settings);
}
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
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
© Copyright 2021 By BarRaider