diff --git a/.gitignore b/.gitignore index 90b5e37..3edd58f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,11 @@ .DS_Store .idea/** /src/DistributionTool -com.elgato.template.streamDeckPlugin +net.forgeserv.api.streamDeckPlugin .vscode/** package.json package-lock.json .history __exclude .editorconfig +DistributionTool.exe diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..592d812 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "src/my.domain.plugin-name/libs"] + path = src/my.domain.plugin-name/libs + url = https://github.com/elgatosf/streamdeck-javascript-sdk +[submodule "src/net.forgeserv.api/libs"] + path = src/net.forgeserv.api/libs + url = https://github.com/elgatosf/streamdeck-javascript-sdk diff --git a/src/com.elgato.template.sdPlugin/actions/template/action.sketch b/src/com.elgato.template.sdPlugin/actions/template/action.sketch deleted file mode 100644 index 8e2df7a..0000000 Binary files a/src/com.elgato.template.sdPlugin/actions/template/action.sketch and /dev/null differ diff --git a/src/com.elgato.template.sdPlugin/actions/template/assets/action.svg b/src/com.elgato.template.sdPlugin/actions/template/assets/action.svg deleted file mode 100644 index 25ed235..0000000 --- a/src/com.elgato.template.sdPlugin/actions/template/assets/action.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/com.elgato.template.sdPlugin/actions/template/assets/actionImage.svg b/src/com.elgato.template.sdPlugin/actions/template/assets/actionImage.svg deleted file mode 100644 index c973853..0000000 --- a/src/com.elgato.template.sdPlugin/actions/template/assets/actionImage.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/com.elgato.template.sdPlugin/actions/template/property-inspector/inspector.html b/src/com.elgato.template.sdPlugin/actions/template/property-inspector/inspector.html deleted file mode 100644 index 13d5a46..0000000 --- a/src/com.elgato.template.sdPlugin/actions/template/property-inspector/inspector.html +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - - - - com.elgato.template Property Inspector - - - - -
-
-
-
-
Inputs
-
Text
-
-
-
-
-
-
-
Name
- -
- -
-
Message
-
- -
-
-
-
-
-
More
- -
-
-
-
-
Button
- -
-
- - - - - - - - - - - - - - - - - - diff --git a/src/com.elgato.template.sdPlugin/actions/template/property-inspector/inspector.js b/src/com.elgato.template.sdPlugin/actions/template/property-inspector/inspector.js deleted file mode 100644 index 214fe49..0000000 --- a/src/com.elgato.template.sdPlugin/actions/template/property-inspector/inspector.js +++ /dev/null @@ -1,96 +0,0 @@ -/// -/// - -$PI.onConnected((jsn) => { - const form = document.querySelector('#property-inspector'); - const {actionInfo, appInfo, connection, messageType, port, uuid} = jsn; - const {payload, context} = actionInfo; - const {settings} = payload; - - Utils.setFormValue(settings, form); - - form.addEventListener( - 'input', - Utils.debounce(150, () => { - const value = Utils.getFormValue(form); - $PI.setSettings(value); - }) - ); -}); - -$PI.onDidReceiveGlobalSettings(({payload}) => { - console.log('onDidReceiveGlobalSettings', payload); -}) - -/** - * Provide window level functions to use in the external window - * (this can be removed if the external window is not used) - */ -window.sendToInspector = (data) => { - console.log(data); -}; - -document.querySelector('#open-external').addEventListener('click', () => { - window.open('../../../external.html'); -}); - - -/** - * TABS - * ---- - * - * This will make the tabs interactive: - * - clicking on a tab will make it active - * - clicking on a tab will show the corresponding content - * - clicking on a tab will hide the content of all other tabs - * - a tab must have the class "tab" - * - a tab must have a data-target attribute that points to the id of the content - * - the content must have the class "tab-content" - * - the content must have an id that matches the data-target attribute of the tab - * - *
Inputs
- *
Text
- * a complete tab-example can be found in the index.html -
-
-
-
Inputs
-
Text
-
-
-
- * You can use the code below to activate the tabs (`activateTabs` and `clickTab` are required) - */ - -function activateTabs(activeTab) { - const allTabs = Array.from(document.querySelectorAll('.tab')); - let activeTabEl = null; - allTabs.forEach((el, i) => { - el.onclick = () => clickTab(el); - if(el.dataset?.target === activeTab) { - activeTabEl = el; - } - }); - if(activeTabEl) { - clickTab(activeTabEl); - } else if(allTabs.length) { - clickTab(allTabs[0]); - } -} - -function clickTab(clickedTab) { - const allTabs = Array.from(document.querySelectorAll('.tab')); - allTabs.forEach((el, i) => el.classList.remove('selected')); - clickedTab.classList.add('selected'); - activeTab = clickedTab.dataset?.target; - allTabs.forEach((el, i) => { - if(el.dataset.target) { - const t = document.querySelector(el.dataset.target); - if(t) { - t.style.display = el == clickedTab ? 'block' : 'none'; - } - } - }); -} - -activateTabs(); diff --git a/src/com.elgato.template.sdPlugin/app.html b/src/com.elgato.template.sdPlugin/app.html deleted file mode 100644 index 4c51a9f..0000000 --- a/src/com.elgato.template.sdPlugin/app.html +++ /dev/null @@ -1,29 +0,0 @@ - - - - - com.elgato.template - - - - - - - - - - - - - - - - - - - - diff --git a/src/com.elgato.template.sdPlugin/app.js b/src/com.elgato.template.sdPlugin/app.js deleted file mode 100644 index e39743c..0000000 --- a/src/com.elgato.template.sdPlugin/app.js +++ /dev/null @@ -1,19 +0,0 @@ -/// -/// - -const myAction = new Action('com.elgato.template.action'); - -/** - * The first event fired when Stream Deck starts - */ -$SD.onConnected(({ actionInfo, appInfo, connection, messageType, port, uuid }) => { - console.log('Stream Deck connected!'); -}); - -myAction.onKeyUp(({ action, context, device, event, payload }) => { - console.log('Your key code goes here!'); -}); - -myAction.onDialRotate(({ action, context, device, event, payload }) => { - console.log('Your dial code goes here!'); -}); diff --git a/src/com.elgato.template.sdPlugin/de.json b/src/com.elgato.template.sdPlugin/de.json deleted file mode 100644 index 67059df..0000000 --- a/src/com.elgato.template.sdPlugin/de.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "Description": "Nimm diese Vorlage für dein erstes Plugin", - "Name": "Stream Deck Template", - "Category": "Templates", - "com.elgato.template.action": { - "Name": "Action", - "Tooltip": "Dies ist die einzige 'Action' in diesem Template" - }, - "Localization": { - "More info": "Mehr Infos", - "Message": "Nachricht", - "Click Me": "Klicke mich", - "Button": "Taste", - "More": "Mehr", - "My name": "Mein Name", - "My title": "Mein Titel", - "My message": "Meine Nachricht", - "My button": "Meine Taste" - - } -} diff --git a/src/com.elgato.template.sdPlugin/en.json b/src/com.elgato.template.sdPlugin/en.json deleted file mode 100644 index 7b43e58..0000000 --- a/src/com.elgato.template.sdPlugin/en.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "Description": "Use this to create your own plugin", - "Name": "Stream Deck Template", - "Category": "Templates", - "com.elgato.template.action": { - "Name": "Action", - "Tooltip": "This is the only action in this plugin" - }, - "Localization": { - "More info": "More info", - "Message": "Message", - "Click Me": "Click Me", - "Button": "Button", - "More": "More", - "My name": "My name", - "My title": "My title", - "My message": "My message", - "My button": "My button" - } -} diff --git a/src/com.elgato.template.sdPlugin/external.html b/src/com.elgato.template.sdPlugin/external.html deleted file mode 100644 index 643dc1d..0000000 --- a/src/com.elgato.template.sdPlugin/external.html +++ /dev/null @@ -1,72 +0,0 @@ - - - - com.elgato.template.externalWindow - - - - - - -
-
INFORMATION
-
-

