Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
🎨
Browse files Browse the repository at this point in the history
  • Loading branch information
tobimori committed May 23, 2020
1 parent de99c11 commit b5f1dac
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 55 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
40 changes: 16 additions & 24 deletions pi/main_pi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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))
}
}))
}
52 changes: 22 additions & 30 deletions plugin/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b5f1dac

Please sign in to comment.