Skip to content

Commit

Permalink
📝 initial commit V0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jkharrat committed Apr 17, 2021
0 parents commit c0efd1f
Show file tree
Hide file tree
Showing 16 changed files with 1,894 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# streamDeck-weatherPlugin
Plugin for StreamDeck to display weather info
Binary file added Release/com.jk.weather.streamDeckPlugin
Binary file not shown.
41 changes: 41 additions & 0 deletions Sources/com.jk.weather.sdPlugin/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"Actions": [
{
"Icon": "resources/actionIcon",
"Name": "Weather",
"States": [
{
"Image": "resources/actionDefaultImage",
"TitleAlignment": "bottom",
"FontSize": "10"
}
],
"SupportedInMultiActions": true,
"Tooltip": "Get current weather",
"UUID": "com.jk.weather.action"
}
],
"SDKVersion": 2,
"Author": "Jaouher",
"CodePath": "plugin/main.html",
"Description": "Easily get a preview about the weather",
"Name": "Weather",
"Icon": "resources/pluginIcon",
"PropertyInspectorPath": "pi/main_pi.html",
"URL": "https://jk.com",
"Version": "2.0",
"OS": [
{
"Platform": "mac",
"MinimumVersion" : "10.11"
},
{
"Platform": "windows",
"MinimumVersion" : "10"
}
],
"Software":
{
"MinimumVersion" : "4.1"
}
}
3 changes: 3 additions & 0 deletions Sources/com.jk.weather.sdPlugin/pi/caret.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions Sources/com.jk.weather.sdPlugin/pi/main_pi.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<title>com.jk.weather.pi</title>
<link rel="stylesheet" href="sdpi.css">
<script src="main_pi.js"></script>
</head>

<body>
<div class="sdpi-wrapper hidden">
<div class="sdpi-item">
<div class="sdpi-item-label">API Key</div>
<input class="sdpi-item-value" id="apiKey" value="" onchange="updateApiKey()" placeholder="Enter your WeatherApi Key">
</div>
<div class="sdpi-item">
<div class="sdpi-item-label">City Name</div>
<input class="sdpi-item-value" id="cityName" value="" onchange="updateCityName()" placeholder="Enter the city for the current weather details">
</div>
<div class="sdpi-item">
<button class="sdpi-item-value" onclick="openPage('weatherapi.com/my/')">Get my API key</button>
<button class="sdpi-item-value" onclick="openPage('github.com/JaouherK/streamDeck-weatherPlugin')">GitHub</button>
</div>
</div>
</body>

</html>
100 changes: 100 additions & 0 deletions Sources/com.jk.weather.sdPlugin/pi/main_pi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
let websocket = null,
uuid = null,
actionInfo = {};

function connectElgatoStreamDeckSocket(inPort, inPropertyInspectorUUID, inRegisterEvent, inInfo, inActionInfo) {

uuid = inPropertyInspectorUUID;
actionInfo = JSON.parse(inActionInfo);

websocket = new WebSocket('ws://localhost:' + inPort);

websocket.onopen = function()
{
// WebSocket is connected, register the Property Inspector
let json = {
"event": inRegisterEvent,
"uuid": inPropertyInspectorUUID
};
websocket.send(JSON.stringify(json));

json = {
"event": "getSettings",
"context": uuid,
};
websocket.send(JSON.stringify(json));

json = {
"event": "getGlobalSettings",
"context": uuid,
};
websocket.send(JSON.stringify(json));
};

websocket.onmessage = function (evt) {
// Received message from Stream Deck
const jsonObj = JSON.parse(evt.data);
if (jsonObj.event === 'didReceiveSettings') {
const payload = jsonObj.payload.settings;

document.getElementById('cityName').value = payload.cityName;

if(document.getElementById('cityName').value === "undefined") {
document.getElementById('cityName').value = "";
}
}
if (jsonObj.event === 'didReceiveGlobalSettings') {
const payload = jsonObj.payload.settings;

document.getElementById('apiKey').value = payload.apiKey;

if(document.getElementById('apiKey').value === "undefined") {
document.getElementById('apiKey').value = "";
}

const el = document.querySelector('.sdpi-wrapper');
el && el.classList.remove('hidden');
}
};

}

function updateCityName() {
if (websocket && (websocket.readyState === 1)) {
let payload = {};
payload.cityName = document.getElementById('cityName').value;
const json = {
"event": "setSettings",
"context": uuid,
"payload": payload
};
websocket.send(JSON.stringify(json));
console.log(json)
}
}

function updateApiKey() {
if (websocket && (websocket.readyState === 1)) {
let payload = {};
payload.apiKey = document.getElementById('apiKey').value;
const json = {
"event": "setGlobalSettings",
"context": uuid,
"payload": payload
};
websocket.send(JSON.stringify(json));
console.log(json)
}
}

function openPage(site) {
if (websocket && (websocket.readyState === 1)) {
const json = {
'event': 'openUrl',
'payload': {
'url': 'https://' + site
}
};
websocket.send(JSON.stringify(json));
}
}
Loading

0 comments on commit c0efd1f

Please sign in to comment.