From 230efd7729a71d8654cde788e23878d09d1fb6bd Mon Sep 17 00:00:00 2001 From: jkharrat Date: Sun, 25 Apr 2021 20:16:49 +0200 Subject: [PATCH] :arrow_up: Fix default selection of dropdown items v2.0.2 --- Release/com.jk.weather.streamDeckPlugin | Bin 61476 -> 61550 bytes Sources/com.jk.weather.sdPlugin/manifest.json | 2 +- Sources/com.jk.weather.sdPlugin/pi/main_pi.js | 88 ++++++------- .../com.jk.weather.sdPlugin/plugin/main.js | 119 +++++++++--------- 4 files changed, 98 insertions(+), 111 deletions(-) diff --git a/Release/com.jk.weather.streamDeckPlugin b/Release/com.jk.weather.streamDeckPlugin index 428b5d053003322f8703c47b5d98739ece600ede..acd5bd28071381c56c01c2bb7fb95eab56a3dd3e 100644 GIT binary patch delta 3276 zcmY+Gc_36>8^FiRSW<&9b~Vb@knBsAY@sZ}D9Kh)$iAkhN(D%-k3PzHGZxL$F~S#~w2r>AFI z$KH2&X-6q%>ff1DS#QqP$R$vzn>hnZv3b?wYmwE(Gs3R}y#loBv7I5AdN@*LlRD~S zHT5F${@rsrXvSm-L&=jDWaoiT1?vSj5BVoq5pXR<$54QSL!(aFOj9RXYJl5&O7KL1 z!E?!*Z1ZOkySwD2%E*6U}%sp+$XE>7EB&cHHJH;c5gt{EC!u|dyR zQ{_NZu;P2g5icg$B?`%ACC<-L>icX@#Aub~rt#voz%V zJIqcdbc<67S!G}|`n=Funhk5Z-|^|GjLG;<_Vr~?{)ZhaB@bj`HOJgz$yjTX(kG~W zu(>faOXmfcXBPtqqz(mv{#AA~=pQ0T*PXmQW!&6lh{<3#D5L=Y>xWPQtW3SfWsfxT zE&&{g`L%NWpDGXeEe$w!E5A68bsR$~=ayU+MWy5Tb@q29fpOEpl)!HyHE`O-Ms{Iu zTdGp;izCOWUMBja1^}Z^y=ci380_kr#m#lpcw)-Ku!}x?ku-bGiy{a`UW{2%jsRmo zDBDcCqG3>W{X^0ZC~!rL%Ut|1OD?|o(#w}P|J^QFZ?-aC#tPwQE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KOubp=gT1gWF3NQ$C67(}~G8JL}-||5qp+5vg#w+sJJn`!y&UHDk z8T?o1xqgzDoW?KGg8uRH{+WMI{Xo|G1u&lsFel9iFl?|Q$UhG3-$fJtWB+}N!~Ytg zfZGN=f?P-J-&NrImswSjoCGIOxxxDDiMuzrz@5J(1PKn%Y>I<<(7zlA5+hKGW(0i5 zlAP&Z5-l)bN(D@iWh2i&vIdy$&Y$okkVujS=Rf requestSending(context, cityName, unit), frequency); } } - } else if (jsonObj['event'] === "didReceiveGlobalSettings") { - if (jsonObj.payload.settings != null && jsonObj.payload.settings.hasOwnProperty('apiKey')) { + } else if (jsonObj["event"] === "didReceiveGlobalSettings") { + if (jsonObj.payload.settings != null && jsonObj.payload.settings.hasOwnProperty("apiKey")) { apiKey = jsonObj.payload.settings["apiKey"]; } - } else if (jsonObj['event'] === "keyDown") { + } else if (jsonObj["event"] === "keyDown") { const json = { - "event": "getGlobalSettings", - "context": pluginUUID + event: "getGlobalSettings", + context: pluginUUID }; websocket.send(JSON.stringify(json)); @@ -69,76 +69,77 @@ function connectElgatoStreamDeckSocket(inPort, inPluginUUID, inRegisterEvent, in function requestSending(context, cityName, unit) { const request = new XMLHttpRequest(); - request.open("GET", 'https://api.weatherapi.com/v1/current.json?key=' + apiKey + '&q=' + cityName + '&aqi=no'); + request.open("GET", "https://api.weatherapi.com/v1/current.json?key=" + apiKey + "&q=" + cityName + "&aqi=no"); request.send(); request.onreadystatechange = function () { if (request.readyState === XMLHttpRequest.DONE) { if (request.status === 200) { const response = JSON.parse(request.responseText); let temperature = ""; - if (unit === 'celsius') { + if (unit === "celsius") { temperature = response.current.temp_c ? response.current.temp_c + "°C" : "NaN"; } - if (unit === 'fahrenheit') { + if (unit === "fahrenheit") { temperature = response.current.temp_f ? response.current.temp_f + "°F" : "NaN"; } - let json = { - "event": "setTitle", - "context": context, - "payload": { - "title": "" + temperature, - "target": 1 + let jsonDeck = { + event: "setTitle", + context, + payload: { + title: temperature, + target: 1 } }; - websocket.send(JSON.stringify(json)); + websocket.send(JSON.stringify(jsonDeck)); - let json2 = { - "event": "setTitle", - "context": context, - "payload": { - "title": "" + cityName, - "target": 2 + let jsonSoftware = { + event: "setTitle", + context: context, + payload: { + title: cityName, + target: 2 } }; - websocket.send(JSON.stringify(json2)); - - function toDataURL(url, callback) { - let xhr = new XMLHttpRequest(); - xhr.onload = function () { - let reader = new FileReader(); - reader.onloadend = function () { - callback(reader.result); - } - reader.readAsDataURL(xhr.response); - }; - xhr.open('GET', url); - xhr.responseType = 'blob'; - xhr.send(); - } + websocket.send(JSON.stringify(jsonSoftware)); if (response.current.condition.icon != null) { - toDataURL("https:" + response.current.condition.icon, function (dataUrl) { - let json = { - "event": "setImage", - "context": context, - "payload": { - "image": '' + dataUrl, - "target": 1 - } - }; - - websocket.send(JSON.stringify(json)); - }) + toDataURL( + "https:" + response.current.condition.icon, + (dataUrl) => { + let json = { + event: "setImage", + context, + payload: { + image: dataUrl, + target: 1 + } + }; + websocket.send(JSON.stringify(json)); + }) } } else { const json = { - "event": "showAlert", - "context": context, + event: "showAlert", + context, }; websocket.send(JSON.stringify(json)); } } } } + +function toDataURL(url, callback) { + let xhr = new XMLHttpRequest(); + xhr.onload = function () { + let reader = new FileReader(); + reader.onloadend = function () { + callback(reader.result); + } + reader.readAsDataURL(xhr.response); + }; + xhr.open("GET", url); + xhr.responseType = "blob"; + xhr.send(); +}