lib submodule

This commit is contained in:
Zack Hoherchak 2022-05-06 23:30:28 -04:00
commit fbff978cdd
15 changed files with 4 additions and 2519 deletions

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "src/com.elgato.template.sdPlugin/libs"]
path = src/com.elgato.template.sdPlugin/libs
url = https://github.com/elgatosf/streamdeck-javascript-sdk

@ -0,0 +1 @@
Subproject commit d642da9b86a8a45651647ccf1cacc5bd70acf783

View file

@ -1,3 +0,0 @@
<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>

Before

Width:  |  Height:  |  Size: 171 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 234 B

View file

@ -1,3 +0,0 @@
<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>

Before

Width:  |  Height:  |  Size: 210 B

View file

@ -1,24 +0,0 @@
<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>

Before

Width:  |  Height:  |  Size: 1.3 KiB

View file

@ -1,7 +0,0 @@
<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>

Before

Width:  |  Height:  |  Size: 764 B

View file

@ -1,3 +0,0 @@
<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>

Before

Width:  |  Height:  |  Size: 131 B

File diff suppressed because it is too large Load diff

View file

@ -1,138 +0,0 @@
/// <reference path="constants.js" />
/**
* @class Action
* A Stream Deck plugin action, where you can register callback functions for different events
*/
class ELGSDAction {
UUID;
on = EventEmitter.on;
emit = EventEmitter.emit;
constructor(UUID) {
if (!UUID) {
throw 'An action UUID matching the action UUID in your manifest is required when creating Actions.';
}
this.UUID = UUID;
}
/**
* Registers a callback function for the didReceiveSettings event, which fires when calling getSettings
* @param {function} fn
*/
onDidReceiveSettings(fn) {
if (!fn) {
throw 'A callback function for the didReceiveSettings event is required for onDidReceiveSettings.';
}
this.on(`${this.UUID}.${Events.didReceiveSettings}`, (jsn) => fn(jsn));
return this;
}
/**
* Registers a callback function for the keyDown event, which fires when pressing a key down
* @param {function} fn
*/
onKeyDown(fn) {
if (!fn) {
throw 'A callback function for the keyDown event is required for onKeyDown.';
}
this.on(`${this.UUID}.${Events.keyDown}`, (jsn) => fn(jsn));
return this;
}
/**
* Registers a callback function for the keyUp event, which fires when releasing a key
* @param {function} fn
*/
onKeyUp(fn) {
if (!fn) {
throw 'A callback function for the keyUp event is required for onKeyUp.';
}
this.on(`${this.UUID}.${Events.keyUp}`, (jsn) => fn(jsn));
return this;
}
/**
* Registers a callback function for the willAppear event, which fires when an action appears on the canvas
* @param {function} fn
*/
onWillAppear(fn) {
if (!fn) {
throw 'A callback function for the willAppear event is required for onWillAppear.';
}
this.on(`${this.UUID}.${Events.willAppear}`, (jsn) => fn(jsn));
return this;
}
/**
* Registers a callback function for the willAppear event, which fires when an action disappears on the canvas
* @param {function} fn
*/
onWillDisappear(fn) {
if (!fn) {
throw 'A callback function for the willDisappear event is required for onWillDisappear.';
}
this.on(`${this.UUID}.${Events.willDisappear}`, (jsn) => fn(jsn));
return this;
}
/**
* Registers a callback function for the titleParametersDidChange event, which fires when a user changes the key title
* @param {function} fn
*/
onTitleParametersDidChange(fn) {
if (!fn) {
throw 'A callback function for the titleParametersDidChange event is required for onTitleParametersDidChange.';
}
this.on(`${this.UUID}.${Events.titleParametersDidChange}`, (jsn) => fn(jsn));
return this;
}
/**
* Registers a callback function for the propertyInspectorDidAppear event, which fires when the property inspector is displayed
* @param {function} fn
*/
onPropertyInspectorDidAppear(fn) {
if (!fn) {
throw 'A callback function for the propertyInspectorDidAppear event is required for onPropertyInspectorDidAppear.';
}
this.on(`${this.UUID}.${Events.propertyInspectorDidAppear}`, (jsn) => fn(jsn));
return this;
}
/**
* Registers a callback function for the propertyInspectorDidDisappear event, which fires when the property inspector is closed
* @param {function} fn
*/
onPropertyInspectorDidDisappear(fn) {
if (!fn) {
throw 'A callback function for the propertyInspectorDidDisappear event is required for onPropertyInspectorDidDisappear.';
}
this.on(`${this.UUID}.${Events.propertyInspectorDidDisappear}`, (jsn) => fn(jsn));
return this;
}
/**
* Registers a callback function for the sendToPlugin event, which fires when the property inspector uses the sendToPlugin api
* @param {function} fn
*/
onSendToPlugin(fn) {
if (!fn) {
throw 'A callback function for the sendToPlugin event is required for onSendToPlugin.';
}
this.on(`${this.UUID}.${Events.sendToPlugin}`, (jsn) => fn(jsn));
return this;
}
}
const Action = ELGSDAction;

