From b5f1dac501fa99142609626049516bd370e8d732 Mon Sep 17 00:00:00 2001 From: tobimori Date: Sat, 23 May 2020 23:47:14 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manifest.json | 2 +- pi/main_pi.js | 40 ++++++++++++++++---------------------- plugin/main.js | 52 +++++++++++++++++++++----------------------------- 3 files changed, 39 insertions(+), 55 deletions(-) diff --git a/manifest.json b/manifest.json index c6dbe27..50244c4 100644 --- a/manifest.json +++ b/manifest.json @@ -25,7 +25,7 @@ "SDKVersion": 2, "Author": "tobimori", "CodePath": "plugin/main.html", - "Description": "Hassle-free time tracking using the Elgato Stream Deck and Toggl", + "Description": "Hassle-free time tracking using the Elgato Stream Deck and Toggl.", "Name": "Toggl", "Icon": "resources/pluginIcon", "PropertyInspectorPath": "pi/main_pi.html", diff --git a/pi/main_pi.js b/pi/main_pi.js index 37b10a6..8e2f3cd 100644 --- a/pi/main_pi.js +++ b/pi/main_pi.js @@ -9,18 +9,16 @@ function connectElgatoStreamDeckSocket (inPort, inPropertyInspectorUUID, inRegis websocket.onopen = function () { // WebSocket is connected, register the Property Inspector - let json = { + websocket.send(JSON.stringify({ event: inRegisterEvent, uuid: inPropertyInspectorUUID - } - websocket.send(JSON.stringify(json)) + })) // Request settings - json = { + websocket.send(JSON.stringify({ event: 'getSettings', context: uuid - } - websocket.send(JSON.stringify(json)) + })) } websocket.onmessage = function (evt) { @@ -41,31 +39,25 @@ function connectElgatoStreamDeckSocket (inPort, inPropertyInspectorUUID, inRegis } function sendSettings () { - if (websocket && (websocket.readyState === 1)) { - const payload = { + websocket && (websocket.readyState === 1) && + websocket.send(JSON.stringify({ + event: 'setSettings', + context: uuid, + payload: { apiToken: document.getElementById('apitoken').value, activity: document.getElementById('activity').value, workspaceId: document.getElementById('wid').value, projectId: document.getElementById('pid').value } - const json = { - event: 'setSettings', - 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 && (websocket.readyState === 1) && + websocket.send(JSON.stringify({ + event: 'openUrl', + payload: { + url: 'https://' + site } - websocket.send(JSON.stringify(json)) - } + })) } diff --git a/plugin/main.js b/plugin/main.js index b7990b1..af45548 100644 --- a/plugin/main.js +++ b/plugin/main.js @@ -14,12 +14,10 @@ function connectElgatoStreamDeckSocket (inPort, inPluginUUID, inRegisterEvent, i websocket.onopen = function () { // WebSocket is connected, register the plugin - const json = { + websocket.send(JSON.stringify(json = { event: inRegisterEvent, uuid: inPluginUUID - } - - websocket.send(JSON.stringify(json)) + })) } websocket.onmessage = function (evt) { @@ -143,41 +141,35 @@ async function getCurrentEntry (apiToken = isRequired()) { // Set Button State (for Polling) function setState (context = isRequired(), state = isRequired()) { - if (websocket && (websocket.readyState === 1)) { - const json = { - event: 'setState', - context: context, - payload: { - state: state - } + websocket && (websocket.readyState === 1) && + websocket.send(JSON.stringify({ + event: 'setState', + context: context, + payload: { + state: state } - websocket.send(JSON.stringify(json)) - } + })) } // Set Button Title (for Polling) function setTitle (context = isRequired(), title = '') { - if (websocket && (websocket.readyState === 1)) { - const json = { - event: 'setTitle', - context: context, - payload: { - title: title, - target: 'both' - } + websocket && (websocket.readyState === 1) && + websocket.send(JSON.stringify({ + event: 'setTitle', + context: context, + payload: { + title: title, + target: 'both' } - websocket.send(JSON.stringify(json)) - } + })) } function showAlert (context = isRequired()) { - if (websocket && (websocket.readyState === 1)) { - const json = { - event: 'showAlert', - context: context - } - websocket.send(JSON.stringify(json)) - } + websocket && (websocket.readyState === 1) && + websocket.send(JSON.stringify({ + event: 'showAlert', + context: context + })) } // throw error when required argument is not supplied