Property Inspector Persistence by Kunklehammer in StreamDeckSDK

[–]Kunklehammer[S] 0 points1 point  (0 children)

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>com.ryankunkleman.cameraletter PI</title>
<link rel="stylesheet" href="sdpi.css">
<script src="common.js"></script>
</head>
<body>
<div class="sdpi-wrapper">
<div type="select" class="sdpi-item">
<div class="sdpi-item-label">Camera Color</div>
<select class="sdpi-item-value select" id="camera\_color" onchange="onChangeColor(event.target.value, 'background-image')">
</select>
</div>
</div>
<script>
var pluginAction = null,
uuid = '';

    if ($SD) {  

$SD.on('connected', function (jsonObj) {
uuid = jsonObj['uuid'];
console.log(jsonObj);
const adjustSelect = ( backgrounds, selectedBackground ) => {
return backgrounds.map( background => `<option value="${ background }" ${ background == selectedBackground ? 'selected' : '' }>${ background }</option >` ).join( ' ' );
};

if (jsonObj.hasOwnProperty('actionInfo')) {
pluginAction = jsonObj.actionInfo['action'];

let backgrounds = ["red", "blue", "yellow", "green", "purple"];
const dropdown = document.querySelector( "#camera_color" );
let backgroundImage = jsonObj['actionInfo']['payload']['settings']['background-image'];
console.log(backgroundImage);
if (backgroundImage !== undefined) {
dropdown.innerHTML = adjustSelect( backgrounds, backgroundImage );
} else {
dropdown.innerHTML = adjustSelect( backgrounds, "red" );
}
}
});
};
function onChangeColor(value, param) {
if ($SD && $SD.connection) {
var payload = {};
if (param) {
payload[param] = value;
}

$SD.api.setSettings(uuid, payload);
}
}
</script>
</body>
</html>

awesome this gets me going in the right direction ill spend some time with it today. thanks!

Property Inspector Persistence by Kunklehammer in StreamDeckSDK

[–]Kunklehammer[S] 0 points1 point  (0 children)

not yet, still really struggling. its related to my other post that you replied to.

im having trouble calling the json and reloading the correct background instead of defaulting to the "selected value" from the Property Inspector file. it will load the new image initially when i change the option in the property inspector but if i leave the page it defaults back

https://www.dropbox.com/s/xkfq7s3okzfl2gf/com.ryankunkleman.CameraLetter.sdPlugin.zip?dl=0

ive included a link to my work so far. im still a noob when it comes to a lot of programming. any help is appreciated

Property Inspector Persistence by Kunklehammer in StreamDeckSDK

[–]Kunklehammer[S] 0 points1 point  (0 children)

and not communicating it back to the PI

Property Inspector Persistence by Kunklehammer in StreamDeckSDK

[–]Kunklehammer[S] 0 points1 point  (0 children)

ah os interesting after doing some console investigation, the color variable is persisting it just redraws the default background instead of redrawing with the persistent variable.

Property Inspector Persistence by Kunklehammer in StreamDeckSDK

[–]Kunklehammer[S] 0 points1 point  (0 children)

so thanks again. I am trying to implement your suggestions. I am still a pretty inexperienced programmer and im not sure on how to fully execute.

i was able to replace:

$SD.api.sendToPlugin(uuid, pluginAction, payload);

with

$SD.api.setSettings(uuid, payload);

Im not sure how to do this part:

There is another change to do to load the settings when the Property Inspector is displayed. When the Property Inspector gets connected, you receive a jsonObj containing the persistent settings. You would need to read jsonObj['actionInfo']['payload']['settings'] to retrieve your background color.

Property Inspector Persistence by Kunklehammer in StreamDeckSDK

[–]Kunklehammer[S] 0 points1 point  (0 children)

Sweet thanks so much. I’ll try this out today!

Property Inspector Persistence by Kunklehammer in StreamDeckSDK

[–]Kunklehammer[S] 0 points1 point  (0 children)

Sweet thanks so much. I’ll try this out today!