sync icons
This commit is contained in:
@@ -11,6 +11,8 @@ const ACTION_MAP = {
|
||||
},
|
||||
};
|
||||
|
||||
let cts = [];
|
||||
|
||||
// подключение от D6
|
||||
function connectElgatoStreamDeckSocket(inPort, inUUID, inRegisterEvent, inInfo) {
|
||||
uuid = inUUID;
|
||||
@@ -24,33 +26,36 @@ function connectElgatoStreamDeckSocket(inPort, inUUID, inRegisterEvent, inInfo)
|
||||
}));
|
||||
};
|
||||
|
||||
websocket.onmessage = function (evt) {
|
||||
websocket.onmessage = async function (evt) {
|
||||
const msg = JSON.parse(evt.data);
|
||||
|
||||
const { event, action, context, payload } = msg;
|
||||
|
||||
if (event === "willAppear") {
|
||||
cts.push(context)
|
||||
|
||||
const s = (payload && payload.settings) || { isOn: false };
|
||||
ctxSettings.set(context, s);
|
||||
setState(context, s.isOn ? 1 : 0);
|
||||
// setState(context, s.isOn ? 1 : 0);
|
||||
|
||||
const cfg = ACTION_MAP[action];
|
||||
if (!cfg) return;
|
||||
|
||||
post("http://127.0.0.1:16888/press", {
|
||||
var resp = await postJson("http://127.0.0.1:16888/press", {
|
||||
actionUUID: action,
|
||||
actionId: cfg.actionId,
|
||||
toggleChanged: false,
|
||||
isOn: !s.isOn,
|
||||
});
|
||||
|
||||
setState(element, resp?.mode);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (event === "didReceiveSettings") {
|
||||
const s = payload.settings || { isOn: false };
|
||||
ctxSettings.set(context, s);
|
||||
setState(context, s.isOn ? 1 : 0);
|
||||
// setState(context, s.isOn ? 1 : 0);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -62,32 +67,37 @@ function connectElgatoStreamDeckSocket(inPort, inUUID, inRegisterEvent, inInfo)
|
||||
}
|
||||
|
||||
// обработка нажатия
|
||||
function handleKeyDown(action, context) {
|
||||
async function handleKeyDown(action, context) {
|
||||
|
||||
let s = ctxSettings.get(context) || { isOn: false };
|
||||
const prevState = s.isOn;
|
||||
|
||||
s.isOn = !s.isOn;
|
||||
const newState = s.isOn;
|
||||
|
||||
ctxSettings.set(context, s);
|
||||
|
||||
setState(context, newState ? 1 : 0);
|
||||
|
||||
websocket.send(JSON.stringify({
|
||||
event: "setSettings",
|
||||
context: context,
|
||||
payload: s
|
||||
}));
|
||||
|
||||
// setState(context, newState ? 1 : 0);
|
||||
|
||||
const cfg = ACTION_MAP[action];
|
||||
if (!cfg) return;
|
||||
|
||||
post("http://127.0.0.1:16888/press", {
|
||||
var resp = await postJson("http://127.0.0.1:16888/press", {
|
||||
actionUUID: action,
|
||||
actionId: cfg.actionId,
|
||||
toggleChanged: prevState !== newState,
|
||||
isOn: !newState,
|
||||
cts
|
||||
});
|
||||
|
||||
cts.forEach(element => {
|
||||
console.log(element)
|
||||
setState(element, resp?.mode);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -101,10 +111,12 @@ function setState(context, stateIndex) {
|
||||
}
|
||||
|
||||
// HTTP POST
|
||||
function post(url, data) {
|
||||
fetch(url, {
|
||||
async function postJson(url, data) {
|
||||
const res = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(data)
|
||||
}).catch(err => console.error(err));
|
||||
});
|
||||
if (!res.ok) throw new Error("HTTP " + res.status);
|
||||
return await res.json();
|
||||
}
|
||||
@@ -4,10 +4,10 @@
|
||||
"Description": "D6 plugin: button -> HTTP POST to localhost",
|
||||
"Icon": "icon",
|
||||
"Name": "HTTP Keys",
|
||||
"Version": "0.1.0",
|
||||
"Version": "0.2.0",
|
||||
"SDKVersion": 2,
|
||||
"OS": [
|
||||
{ "Platform": "windows", "MinimumVersion": "10" }
|
||||
{ "Platform": "windows", "MinimumVersion": "11" }
|
||||
],
|
||||
"Software": { "MinimumVersion": "1.0" },
|
||||
"Category": "Utilities",
|
||||
@@ -26,6 +26,16 @@
|
||||
"TitleAlignment": "middle",
|
||||
"FontSize": "12"
|
||||
},
|
||||
{
|
||||
"Image": "icons/any_off",
|
||||
"TitleAlignment": "middle",
|
||||
"FontSize": "12"
|
||||
},
|
||||
{
|
||||
"Image": "icons/ts_off",
|
||||
"TitleAlignment": "middle",
|
||||
"FontSize": "12"
|
||||
},
|
||||
{
|
||||
"Image": "icons/micro_off",
|
||||
"TitleAlignment": "middle",
|
||||
@@ -45,6 +55,16 @@
|
||||
"TitleAlignment": "middle",
|
||||
"FontSize": "12"
|
||||
},
|
||||
{
|
||||
"Image": "icons/groupmicro_on",
|
||||
"TitleAlignment": "middle",
|
||||
"FontSize": "12"
|
||||
},
|
||||
{
|
||||
"Image": "icons/groupmicro_off",
|
||||
"TitleAlignment": "middle",
|
||||
"FontSize": "12"
|
||||
},
|
||||
{
|
||||
"Image": "icons/groupmicro_off",
|
||||
"TitleAlignment": "middle",
|
||||
|
||||
Reference in New Issue
Block a user