initial commit
6
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
.DS_Store
|
||||||
|
.idea/**
|
||||||
|
/src/DistributionTool
|
||||||
|
/src/DistributionTool
|
||||||
|
com.elgato.template.streamDeckPlugin
|
||||||
|
.vscode/**
|
||||||
49
README.md
|
|
@ -1,2 +1,47 @@
|
||||||
# streamdeck-plugin-template
|
|
||||||
A starting place for a new JavaScript Stream Deck plugin.
|
# Stream Deck Plugin Template
|
||||||
|
|
||||||
|
The `Stream Deck Plugin Template` is a template to let you get started quickly when writing a JavaScript plugin for [Stream Deck](https://developer.elgato.com/documentation/stream-deck/). `Stream Deck Plugin Template` requires Stream Deck 5.0 or later.
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
`Stream Deck Plugin Template` is a complete plugin that shows you how to
|
||||||
|
|
||||||
|
- load and save settings using Stream Deck's persistent store
|
||||||
|
- setup and communicate with the Property Inspector
|
||||||
|
- pass messages directly from Property Inspector to the plugin (and vice versa)
|
||||||
|
- localize your Property Inspector's UI to another language
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- code written in Javascript
|
||||||
|
- cross-platform (macOS, Windows)
|
||||||
|
- localization support
|
||||||
|
- styled [Property Inspector](https://developer.elgato.com/documentation/stream-deck/sdk/property-inspector/) included
|
||||||
|
- Property Inspector contains all required boilerplate code to let you instantly work on your plugin's code.
|
||||||
|
|
||||||
|
## Quick Start Guide
|
||||||
|
|
||||||
|
A short guide to help you getting started quickly.
|
||||||
|
|
||||||
|
### Clone the repo
|
||||||
|
|
||||||
|
```git clone https://github.com/elgatosf/streamdeck-plugin-template```
|
||||||
|
|
||||||
|
### Replace Name
|
||||||
|
|
||||||
|
`com.elgato.template` with `my.domain.plugin`
|
||||||
|
|
||||||
|
### Start Coding
|
||||||
|
|
||||||
|
You can get starting in app.js!
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
streamDeck.onConnected(({actionInfo, appInfo, connection, messageType, port, uuid}) => {
|
||||||
|
const myAction = new Action('my.domain.plugin.action');
|
||||||
|
|
||||||
|
myAction.onKeyUp(({action, context, device, event, payload}) => {
|
||||||
|
console.log('Your code goes here!');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
|
||||||
BIN
src/com.elgato.template.sdPlugin/actions/template/action.sketch
Normal file
|
After Width: | Height: | Size: 5.7 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 521 B |
|
After Width: | Height: | Size: 988 B |
|
|
@ -0,0 +1,64 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta
|
||||||
|
name="viewport"
|
||||||
|
content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no,minimal-ui,viewport-fit=cover"
|
||||||
|
/>
|
||||||
|
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||||
|
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
|
||||||
|
<title>com.elgato.template Property Inspector</title>
|
||||||
|
<link rel="stylesheet" href="../../../libs/css/sdpi.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="sdpi-wrapper">
|
||||||
|
<!--TODOZ: add one of each control from pi-samples to test FormUtils & CSS -->
|
||||||
|
<form id="property-inspector">
|
||||||
|
<div class="sdpi-item">
|
||||||
|
<div data-localize class="sdpi-item-label">Name</div>
|
||||||
|
<input
|
||||||
|
class="sdpi-item-value"
|
||||||
|
name="name"
|
||||||
|
type="text"
|
||||||
|
value=""
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div type="textarea" class="sdpi-item">
|
||||||
|
<div class="sdpi-item-label up20" data-localize>
|
||||||
|
Message
|
||||||
|
</div>
|
||||||
|
<div class="sdpi-item-value textarea">
|
||||||
|
<textarea
|
||||||
|
name="message"
|
||||||
|
type="textarea"
|
||||||
|
maxlength="50"
|
||||||
|
class="three-lines"
|
||||||
|
></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="sdpi-item">
|
||||||
|
<div class="sdpi-item-label" data-localize>Button</div>
|
||||||
|
<button
|
||||||
|
class="sdpi-item-value"
|
||||||
|
value="Click Me"
|
||||||
|
data-localize
|
||||||
|
id="open-external"
|
||||||
|
>
|
||||||
|
Click Me
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="sdpi-info-label hidden" style="top: -1000" value=""></div>
|
||||||
|
<script src="../../../libs/js/utils.js"></script>
|
||||||
|
<script src="../../../libs/js/constants.js"></script>
|
||||||
|
<script src="../../../libs/js/event-handler.js"></script>
|
||||||
|
<script src="../../../libs/js/deck.js"></script>
|
||||||
|
<script src="../../../libs/js/dynamic-styles.js"></script>
|
||||||
|
<script src="inspector.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
/// <reference path="../../../libs/js/deck.js" />
|
||||||
|
/// <reference path="../../../libs/js/utils.js" />
|
||||||
|
|
||||||
|
const streamDeck = new StreamDeck();
|
||||||
|
|
||||||
|
streamDeck.onConnected((jsn) => {
|
||||||
|
streamDeck.loadLocalization('../../../');
|
||||||
|
|
||||||
|
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);
|
||||||
|
streamDeck.sendToPlugin(value, context);
|
||||||
|
streamDeck.setSettings(value);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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');
|
||||||
|
});
|
||||||
22
src/com.elgato.template.sdPlugin/app.html
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>com.elgato.template</title>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<style>
|
||||||
|
canvas {
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<script src="libs/js/constants.js"></script>
|
||||||
|
<script src="libs/js/event-handler.js"></script>
|
||||||
|
<script src="libs/js/deck.js"></script>
|
||||||
|
<script src="libs/js/action.js"></script>
|
||||||
|
<script src="app.js"></script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
19
src/com.elgato.template.sdPlugin/app.js
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
/// <reference path="libs/js/action.js" />
|
||||||
|
/// <reference path="libs/js/deck.js" />
|
||||||
|
|
||||||
|
const streamDeck = new StreamDeck();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The first event fired when Stream Deck starts
|
||||||
|
*/
|
||||||
|
streamDeck.onConnected(({actionInfo, appInfo, connection, messageType, port, uuid}) => {
|
||||||
|
const myAction = new Action('com.elgato.template.action');
|
||||||
|
|
||||||
|
myAction.onKeyUp(({action, context, device, event, payload}) => {
|
||||||
|
streamDeck.openUrl('https://developer.elgato.com/documentation/stream-deck/sdk/overview/');
|
||||||
|
|
||||||
|
console.log('Your code goes here!');
|
||||||
|
|
||||||
|
streamDeck.showOk(context);
|
||||||
|
});
|
||||||
|
});
|
||||||
15
src/com.elgato.template.sdPlugin/de.json
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
}
|
||||||
15
src/com.elgato.template.sdPlugin/en.json
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
}
|
||||||
72
src/com.elgato.template.sdPlugin/external.html
Normal file
|
|
@ -0,0 +1,72 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>com.elgato.template.externalWindow</title>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<link rel="stylesheet" href="libs/css/sdpi.css" />
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sdpi-item {
|
||||||
|
max-width: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sdpi-heading {
|
||||||
|
margin: 16px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul {
|
||||||
|
max-height: none;
|
||||||
|
}
|
||||||
|
li * {
|
||||||
|
min-height: 18px;
|
||||||
|
padding: 4px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wrap {
|
||||||
|
margin: 8px;
|
||||||
|
}
|
||||||
|
.title {
|
||||||
|
font-weight: bold;
|
||||||
|
padding-bottom: 2px;
|
||||||
|
margin-bottom: 6px;
|
||||||
|
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wrap {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="sdpi-wrapper">
|
||||||
|
<div class="sdpi-heading">INFORMATION</div>
|
||||||
|
<div class="wrap">
|
||||||
|
<p>
|
||||||
|
In your external window you can either place your own
|
||||||
|
designs, or simply use the built-in sdpi.css to style your
|
||||||
|
content.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="wrap">
|
||||||
|
<button id="send" type="button" value="Click here">
|
||||||
|
Click here
|
||||||
|
</button>
|
||||||
|
<p>
|
||||||
|
Clicking the button sends some information to your Property
|
||||||
|
Inspector. Just open the remote-debugger for your Property
|
||||||
|
Inspector and watch the console.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="external.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
5
src/com.elgato.template.sdPlugin/external.js
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
window.onload = () => {
|
||||||
|
document.querySelector('#send').addEventListener('click', () => {
|
||||||
|
window.opener.sendToInspector('Message from external window.');
|
||||||
|
});
|
||||||
|
};
|
||||||
3
src/com.elgato.template.sdPlugin/libs/assets/caret.svg
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="6" viewBox="0 0 12 6">
|
||||||
|
<polygon fill="#8E8E92" fill-rule="evenodd" points="5 4 9 0 10 1 5 6 0 1 1 0"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 171 B |
BIN
src/com.elgato.template.sdPlugin/libs/assets/check.png
Normal file
|
After Width: | Height: | Size: 234 B |
3
src/com.elgato.template.sdPlugin/libs/assets/check.svg
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="10" viewBox="0 0 12 10">
|
||||||
|
<polygon fill="#FFF" points="7.2 7.5 7.2 -1.3 8.7 -1.3 8.6 9.1 2.7 8.7 2.7 7.2" transform="rotate(37 5.718 3.896)"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 210 B |
|
|
@ -0,0 +1,24 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
|
||||||
|
<g fill="none" fill-rule="evenodd">
|
||||||
|
<path fill="#9C9C9C" fill-rule="nonzero" d="M1,5 L1,14 L14,14 L14,5 L1,5 Z M0,1 L15,1 L15,15 L0,15 L0,1 Z M14,4 L14,2 L1,2 L1,4 L14,4 Z"/>
|
||||||
|
<rect width="1" height="1" x="2" fill="#9C9C9C" fill-rule="nonzero"/>
|
||||||
|
<rect width="1" height="1" x="12" fill="#9C9C9C" fill-rule="nonzero"/>
|
||||||
|
<g transform="translate(3 7)">
|
||||||
|
<rect width="1" height="1" x="2" fill="#9C9C9C"/>
|
||||||
|
<rect width="1" height="1" fill="#666"/>
|
||||||
|
<rect width="1" height="1" x="4" fill="#9C9C9C"/>
|
||||||
|
<rect width="1" height="1" x="6" fill="#9C9C9C"/>
|
||||||
|
<rect width="1" height="1" x="8" fill="#9C9C9C"/>
|
||||||
|
<rect width="1" height="1" y="2" fill="#9C9C9C"/>
|
||||||
|
<rect width="1" height="1" x="2" y="2" fill="#9C9C9C"/>
|
||||||
|
<rect width="1" height="1" x="4" y="2" fill="#9C9C9C"/>
|
||||||
|
<rect width="1" height="1" x="6" y="2" fill="#9C9C9C"/>
|
||||||
|
<rect width="1" height="1" x="8" y="2" fill="#9C9C9C"/>
|
||||||
|
<rect width="1" height="1" y="4" fill="#9C9C9C"/>
|
||||||
|
<rect width="1" height="1" x="2" y="4" fill="#9C9C9C"/>
|
||||||
|
<rect width="1" height="1" x="4" y="4" fill="#9C9C9C"/>
|
||||||
|
<rect width="1" height="1" x="6" y="4" fill="#9C9C9C"/>
|
||||||
|
<rect width="1" height="1" x="8" y="4" fill="#666"/>
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 1.3 KiB |
|
|
@ -0,0 +1,7 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
|
||||||
|
<g fill="#9C9C9C">
|
||||||
|
<path d="M15,15 L1.77635684e-15,15 L1.77635684e-15,1 L15,1 L15,15 Z M5,7 L5,8 L6,8 L6,7 L5,7 Z M3,7 L3,8 L4,8 L4,7 L3,7 Z M7,7 L7,8 L8,8 L8,7 L7,7 Z M9,7 L9,8 L10,8 L10,7 L9,7 Z M11,7 L11,8 L12,8 L12,7 L11,7 Z M3,9 L3,10 L4,10 L4,9 L3,9 Z M5,9 L5,10 L6,10 L6,9 L5,9 Z M7,9 L7,10 L8,10 L8,9 L7,9 Z M9,9 L9,10 L10,10 L10,9 L9,9 Z M11,9 L11,10 L12,10 L12,9 L11,9 Z M3,11 L3,12 L4,12 L4,11 L3,11 Z M5,11 L5,12 L6,12 L6,11 L5,11 Z M7,11 L7,12 L8,12 L8,11 L7,11 Z M9,11 L9,12 L10,12 L10,11 L9,11 Z M11,11 L11,12 L12,12 L12,11 L11,11 Z M14,4 L14,2 L1,2 L1,4 L14,4 Z"/>
|
||||||
|
<rect width="1" height="1" x="2"/>
|
||||||
|
<rect width="1" height="1" x="12"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 764 B |
3
src/com.elgato.template.sdPlugin/libs/assets/rcheck.svg
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="6" height="6" viewBox="0 0 6 6">
|
||||||
|
<circle cx="3" cy="3" r="3" fill="#FFF"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 131 B |
1566
src/com.elgato.template.sdPlugin/libs/css/sdpi.css
Normal file
161
src/com.elgato.template.sdPlugin/libs/js/action.js
Normal file
|
|
@ -0,0 +1,161 @@
|
||||||
|
/// <reference path="constants.js" />
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class Action
|
||||||
|
* A Stream Deck plugin action, where you can register callback functions for different events
|
||||||
|
*/
|
||||||
|
class Action {
|
||||||
|
UUID;
|
||||||
|
#on = EventHandler.on;
|
||||||
|
#removeListener = EventHandler.remove;
|
||||||
|
#removeAllListeners = EventHandler.removeAll;
|
||||||
|
|
||||||
|
constructor(UUID) {
|
||||||
|
this.UUID = UUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a callback function for the didReceiveSettings event, which fires when calling getSettings
|
||||||
|
* @param {*} fn
|
||||||
|
*/
|
||||||
|
onDidReceiveSettings(fn) {
|
||||||
|
this.#on(`${this.UUID}.${DID_RECEIVE_SETTINGS}`, (jsn) => fn(jsn));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a callback function for the didReceiveGlobalSettings event, which fires when calling getGlobalSettings
|
||||||
|
* @param {*} fn
|
||||||
|
*/
|
||||||
|
onDidReceiveGlobalSettings(fn) {
|
||||||
|
this.#on(DID_RECEIVE_GLOBAL_SETTINGS, (jsn) => fn(jsn));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a callback function for the keyDown event, which fires when pressing a key down
|
||||||
|
* @param {*} fn
|
||||||
|
*/
|
||||||
|
onKeyDown(fn) {
|
||||||
|
this.#on(`${this.UUID}.${KEY_DOWN}`, (jsn) => fn(jsn));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a callback function for the keyUp event, which fires when releasing a key
|
||||||
|
* @param {*} fn
|
||||||
|
*/
|
||||||
|
onKeyUp(fn) {
|
||||||
|
this.#on(`${this.UUID}.${KEY_UP}`, (jsn) => fn(jsn));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a callback function for the willAppear event, which fires when an action appears on they key
|
||||||
|
* @param {*} fn
|
||||||
|
*/
|
||||||
|
onWillAppear(fn) {
|
||||||
|
this.#on(`${this.UUID}.${WILL_APPEAR}`, (jsn) => fn(jsn));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a callback function for the titleParametersDidChange event, which fires when a user changes the key title
|
||||||
|
* @param {*} fn
|
||||||
|
*/
|
||||||
|
onTitleParametersDidChange(fn) {
|
||||||
|
this.#on(`${this.UUID}.${TITLE_PARAMETERS_DID_CHANGE}`, (jsn) => fn(jsn));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a callback function for the deviceDidConnect event, which fires when a device is plugged in
|
||||||
|
* @param {*} fn
|
||||||
|
*/
|
||||||
|
onDeviceDidConnect(fn) {
|
||||||
|
this.#on(`${this.UUID}.${DEVICE_DID_CONNECT}`, (jsn) => fn(jsn));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a callback function for the deviceDidDisconnect event, which fires fires when a device is unplugged
|
||||||
|
* @param {*} fn
|
||||||
|
*/
|
||||||
|
onDeviceDidDisconnect(fn) {
|
||||||
|
this.#on(`${this.UUID}.${DEVICE_DID_DISCONNECT}`, (jsn) => fn(jsn));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a callback function for the applicationDidLaunch event, which fires fires when the application starts
|
||||||
|
* @param {*} fn
|
||||||
|
*/
|
||||||
|
onApplicationDidLaunch(fn) {
|
||||||
|
this.#on(`${this.UUID}.${APPLICATION_DID_LAUNCH}`, (jsn) => fn(jsn));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a callback function for the applicationDidTerminate event, which fires fires when the application exits
|
||||||
|
* @param {*} fn
|
||||||
|
*/
|
||||||
|
onApplicationDidTerminate(fn) {
|
||||||
|
this.#on(`${this.UUID}.${APPLICATION_DID_TERMINATE}`, (jsn) => fn(jsn));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a callback function for the systemDidWakeUp event, which fires fires when the computer wakes
|
||||||
|
* @param {*} fn
|
||||||
|
*/
|
||||||
|
onSystemDidWakeUp(fn) {
|
||||||
|
this.#on(`${this.UUID}.${SYSTEM_DID_WAKE_UP}`, (jsn) => fn(jsn));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a callback function for the propertyInspectorDidAppear event, which fires fires when the property inspector is displayed
|
||||||
|
* @param {*} fn
|
||||||
|
*/
|
||||||
|
onPropertyInspectorDidAppear(fn) {
|
||||||
|
this.#on(`${this.UUID}.${PROPERTY_INSPECTOR_DID_APPEAR}`, (jsn) => fn(jsn));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a callback function for the propertyInspectorDidDisappear event, which fires fires when the property inspector is closed
|
||||||
|
* @param {*} fn
|
||||||
|
*/
|
||||||
|
onPropertyInspectorDidDisappear(fn) {
|
||||||
|
this.#on(`${this.UUID}.${PROPERTY_INSPECTOR_DID_DISAPPEAR}`, (jsn) => fn(jsn));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a callback function for the sendToPlugin event, which fires fires when the property inspector uses the sendToPlugin api
|
||||||
|
* @param {*} fn
|
||||||
|
*/
|
||||||
|
onSendToPlugin(fn) {
|
||||||
|
this.#on(`${this.UUID}.${SEND_TO_PLUGIN}`, (jsn) => fn(jsn));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a callback function for the sendToPropertyInspector event, which fires fires when the plugin uses the sendToPropertyInspector api
|
||||||
|
* @param {*} fn
|
||||||
|
*/
|
||||||
|
onSendToPropertyInspector(fn) {
|
||||||
|
this.#on(`${this.UUID}.${SEND_TO_PROPERTY_INSPECTOR}`, (jsn) => fn(jsn));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the event listener
|
||||||
|
* @param eventName
|
||||||
|
*/
|
||||||
|
removeListener(eventName) {
|
||||||
|
if (!eventName) return this.#removeAllListeners(this.UUID);
|
||||||
|
if (eventName === DID_RECEIVE_GLOBAL_SETTINGS) return this.#removeListener(eventName);
|
||||||
|
return this.#removeListener(`${this.UUID}.${eventName}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
60
src/com.elgato.template.sdPlugin/libs/js/constants.js
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
const SocketErrors = {
|
||||||
|
0: 'The connection has not yet been established',
|
||||||
|
1: 'The connection is established and communication is possible',
|
||||||
|
2: 'The connection is going through the closing handshake',
|
||||||
|
3: 'The connection has been closed or could not be opened',
|
||||||
|
1000: 'Normal Closure. The purpose for which the connection was established has been fulfilled.',
|
||||||
|
1001: 'Going Away. An endpoint is "going away", such as a server going down or a browser having navigated away from a page.',
|
||||||
|
1002: 'Protocol error. An endpoint is terminating the connection due to a protocol error',
|
||||||
|
1003: "Unsupported Data. An endpoint received a type of data it doesn't support.",
|
||||||
|
1004: '--Reserved--. The specific meaning might be defined in the future.',
|
||||||
|
1005: 'No Status. No status code was actually present.',
|
||||||
|
1006: 'Abnormal Closure. The connection was closed abnormally, e.g., without sending or receiving a Close control frame',
|
||||||
|
1007: 'Invalid frame payload data. The connection was closed, because the received data was not consistent with the type of the message (e.g., non-UTF-8 [http://tools.ietf.org/html/rfc3629]).',
|
||||||
|
1008: 'Policy Violation. The connection was closed, because current message data "violates its policy". This reason is given either if there is no other suitable reason, or if there is a need to hide specific details about the policy.',
|
||||||
|
1009: 'Message Too Big. Connection closed because the message is too big for it to process.',
|
||||||
|
1010: "Mandatory Extension. Connection is terminated the connection because the server didn't negotiate one or more extensions in the WebSocket handshake.",
|
||||||
|
1011: 'Internl Server Error. Connection closed because it encountered an unexpected condition that prevented it from fulfilling the request.',
|
||||||
|
1015: "TLS Handshake. The connection was closed due to a failure to perform a TLS handshake (e.g., the server certificate can't be verified).",
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Events
|
||||||
|
*/
|
||||||
|
const DID_RECEIVE_SETTINGS = 'didReceiveSettings';
|
||||||
|
const DID_RECEIVE_GLOBAL_SETTINGS = 'didReceiveGlobalSettings';
|
||||||
|
const KEY_DOWN = 'keyDown';
|
||||||
|
const KEY_UP = 'keyUp';
|
||||||
|
const WILL_APPEAR = 'willAppear';
|
||||||
|
const TITLE_PARAMETERS_DID_CHANGE = 'titleParametersDidChange';
|
||||||
|
const DEVICE_DID_CONNECT = 'deviceDidConnect';
|
||||||
|
const DEVICE_DID_DISCONNECT = 'deviceDidDisconnect';
|
||||||
|
const APPLICATION_DID_LAUNCH = 'applicationDidLaunch';
|
||||||
|
const APPLICATION_DID_TERMINATE = 'applicationDidTerminate';
|
||||||
|
const SYSTEM_DID_WAKE_UP = 'systemDidWakeUp';
|
||||||
|
const PROPERTY_INSPECTOR_DID_APPEAR = 'propertyInspectorDidAppear';
|
||||||
|
const PROPERTY_INSPECTOR_DID_DISAPPEAR = 'propertyInspectorDidDisappear';
|
||||||
|
const SEND_TO_PLUGIN = 'sendToPlugin';
|
||||||
|
const SEND_TO_PROPERTY_INSPECTOR = 'sendToPropertyInspector';
|
||||||
|
const CONNECTED = 'connected';
|
||||||
|
const SET_IMAGE = 'setImage';
|
||||||
|
const SET_TITLE = 'setTitle';
|
||||||
|
const SET_STATE = 'setState';
|
||||||
|
const SHOW_OK = 'showOk';
|
||||||
|
const SHOW_ALERT = 'showAlert';
|
||||||
|
const OPEN_URL = 'openUrl';
|
||||||
|
const SET_GLOBAL_SETTINGS = 'setGlobalSettings';
|
||||||
|
const GET_GLOBAL_SETTINGS = 'getGlobalSettings';
|
||||||
|
const SET_SETTINGS = 'setSettings';
|
||||||
|
const GET_SETTINGS = 'getSettings';
|
||||||
|
const REGISTER_PROPERTY_INSPECTOR = 'registerPropertyInspector';
|
||||||
|
const REGISTER_PLUGIN = 'registerPlugin';
|
||||||
|
const DATA_LOCALIZE = '[data-localize]';
|
||||||
|
const LOG_MESSAGE = 'logMessage';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destination
|
||||||
|
*/
|
||||||
|
const HARDWARE_AND_SOFTWARE = 0;
|
||||||
|
const HARDWARE_ONLY = 1;
|
||||||
|
const SOFTWARE_ONLY = 2;
|
||||||
345
src/com.elgato.template.sdPlugin/libs/js/deck.js
Normal file
|
|
@ -0,0 +1,345 @@
|
||||||
|
/// <reference path="event-handler.js" />
|
||||||
|
/// <reference path="constants.js" />
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class StreamDeck
|
||||||
|
* StreamDeck object containing all required code to establish
|
||||||
|
* communication with SD-Software and the Property Inspector
|
||||||
|
*/
|
||||||
|
class StreamDeck {
|
||||||
|
#port;
|
||||||
|
#uuid;
|
||||||
|
#messageType;
|
||||||
|
#actionInfo;
|
||||||
|
#websocket;
|
||||||
|
#language;
|
||||||
|
#localization;
|
||||||
|
#appInfo;
|
||||||
|
#on = EventHandler.on;
|
||||||
|
#emit = EventHandler.emit;
|
||||||
|
#removeListener = EventHandler.remove;
|
||||||
|
#removeAllListeners = EventHandler.removeAll;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
if (StreamDeck.__instance) {
|
||||||
|
return StreamDeck.__instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
StreamDeck.__instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connect to Stream Deck
|
||||||
|
* @param port
|
||||||
|
* @param uuid
|
||||||
|
* @param messageType
|
||||||
|
* @param appInfoString
|
||||||
|
* @param actionString
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
connect([port, uuid, messageType, appInfoString, actionString]) {
|
||||||
|
this.#port = port;
|
||||||
|
this.#uuid = uuid;
|
||||||
|
this.#messageType = messageType;
|
||||||
|
this.#actionInfo = actionString ? JSON.parse(actionString) : null;
|
||||||
|
this.#appInfo = JSON.parse(appInfoString);
|
||||||
|
this.#language = this.#appInfo?.application?.language ?? null;
|
||||||
|
|
||||||
|
if (this.#websocket) {
|
||||||
|
this.#websocket.close();
|
||||||
|
this.#websocket = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.#websocket = new WebSocket('ws://127.0.0.1:' + this.#port);
|
||||||
|
|
||||||
|
this.#websocket.onopen = () => {
|
||||||
|
const json = {
|
||||||
|
event: this.#messageType,
|
||||||
|
uuid: this.#uuid,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.#websocket.send(JSON.stringify(json));
|
||||||
|
|
||||||
|
this.#emit(CONNECTED, {
|
||||||
|
connection: this.#websocket,
|
||||||
|
port: this.#port,
|
||||||
|
uuid: this.#uuid,
|
||||||
|
actionInfo: this.#actionInfo,
|
||||||
|
appInfo: this.#appInfo,
|
||||||
|
messageType: this.#messageType,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
this.#websocket.onerror = (evt) => {
|
||||||
|
const error = `WEBOCKET ERROR: ${evt}, ${evt.data}, ${SocketErrors[evt?.code]}`;
|
||||||
|
console.warn(error);
|
||||||
|
this.log(error);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.#websocket.onclose = (evt) => {
|
||||||
|
console.warn('WEBOCKET CLOSED:', SocketErrors[evt?.code]);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.#websocket.onmessage = (evt) => {
|
||||||
|
const data = evt?.data ? JSON.parse(evt.data) : {};
|
||||||
|
const {action, event} = data;
|
||||||
|
const message = action ? `${action}.${event}` : event;
|
||||||
|
|
||||||
|
if (message && message !== '') this.#emit(message, data);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write to log file
|
||||||
|
* @param message
|
||||||
|
*/
|
||||||
|
log(message) {
|
||||||
|
try {
|
||||||
|
if (this.#websocket) {
|
||||||
|
const json = {
|
||||||
|
event: LOG_MESSAGE,
|
||||||
|
payload: {
|
||||||
|
message: message,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
this.#websocket.send(JSON.stringify(json));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Websocket not defined');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the specified language json file
|
||||||
|
* @param pathPrefix
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async loadLocalization(pathPrefix) {
|
||||||
|
const manifest = await this.readJson(`${pathPrefix}${this.#language}.json`);
|
||||||
|
this.#localization = manifest['Localization'] ?? null;
|
||||||
|
|
||||||
|
if (this.#messageType === REGISTER_PROPERTY_INSPECTOR && this.#localization) {
|
||||||
|
const elements = document.querySelectorAll(DATA_LOCALIZE);
|
||||||
|
|
||||||
|
elements.forEach((element) => {
|
||||||
|
element.textContent =
|
||||||
|
this.#localization[element.textContent] ?? element.textContent;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {*} path
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
async readJson(path) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const req = new XMLHttpRequest();
|
||||||
|
req.onerror = reject;
|
||||||
|
req.overrideMimeType('application/json');
|
||||||
|
req.open('GET', path, true);
|
||||||
|
req.onreadystatechange = (response) => {
|
||||||
|
if (req.readyState === 4) {
|
||||||
|
const jsonString = response?.target?.response;
|
||||||
|
if (jsonString) {
|
||||||
|
resolve(JSON.parse(response?.target?.response));
|
||||||
|
} else {
|
||||||
|
reject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
req.send();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send JSON payload to StreamDeck
|
||||||
|
* @param context
|
||||||
|
* @param fn
|
||||||
|
* @param payload
|
||||||
|
*/
|
||||||
|
send(context, fn, payload) {
|
||||||
|
const pl = Object.assign({}, {event: fn, context: context}, payload);
|
||||||
|
this.#websocket && this.#websocket.send(JSON.stringify(pl));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request the actions's persistent data. StreamDeck does not return the data, but trigger the actions's didReceiveSettings event
|
||||||
|
* @param context
|
||||||
|
*/
|
||||||
|
getSettings(context) {
|
||||||
|
this.send(context ?? this.#uuid, GET_SETTINGS, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the actions's persistent data.
|
||||||
|
* @param payload
|
||||||
|
* @param context
|
||||||
|
*/
|
||||||
|
setSettings(payload, context) {
|
||||||
|
this.send(context ?? this.#uuid, SET_SETTINGS, {
|
||||||
|
action: StreamDeck?.actionInfo?.action,
|
||||||
|
payload: payload || {},
|
||||||
|
targetContext: StreamDeck?.actionInfo?.context,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request the plugin's persistent data. StreamDeck does not return the data, but trigger the plugin/property inspectors didReceiveGlobalSettings event
|
||||||
|
*/
|
||||||
|
getGlobalSettings() {
|
||||||
|
this.send(this.#uuid, GET_GLOBAL_SETTINGS, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the plugin's persistent data
|
||||||
|
* @param payload
|
||||||
|
*/
|
||||||
|
setGlobalSettings(payload) {
|
||||||
|
this.send(this.#uuid, SET_GLOBAL_SETTINGS, {
|
||||||
|
payload: payload,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens a URL in the default web browser
|
||||||
|
* @param urlToOpen
|
||||||
|
*/
|
||||||
|
openUrl(urlToOpen) {
|
||||||
|
this.send(this.#uuid, OPEN_URL, {
|
||||||
|
payload: {
|
||||||
|
url: urlToOpen,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send payload from the property inspector to the plugin
|
||||||
|
* @param payload
|
||||||
|
* @param context
|
||||||
|
*/
|
||||||
|
sendToPlugin(payload, context) {
|
||||||
|
this.send(
|
||||||
|
context ?? this.#uuid,
|
||||||
|
SEND_TO_PLUGIN,
|
||||||
|
{
|
||||||
|
action: StreamDeck?.actionInfo?.action,
|
||||||
|
payload: payload || {},
|
||||||
|
targetContext: StreamDeck?.actionInfo?.context,
|
||||||
|
},
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display alert triangle on actions key
|
||||||
|
* @param context
|
||||||
|
*/
|
||||||
|
showAlert(context) {
|
||||||
|
this.send(context, SHOW_ALERT, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display ok check mark on actions key
|
||||||
|
* @param context
|
||||||
|
*/
|
||||||
|
showOk(context) {
|
||||||
|
this.send(context, SHOW_OK, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the state of the actions
|
||||||
|
* @param context
|
||||||
|
* @param payload
|
||||||
|
*/
|
||||||
|
setState(context, payload) {
|
||||||
|
this.send(context, SET_STATE, {
|
||||||
|
payload: {
|
||||||
|
state: 1 - Number(payload === 0),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the title of the actions's key
|
||||||
|
* @param context
|
||||||
|
* @param title
|
||||||
|
* @param target
|
||||||
|
*/
|
||||||
|
setTitle(context, title, target) {
|
||||||
|
this.send(context, SET_TITLE, {
|
||||||
|
payload: {
|
||||||
|
title: '' + title || '',
|
||||||
|
target: target || HARDWARE_AND_SOFTWARE,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send payload to property inspector
|
||||||
|
* @param context
|
||||||
|
* @param payload
|
||||||
|
*/
|
||||||
|
sendToPropertyInspector(context, payload) {
|
||||||
|
this.send(context, SEND_TO_PROPERTY_INSPECTOR, {
|
||||||
|
action: this.#actionInfo.action,
|
||||||
|
payload: payload,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the actions key image
|
||||||
|
* @param context
|
||||||
|
* @param img
|
||||||
|
* @param target
|
||||||
|
*/
|
||||||
|
setImage(context, img, target) {
|
||||||
|
this.send(context, SET_IMAGE, {
|
||||||
|
payload: {
|
||||||
|
image: img || '',
|
||||||
|
target: target || HARDWARE_AND_SOFTWARE,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a callback function for when Stream Deck is connected
|
||||||
|
* @param {*} fn
|
||||||
|
*/
|
||||||
|
onConnected(fn) {
|
||||||
|
this.#on(CONNECTED, (jsn) => fn(jsn));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a callback function for when Stream Deck sends data to the property inspector
|
||||||
|
* @param fn
|
||||||
|
*/
|
||||||
|
onSendToPropertyInspector(fn) {
|
||||||
|
this.#on(SEND_TO_PROPERTY_INSPECTOR, (jsn) => fn(jsn));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the event listener
|
||||||
|
* @param eventName
|
||||||
|
*/
|
||||||
|
removeListener(eventName) {
|
||||||
|
if (!eventName) return this.#removeAllListeners();
|
||||||
|
return this.#removeListener(eventName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* connectElgatoStreamDeckSocket
|
||||||
|
* This is the first function StreamDeck Software calls, when
|
||||||
|
* establishing the connection to the plugin or the Property Inspector
|
||||||
|
* @param {string} port - The socket's port to communicate with StreamDeck software.
|
||||||
|
* @param {string} uuid - A unique identifier, which StreamDeck uses to communicate with the plugin
|
||||||
|
* @param {string} messageType - Identifies, if the event is meant for the property inspector or the plugin.
|
||||||
|
* @param {string} appInfoString - Information about the host (StreamDeck) application
|
||||||
|
* @param {string} actionInfo - Context is an internal identifier used to communicate to the host application.
|
||||||
|
*/
|
||||||
|
function connectElgatoStreamDeckSocket() {
|
||||||
|
new StreamDeck().connect(arguments);
|
||||||
|
}
|
||||||
70
src/com.elgato.template.sdPlugin/libs/js/dynamic-styles.js
Normal file
|
|
@ -0,0 +1,70 @@
|
||||||
|
const fadeColor = function (col, amt) {
|
||||||
|
const min = Math.min,
|
||||||
|
max = Math.max;
|
||||||
|
const num = parseInt(col.replace(/#/g, ''), 16);
|
||||||
|
const r = min(255, max((num >> 16) + amt, 0));
|
||||||
|
const g = min(255, max((num & 0x0000ff) + amt, 0));
|
||||||
|
const b = min(255, max(((num >> 8) & 0x00ff) + amt, 0));
|
||||||
|
return '#' + (g | (b << 8) | (r << 16)).toString(16).padStart(6, 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
new StreamDeck().onConnected(({ appInfo }) => {
|
||||||
|
if (appInfo?.colors) return;
|
||||||
|
const clrs = appInfo.colors;
|
||||||
|
const node = document.getElementById('#sdpi-dynamic-styles') || document.createElement('style');
|
||||||
|
if (!clrs.mouseDownColor) clrs.mouseDownColor = fadeColor(clrs.highlightColor, -100);
|
||||||
|
const clr = clrs.highlightColor.slice(0, 7);
|
||||||
|
const clr1 = fadeColor(clr, 100);
|
||||||
|
const clr2 = fadeColor(clr, 60);
|
||||||
|
const metersActiveColor = fadeColor(clr, -60);
|
||||||
|
|
||||||
|
node.setAttribute('id', 'sdpi-dynamic-styles');
|
||||||
|
node.innerHTML = `
|
||||||
|
|
||||||
|
input[type="radio"]:checked + label span,
|
||||||
|
input[type="checkbox"]:checked + label span {
|
||||||
|
background-color: ${clrs.highlightColor};
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="radio"]:active:checked + label span,
|
||||||
|
input[type="checkbox"]:active:checked + label span {
|
||||||
|
background-color: ${clrs.mouseDownColor};
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="radio"]:active + label span,
|
||||||
|
input[type="checkbox"]:active + label span {
|
||||||
|
background-color: ${clrs.buttonPressedBorderColor};
|
||||||
|
}
|
||||||
|
|
||||||
|
td.selected,
|
||||||
|
td.selected:hover,
|
||||||
|
li.selected:hover,
|
||||||
|
li.selected {
|
||||||
|
color: white;
|
||||||
|
background-color: ${clrs.highlightColor};
|
||||||
|
}
|
||||||
|
|
||||||
|
.sdpi-file-label > label:active,
|
||||||
|
.sdpi-file-label.file:active,
|
||||||
|
label.sdpi-file-label:active,
|
||||||
|
label.sdpi-file-info:active,
|
||||||
|
input[type="file"]::-webkit-file-upload-button:active,
|
||||||
|
button:active {
|
||||||
|
border: 1pt solid ${clrs.buttonPressedBorderColor};
|
||||||
|
background-color: ${clrs.buttonPressedBackgroundColor};
|
||||||
|
color: ${clrs.buttonPressedTextColor};
|
||||||
|
border-color: ${clrs.buttonPressedBorderColor};
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-progress-value,
|
||||||
|
meter::-webkit-meter-optimum-value {
|
||||||
|
background: linear-gradient(${clr2}, ${clr1} 20%, ${clr} 45%, ${clr} 55%, ${clr2})
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-progress-value:active,
|
||||||
|
meter::-webkit-meter-optimum-value:active {
|
||||||
|
background: linear-gradient(${clr}, ${clr2} 20%, ${metersActiveColor} 45%, ${metersActiveColor} 55%, ${clr})
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
document.body.appendChild(node);
|
||||||
|
});
|
||||||
41
src/com.elgato.template.sdPlugin/libs/js/event-handler.js
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
class EventHandler {
|
||||||
|
static eventList = new Map();
|
||||||
|
|
||||||
|
static on(name, fn) {
|
||||||
|
if (!EventHandler.eventList.has(name)) {
|
||||||
|
EventHandler.eventList.set(name, EventHandler.pubSub());
|
||||||
|
}
|
||||||
|
|
||||||
|
return EventHandler.eventList.get(name).sub(fn);
|
||||||
|
}
|
||||||
|
|
||||||
|
static remove(name) {
|
||||||
|
this.eventList.delete(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
static removeAll(name) {
|
||||||
|
Array.from(this.eventList.keys()).filter(key => key.startsWith(name)).forEach(key => this.eventList.delete(key))
|
||||||
|
}
|
||||||
|
|
||||||
|
static has(name) {
|
||||||
|
return EventHandler.eventList.has(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
static emit(name, data) {
|
||||||
|
return EventHandler.eventList.has(name) && EventHandler.eventList.get(name).pub(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static pubSub() {
|
||||||
|
const subscribers = new Set();
|
||||||
|
|
||||||
|
const sub = (fn) => {
|
||||||
|
subscribers.add(fn);
|
||||||
|
return () => {
|
||||||
|
subscribers.delete(fn);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const pub = (data) => subscribers.forEach((fn) => fn(data));
|
||||||
|
return Object.freeze({pub, sub});
|
||||||
|
}
|
||||||
|
}
|
||||||
65
src/com.elgato.template.sdPlugin/libs/js/utils.js
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
// TODOZ: test other form controls like radio and checkboxes (See previous template code);
|
||||||
|
class Utils {
|
||||||
|
/**
|
||||||
|
* Returns the value from a form using the form controls name property
|
||||||
|
* @param {*} form
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
static getFormValue(form) {
|
||||||
|
if (typeof form === "string") {
|
||||||
|
form = document.querySelector(form);
|
||||||
|
}
|
||||||
|
|
||||||
|
const elements = form?.elements;
|
||||||
|
|
||||||
|
if (!elements) {
|
||||||
|
throw "Could not find form!";
|
||||||
|
}
|
||||||
|
|
||||||
|
return Array.from(elements)
|
||||||
|
.filter((element) => element?.name)
|
||||||
|
.reduce((value, element) => {
|
||||||
|
value[element.name] = element.value;
|
||||||
|
return value;
|
||||||
|
}, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of form controls using their name attribute and the jsn object key
|
||||||
|
* @param {*} jsn
|
||||||
|
* @param {*} form
|
||||||
|
*/
|
||||||
|
static setFormValue(jsn, form) {
|
||||||
|
if (typeof form === "string") {
|
||||||
|
form = document.querySelector(form);
|
||||||
|
}
|
||||||
|
|
||||||
|
const elements = form?.elements;
|
||||||
|
|
||||||
|
if (!elements) {
|
||||||
|
throw "Could not find form!";
|
||||||
|
}
|
||||||
|
|
||||||
|
Array.from(elements)
|
||||||
|
.filter((element) => element?.name)
|
||||||
|
.forEach((element) => {
|
||||||
|
element.value = jsn[element.name] ?? "";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This provides a slight delay before processing rapid events
|
||||||
|
* @param {*} wait - delay before processing function (recommended time 150ms)
|
||||||
|
* @param {*} fn
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
static debounce(wait, fn) {
|
||||||
|
let timeoutId = null;
|
||||||
|
return (...args) => {
|
||||||
|
window.clearTimeout(timeoutId);
|
||||||
|
timeoutId = window.setTimeout(() => {
|
||||||
|
fn.apply(null, args);
|
||||||
|
}, wait);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
37
src/com.elgato.template.sdPlugin/manifest.json
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
{
|
||||||
|
"Actions": [
|
||||||
|
{
|
||||||
|
"Icon": "actions/template/assets/actionimage",
|
||||||
|
"Name": "Example Action",
|
||||||
|
"States": [
|
||||||
|
{
|
||||||
|
"Image": "actions/template/assets/action"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Tooltip": "This is an example tooltip",
|
||||||
|
"UUID": "com.elgato.template.action",
|
||||||
|
"PropertyInspectorPath": "actions/template/property-inspector/inspector.html"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"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.0",
|
||||||
|
"OS": [
|
||||||
|
{
|
||||||
|
"Platform": "mac",
|
||||||
|
"MinimumVersion": "10.11"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Platform": "windows",
|
||||||
|
"MinimumVersion": "10"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Software": {
|
||||||
|
"MinimumVersion": "4.1"
|
||||||
|
}
|
||||||
|
}
|
||||||