- In your external window you can either place your own - designs, or simply use the built-in sdpi.css to style your - content. -

-
- -
- -

- Clicking the button sends some information to your Property - Inspector. Just open the remote-debugger for your Property - Inspector and watch the console. -

-
-
- - - - diff --git a/src/com.elgato.template.sdPlugin/external.js b/src/com.elgato.template.sdPlugin/external.js deleted file mode 100644 index f0621f3..0000000 --- a/src/com.elgato.template.sdPlugin/external.js +++ /dev/null @@ -1,5 +0,0 @@ -window.onload = () => { - document.querySelector('#send').addEventListener('click', () => { - window.opener.sendToInspector('Message from external window.'); - }); -}; diff --git a/src/com.elgato.template.sdPlugin/manifest.json b/src/com.elgato.template.sdPlugin/manifest.json deleted file mode 100644 index dddc94f..0000000 --- a/src/com.elgato.template.sdPlugin/manifest.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - "SDKVersion": 2, - "Author": "Elgato Systems", - "CodePath": "app.html", - "Description": "Example description", - "Name": "Stream Deck Template", - "Icon": "actions/template/assets/action", - "URL": "https://www.elgato.com/en/gaming/stream-deck", - "Version": "1.0.2", - "Software": { - "MinimumVersion": "5.0" - }, - "OS": [ - { - "Platform": "mac", - "MinimumVersion": "10.11" - }, - { - "Platform": "windows", - "MinimumVersion": "10" - } - ], - "Category": "Template Plugin", - "CategoryIcon": "actions/template/assets/actionimage", - "Actions": [ - { - "Icon": "actions/template/assets/actionimage", - "Name": "Example Action", - "Controllers": ["Keypad", "Encoder"], - "Encoder": { - "layout": "$B1", - "TriggerDescription": { - "Rotate": "Describe the rotation", - "Push": "Describe the encoder push", - "Touch": "Describe the touch", - "LongTouch": "Describe the long touch" - } - }, - "States": [ - { - "Image": "actions/template/assets/action" - } - ], - "Tooltip": "This is an example tooltip", - "UUID": "com.elgato.template.action", - "PropertyInspectorPath": "actions/template/property-inspector/inspector.html" - } - ] -} diff --git a/src/net.forgeserv.api.sdPlugin/actionIcon.png b/src/net.forgeserv.api.sdPlugin/actionIcon.png new file mode 100644 index 0000000..f0e6c87 Binary files /dev/null and b/src/net.forgeserv.api.sdPlugin/actionIcon.png differ diff --git a/src/net.forgeserv.api.sdPlugin/actionIcon@2x.png b/src/net.forgeserv.api.sdPlugin/actionIcon@2x.png new file mode 100644 index 0000000..f0e6c87 Binary files /dev/null and b/src/net.forgeserv.api.sdPlugin/actionIcon@2x.png differ diff --git a/src/net.forgeserv.api.sdPlugin/actions/api/property-inspector/inspector.html b/src/net.forgeserv.api.sdPlugin/actions/api/property-inspector/inspector.html new file mode 100644 index 0000000..e5f3559 --- /dev/null +++ b/src/net.forgeserv.api.sdPlugin/actions/api/property-inspector/inspector.html @@ -0,0 +1,53 @@ + + + + + + + + + net.forgeserv.api Property Inspector + + + + +
+
+
+
+
+
Server Index
+ +
+ +
+
Refresh Frequency (Seconds)
+ +
+ +
+
Reset Timeout (Seconds)
+ +
+
+
+
+ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/net.forgeserv.api.sdPlugin/actions/api/property-inspector/inspector.js b/src/net.forgeserv.api.sdPlugin/actions/api/property-inspector/inspector.js new file mode 100644 index 0000000..0017af6 --- /dev/null +++ b/src/net.forgeserv.api.sdPlugin/actions/api/property-inspector/inspector.js @@ -0,0 +1,33 @@ +/// +/// + +$PI.onConnected((jsn) => { + const form = document.querySelector('#property-inspector'); + const { actionInfo, appInfo, connection, messageType, port, uuid } = jsn; + const { payload, context } = actionInfo; + const { settings } = payload; + + Utils.setFormValue(settings, form); + + form.addEventListener( + 'input', + Utils.debounce(150, () => { + const value = Utils.getFormValue(form); + $PI.setSettings(value); + $PI.sendToPlugin({ value }); + }) + ); +}); + +$PI.onDidReceiveGlobalSettings(({ payload }) => { + console.log('onDidReceiveGlobalSettings', payload); +}); + +/** + * Provide window level functions to use in the external window + * (this can be removed if the external window is not used) + */ +window.sendToInspector = (data) => { + console.log(data); +}; + diff --git a/src/net.forgeserv.api.sdPlugin/app.html b/src/net.forgeserv.api.sdPlugin/app.html new file mode 100644 index 0000000..b326f8e --- /dev/null +++ b/src/net.forgeserv.api.sdPlugin/app.html @@ -0,0 +1,29 @@ + + + + + net.forgeserv.api + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/net.forgeserv.api.sdPlugin/app.js b/src/net.forgeserv.api.sdPlugin/app.js new file mode 100644 index 0000000..15e1156 --- /dev/null +++ b/src/net.forgeserv.api.sdPlugin/app.js @@ -0,0 +1,139 @@ +/// +/// + +const myAction = new Action('net.forgeserv.api.action'); + +const UNSET = -1; +const preferencesByCtx = {}; + +let overrideIndicesByCtx = {}; +// Storage of the current program loop's timeout for on kill +let processTimeoutIdsByCtx = {}; +// Storage of the current timeout when _temporarily_ setting the index to something else. +let rerenderTimeoutIdsByCtx = {}; +// The current dataset -- used to prevent refetching all the time where possible. +let dataCache = []; + +/** + * Grabs the current API data, caches it, and then sets a timeout to infinitely repeat. + * @param {string} context The required Action contextId + * @returns {null} + */ +const process = async (context) => { + const resp = await fetch('https://api.forgeserv.net'); + if (resp.status != 200) return; + + dataCache = await resp.json(); + rerender(context); + + processTimeoutIdsByCtx[context] = setTimeout(() => process(context), 1000 * preferencesByCtx[context].refreshFrequency); +}; + +/** + * Parses each int value in the provided object + * @param {Object} settings + * @param {string} context The action's context + */ +const onSettingsUpdated = (settings, context) => { + const newPrefs = { + serverIdx: safeParseInt(settings.serverIdx), + resetTimeout: safeParseFloat(settings.resetTimeout), + refreshFrequency: safeParseFloat(settings.refreshFrequency), + }; + + preferencesByCtx[context] = newPrefs; + console.log(preferencesByCtx); +}; + +/** + * Re-renders the Stream Deck's button with new info + * @param {string} context The action's context + * @returns {null} + */ +const rerender = context => { + const usedIndex = overrideIndicesByCtx[context] > UNSET ? overrideIndicesByCtx[context] : clamp(preferencesByCtx[context].serverIdx); + const server = dataCache[usedIndex]; + if (!server) return; + + $SD.setFeedback(context, { + title: server.name, + value: parseInt(server.online) === 0 ? "Empty" : `${server.online} of ${server.max}`, + icon: `data:image/png;base64,${server.icon}`, + }); +}; + +/** + * Clamps a given index to be no less than 0 and no more than dataCache.length + * @param {Number} index + */ +const clamp = index => { + return index > dataCache.length - 1 ? dataCache.length - 1 : index < 0 ? 0 : index; +}; + +/** + * Returns 0 if the value is evaluated as NaN, the parsed value otherwise + * @param {Number} value + * @returns {Number} + */ +const safeParseInt = value => { + const tmp = parseInt(value); + if (Number.isNaN(tmp)) return 0; + return tmp; +}; + +/** + * Returns 0.0 if the value is evaluated as NaN, the parsed value otherwise + * @param {Number} value + * @returns {Number} + */ +const safeParseFloat = value => { + const tmp = parseFloat(value); + if (Number.isNaN(tmp)) return 0.0; + return tmp; +}; + +// BEGIN REGION: EVENT HANDLERS + +myAction.onWillAppear(({ context, payload }) => { + overrideIndicesByCtx[context] = UNSET; + processTimeoutIdsByCtx[context] = UNSET; + rerenderTimeoutIdsByCtx[context] = UNSET; + + onSettingsUpdated(payload.settings, context); + process(context); +}); + +myAction.onWillDisappear(({ context }) => { + processTimeoutIdsByCtx[context] > UNSET && clearTimeout(processTimeoutIdsByCtx[context]); + rerenderTimeoutIdsByCtx[context] > UNSET && clearTimeout(rerenderTimeoutIdsByCtx[context]); +}); + +myAction.onSendToPlugin(({ payload, context }) => { + onSettingsUpdated(payload.value, context); + rerender(context); +}); + +myAction.onDialRotate(({ payload, context }) => { + if (!payload || !payload.ticks) return; + + // It makes sense from a user perspective to start scrolling from where you are _now_ + if (overrideIndicesByCtx[context] === UNSET) { + overrideIndicesByCtx[context] = preferencesByCtx[context].serverIdx; + } + + overrideIndicesByCtx[context] = clamp(overrideIndicesByCtx[context] + payload.ticks); + rerender(context); + + if (rerenderTimeoutIdsByCtx > UNSET) { + // Don't back-queue additional "reprocesses" + clearTimeout(rerenderTimeoutIdsByCtx); + } + + rerenderTimeoutIdsByCtx[context] = setTimeout(() => { + overrideIndicesByCtx[context] = UNSET; + rerenderTimeoutIdsByCtx[context] = UNSET; + rerender(context); + }, 1000 * preferencesByCtx[context].resetTimeout); +}); + +// END REGION: EVENT HANDLERS \ No newline at end of file diff --git a/src/net.forgeserv.api.sdPlugin/en.json b/src/net.forgeserv.api.sdPlugin/en.json new file mode 100644 index 0000000..3f273a9 --- /dev/null +++ b/src/net.forgeserv.api.sdPlugin/en.json @@ -0,0 +1,9 @@ +{ + "Description": "Use this to create your own plugin", + "Name": "Stream Deck Template", + "Category": "Utilities", + "net.forgeserv.api.action": { + "Name": "ForgeServ API Status", + "Tooltip": "Made by oitsjustjose 💚" + } +} diff --git a/src/net.forgeserv.api.sdPlugin/libs b/src/net.forgeserv.api.sdPlugin/libs new file mode 160000 index 0000000..70f866e --- /dev/null +++ b/src/net.forgeserv.api.sdPlugin/libs @@ -0,0 +1 @@ +Subproject commit 70f866ee3adbb0634977ef9b8acbd44474c9d6fc diff --git a/src/net.forgeserv.api.sdPlugin/manifest.json b/src/net.forgeserv.api.sdPlugin/manifest.json new file mode 100644 index 0000000..f4f64b0 --- /dev/null +++ b/src/net.forgeserv.api.sdPlugin/manifest.json @@ -0,0 +1,49 @@ +{ + "Actions": [ + { + "Icon": "actionIcon", + "Name": "Server Status", + "States": [ + { + "Image": "actionIcon" + } + ], + "PropertyInspectorPath": "actions/api/property-inspector/inspector.html", + "SupporedInMultiActions": false, + "Tooltip": "Gets the Player Count on a given server returned by the API", + "UUID": "net.forgeserv.api.action", + "UserTitleEnabled": false, + "Controllers": ["Keypad", "Encoder"], + "Encoder": { + "layout": "$A1", + "TriggerDescription": { + "Rotate": "Scrolls between servers", + "Push": "(Does Nothing)", + "Touch": "(Does Nothing)", + "LongTouch": "(Does Nothing)" + } + } + } + ], + "SDKVersion": 2, + "Author": "oitsjustjose", + "CodePath": "app.html", + "Description": "Gets the Player Count on a given server returned by the API", + "Name": "ForgeServ API Server Status", + "Icon": "pluginIcon", + "URL": "https://oitsjustjose.com", + "Version": "1.0.0", + "OS": [ + { + "Platform": "mac", + "MinimumVersion": "10.11" + }, + { + "Platform": "windows", + "MinimumVersion": "10" + } + ], + "Software": { + "MinimumVersion": "4.1" + } +} diff --git a/src/net.forgeserv.api.sdPlugin/pluginIcon.png b/src/net.forgeserv.api.sdPlugin/pluginIcon.png new file mode 100644 index 0000000..c7f1180 Binary files /dev/null and b/src/net.forgeserv.api.sdPlugin/pluginIcon.png differ diff --git a/src/net.forgeserv.api.sdPlugin/pluginIcon@2x.png b/src/net.forgeserv.api.sdPlugin/pluginIcon@2x.png new file mode 100644 index 0000000..c7f1180 Binary files /dev/null and b/src/net.forgeserv.api.sdPlugin/pluginIcon@2x.png differ