View file

@ -1,69 +0,0 @@
/**
* Errors received from WebSocket
*/
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 used for communicating with Stream Deck
*/
const Events = {
didReceiveSettings: 'didReceiveSettings',
didReceiveGlobalSettings: 'didReceiveGlobalSettings',
keyDown: 'keyDown',
keyUp: 'keyUp',
willAppear: 'willAppear',
willDisappear: 'willDisappear',
titleParametersDidChange: 'titleParametersDidChange',
deviceDidConnect: 'deviceDidConnect',
deviceDidDisconnect: 'deviceDidDisconnect',
applicationDidLaunch: 'applicationDidLaunch',
applicationDidTerminate: 'applicationDidTerminate',
systemDidWakeUp: 'systemDidWakeUp',
propertyInspectorDidAppear: 'propertyInspectorDidAppear',
propertyInspectorDidDisappear: 'propertyInspectorDidDisappear',
sendToPlugin: 'sendToPlugin',
sendToPropertyInspector: 'sendToPropertyInspector',
connected: 'connected',
setImage: 'setImage',
setTitle: 'setTitle',
setState: 'setState',
showOk: 'showOk',
showAlert: 'showAlert',
openUrl: 'openUrl',
setGlobalSettings: 'setGlobalSettings',
getGlobalSettings: 'getGlobalSettings',
setSettings: 'setSettings',
getSettings: 'getSettings',
registerPropertyInspector: 'registerPropertyInspector',
registerPlugin: 'registerPlugin',
logMessage: 'logMessage',
switchToProfile: 'switchToProfile',
};
/**
* Constants used for Stream Deck
*/
const Constants = {
dataLocalize: '[data-localize]',
hardwareAndSoftware: 0,
hardwareOnly: 1,
softwareOnly: 2,
};

View file

@ -1,70 +0,0 @@
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);
};
$SD.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);
});

View file

@ -1,31 +0,0 @@
class ELGSDEventEmitter {
eventList = new Map();
on(name, fn) {
if (!EventEmitter.eventList.has(name)) {
EventEmitter.eventList.set(name, EventEmitter.pubSub());
}
return EventEmitter.eventList.get(name).sub(fn);
}
emit(name, data) {
return EventEmitter.eventList.has(name) && EventEmitter.eventList.get(name).pub(data);
}
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});
}
}
const EventEmitter = new ELGSDEventEmitter();

View file

