r/StreamDeckSDK • u/llamafilm • Sep 25 '20
How to initialize settings on first launch
Building my javascript plugin, when I receive willAppear event, I call getSettings. Then when I receive didReceiveSettings, I update the property inspector, etc. This works fine.
But now I am adding a multiple state button, so the first thing I want to do is initialize the current state to match the application. I could do this in the didReceiveSettings function, but I think it's inefficient, because this will be called many more times than is necessary. It only needs to run once on didAppear, not every time the settings are changed.
I tried doing it after didAppear, but it fails because the settings have not yet been received. So my question is, how can I call getSettings and wait for the response? Example:
onDidAppear: function(context, state) {
getSettings(context);
....wait here...
...code to query state of external application...
if (current_state != settings['state' + state]) {
setState(context, 0)
}
}
0
u/BarRaider Sep 26 '20
didReceiveSettings will be called every time settings are modified from the Property Inspector, so you do want to listen to it and react accordingly. The willAppear event is the one you should use for getting both the existing settings OR setting default settings (if the settings field in the payload is empty).
If you need more help you can head over to the developers chat we have on Discord. http://discord.barraider.com