@ -1,515 +0,0 @@
/// <reference path="event-emitter.js" />
/// <reference path="constants.js" />
/**
* @class StreamDeck
* StreamDeck object containing all required code to establish
* communication with SD-Software and the Property Inspector
*/
class ELGSDStreamDeck {
port;
uuid;
messageType;
actionInfo;
websocket;
language;
localization;
appInfo;
on = EventEmitter.on;
emit = EventEmitter.emit;
constructor() {
if (ELGSDStreamDeck.__instance) {
return ELGSDStreamDeck.__instance;
}
ELGSDStreamDeck.__instance = this;
}
/**
* Connect to Stream Deck
* @param {string} port
* @param {string} uuid
* @param {string} messageType
* @param {string} appInfoString
* @param {string} actionString
*/
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(Events.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.logMessage(error);
};
this.websocket.onclose = (evt) => {
console.warn('WEBOCKET CLOSED:', SocketErrors[evt?.code]);
};
this.websocket.onmessage = (evt) => {
const data = evt?.data ? JSON.parse(evt.data) : null;
const { action, event } = data;
const message = action ? `${action}.${event}` : event;
if (message && message !== '') this.emit(message, data);
};
}
/**
* Write to log file
* @param {string} message
*/
logMessage(message) {
if (!message) {
throw 'A message is required for logMessage.';
}
try {
if (this.websocket) {
const json = {
event: Events.logMessage,
payload: {
message: message,
},
};
this.websocket.send(JSON.stringify(json));
} else {
console.error('Websocket not defined');
}
} catch (e) {
console.error('Websocket not defined');
}
}
/**
* Fetches the specified language json file
* @param {string} pathPrefix
* @returns {Promise<void>}
*/
async loadLocalization(pathPrefix) {
if (!pathPrefix) {
throw 'A path to localization json is required for loadLocalization.';
}
const manifest = await this.readJson(`${pathPrefix}${this.language}.json`);
this.localization = manifest['Localization'] ?? null;
if (this.messageType === Events.registerPropertyInspector && this.localization) {
const elements = document.querySelectorAll(Constants.dataLocalize);
elements.forEach((element) => {
element.textContent = this.localization[element.textContent] ?? element.textContent;
});
}
}
/**
*
* @param {string} path
* @returns {Promise<any>} json
*/
async readJson(path) {
if (!path) {
throw 'A path is required to readJson.';
}
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 {string} event
* @param {string} context
* @param {object} [payload]
*/
send(event, context, payload = {}) {
const pl = Object.assign({}, { event: event, 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 {string} [context]
*/
getSettings(context) {
this.send(Events.getSettings, context ?? this.uuid);
}
/**
* Save the actions's persistent data.
* @param {object} payload
* @param [context]
*/
setSettings(payload, context) {
this.send(Events.setSettings, this.uuid, {
action: this?.actionInfo?.action,
payload: payload || null,
targetContext: context,
});
}
/**
* Request the plugin's persistent data. StreamDeck does not return the data, but trigger the plugin/property inspectors didReceiveGlobalSettings event
*/
getGlobalSettings() {
this.send(Events.getGlobalSettings, this.uuid);
}
/**
* Save the plugin's persistent data
* @param {object} payload
*/
setGlobalSettings(payload) {
this.send(Events.setGlobalSettings, this.uuid, {
payload: payload,
});
}
/**
* Opens a URL in the default web browser
* @param {string} urlToOpen
*/
openUrl(urlToOpen) {
if (!url) {
throw 'A url is required for openUrl.';
}
this.send(Events.openUrl, this.uuid, {
payload: {
url: urlToOpen,
},
});
}
/**
* Send payload from the property inspector to the plugin
* @param {object} payload
* @param {string} [context]
*/
sendToPlugin(payload, context) {
this.send(Events.sendToPlugin, this.uuid, {
action: this?.actionInfo?.action,
payload: payload || null,
targetContext: context,
});
}
/**
* Display alert triangle on actions key
* @param {string} context
*/
showAlert(context) {
if (!context) {
throw 'A context is required to showAlert on the key.';
}
this.send(Events.showAlert, context);
}
/**
* Display ok check mark on actions key
* @param {string} context
*/
showOk(context) {
if (!context) {
throw 'A context is required to showOk on the key.';
}
this.send(Events.showOk, context);
}
/**
* Set the state of the actions
* @param {object} payload
* @param {string} context
*/
setState(payload, context) {
if (!payload) {
throw 'A state is required when using setState.';
}
if (!context) {
throw 'A context is required when using setState.';
}
this.send(Events.setState, context, {
payload: {
state: 1 - Number(payload === 0),
},
});
}
/**
* Set the title of the action's key
* @param {string} title
* @param {string} context
* @param [target]
*/
setTitle(title, context, target) {
if (!title) {
throw 'A title is required for setTitle.';
}
if (!context) {
throw 'A key context is required for setTitle.';
}
this.send(Events.setTitle, context, {
payload: {
title: '' + title || '',
target: target || Constants.hardwareAndSoftware,
},
});
}
/**
*
* @param {string} context
* @param {number} [target]
*/
clearTitle(context, target) {
if (!context) {
throw 'A key context is required to clearTitle.';
}
this.setTitle(null, context, target || Constants.hardwareAndSoftware);
}
/**
* Send payload to property inspector
* @param {string} actionUUID
* @param {object} payload
* @param {string} context
*/
sendToPropertyInspector(actionUUID, context, payload) {
if (typeof actionUUID != 'string') {
throw 'An action UUID is required to sendToPropertyInspector.';
}
if (typeof context != 'string') {
throw 'A key context is required to sendToPropertyInspector.';
}
this.send(Events.sendToPropertyInspector, context, {
action: actionUUID,
payload: payload || null,
});
}
/**
* Set the actions key image
* @param {string} img
* @param {string} context
* @param {number} [target]
*/
setImage(img, context, target) {
if (!img) {
throw 'An image is required for setImage.';
}
if (!context) {
throw 'A key context is required for setImage.';
}
this.send(Events.setImage, context, {
payload: {
image: img || '',
target: target || Constants.hardwareAndSoftware,
},
});
}
/**
* Switches to a readonly profile or returns to previous profile
* @param {string} device
* @param {string} [profile]
*/
switchToProfile(device, profile) {
if (!device) {
throw 'A device id is required for switchToProfile.';
}
if (!profile) {
throw 'A profile name is required for switchToProfile';
}
this.send(Events.switchToProfile, this.uuid, { device: device, payload: { profile } });
}
/**
* Registers a callback function for when Stream Deck is connected
* @param {function} fn
* @returns ELGSDStreamDeck
*/
onConnected(fn) {
if (!fn) {
throw 'A callback function for the connected event is required for onConnected.';
}
this.on(Events.connected, (jsn) => fn(jsn));
return this;
}
/**
* Registers a callback function for when Stream Deck sends data to the property inspector
* @param {string} actionUUID
* @param {function} fn
* @returns ELGSDStreamDeck
*/
onSendToPropertyInspector(actionUUID, fn) {
if (typeof actionUUID != 'string') {
throw 'An action UUID string is required for onSendToPropertyInspector.';
}
if (!fn) {
throw 'A callback function for the sendToPropertyInspector event is required for onSendToPropertyInspector.';
}
this.on(`${actionUUID}.${Events.sendToPropertyInspector}`, (jsn) => fn(jsn));
return this;
}
/**
* Registers a callback function for the deviceDidConnect event, which fires when a device is plugged in
* @param {function} fn
* @returns ELGSDStreamDeck
*/
onDeviceDidConnect(fn) {
if (!fn) {
throw 'A callback function for the deviceDidConnect event is required for onDeviceDidConnect.';
}
this.on(Events.deviceDidConnect, (jsn) => fn(jsn));
return this;
}
/**
* Registers a callback function for the deviceDidDisconnect event, which fires when a device is unplugged
* @param {function} fn
* @returns ELGSDStreamDeck
*/
onDeviceDidDisconnect(fn) {
if (!fn) {
throw 'A callback function for the deviceDidDisconnect event is required for onDeviceDidDisconnect.';
}
this.on(Events.deviceDidDisconnect, (jsn) => fn(jsn));
return this;
}
/**
* Registers a callback function for the applicationDidLaunch event, which fires when the application starts
* @param {function} fn
* @returns ELGSDStreamDeck
*/
onApplicationDidLaunch(fn) {
if (!fn) {
throw 'A callback function for the applicationDidLaunch event is required for onApplicationDidLaunch.';
}
this.on(Events.applicationDidLaunch, (jsn) => fn(jsn));
return this;
}
/**
* Registers a callback function for the applicationDidTerminate event, which fires when the application exits
* @param {function} fn
* @returns ELGSDStreamDeck
*/
onApplicationDidTerminate(fn) {
if (!fn) {
throw 'A callback function for the applicationDidTerminate event is required for onApplicationDidTerminate.';
}
this.on(Events.applicationDidTerminate, (jsn) => fn(jsn));
return this;
}
/**
* Registers a callback function for the systemDidWakeUp event, which fires when the computer wakes
* @param {function} fn
* @returns ELGSDStreamDeck
*/
onSystemDidWakeUp(fn) {
if (!fn) {
throw 'A callback function for the systemDidWakeUp event is required for onSystemDidWakeUp.';
}
this.on(Events.systemDidWakeUp, (jsn) => fn(jsn));
return this;
}
/**
* Registers a callback function for the didReceiveGlobalSettings event, which fires when calling getGlobalSettings
* @param {function} fn
*/
onDidReceiveGlobalSettings(fn) {
if (!fn) {
throw 'A callback function for the didReceiveGlobalSettings event is required for onDidReceiveGlobalSettings.';
}
this.on(Events.didReceiveGlobalSettings, (jsn) => fn(jsn));
return this;
}
}
const $SD = new ELGSDStreamDeck();
/**
* 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() {
$SD.connect(arguments);
}

View file

@ -1,90 +0,0 @@
class Utils {
/**
* Returns the value from a form using the form controls name property
* @param {Element | string} form
* @returns
*/
static getFormValue(form) {
if (typeof form === 'string') {
form = document.querySelector(form);
}
const elements = form?.elements;
if (!elements) {
throw 'Could not find form!';
}
const formData = new FormData(form);
let formValue = {};
formData.forEach((value, key) => {
if (!Reflect.has(formValue, key)) {
formValue[key] = value;
return;
}
if (!Array.isArray(formValue[key])) {
formValue[key] = [formValue[key]];
}
formValue[key].push(value);
});
return formValue;
}
/**
* Sets the value of form controls using their name attribute and the jsn object key
* @param {*} jsn
* @param {Element | string} form
*/
static setFormValue(jsn, form) {
if (!jsn) {
return;
}
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) => {
const { name, type } = element;
const value = name in jsn ? jsn[name] : null;
const isCheckOrRadio = type === 'checkbox' || type === 'radio';
if (value === null) return;
if (isCheckOrRadio) {
const isSingle = value === element.value;
if (isSingle || (Array.isArray(value) && value.includes(element.value))) {
element.checked = true;
}
} else {
element.value = value ?? '';
}
});
}
/**
* This provides a slight delay before processing rapid events
* @param {number} wait - delay before processing function (recommended time 150ms)
* @param {function} fn
* @returns
*/
static debounce(wait, fn) {
let timeoutId = null;
return (...args) => {
window.clearTimeout(timeoutId);
timeoutId = window.setTimeout(() => {
fn.apply(null, args);
}, wait);
};
}
}