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 index c26b4fb..fc65a67 100644 --- a/src/com.elgato.template.sdPlugin/actions/template/property-inspector/inspector.html +++ b/src/com.elgato.template.sdPlugin/actions/template/property-inspector/inspector.html @@ -57,7 +57,7 @@ - + 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 index 4122013..4cb6f45 100644 --- a/src/com.elgato.template.sdPlugin/actions/template/property-inspector/inspector.js +++ b/src/com.elgato.template.sdPlugin/actions/template/property-inspector/inspector.js @@ -1,26 +1,24 @@ -/// +/// /// -const streamDeck = new StreamDeck(); +StreamDeck.onConnected((jsn) => { + StreamDeck.loadLocalization('../../../'); -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; - 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); - Utils.setFormValue(settings, form); - - form.addEventListener( - 'input', - Utils.debounce(150, () => { - const value = Utils.getFormValue(form); - streamDeck.sendToPlugin(value, context); - streamDeck.setSettings(value); - }) - ); + form.addEventListener( + 'input', + Utils.debounce(150, () => { + const value = Utils.getFormValue(form); + StreamDeck.sendToPlugin(value, context); + StreamDeck.setSettings(value); + }) + ); }); /** @@ -28,9 +26,9 @@ streamDeck.onConnected((jsn) => { * (this can be removed if the external window is not used) */ window.sendToInspector = (data) => { - console.log(data); + console.log(data); }; document.querySelector('#open-external').addEventListener('click', () => { - window.open('../../../external.html'); + window.open('../../../external.html'); }); diff --git a/src/com.elgato.template.sdPlugin/app.html b/src/com.elgato.template.sdPlugin/app.html index a21338c..aa82cec 100644 --- a/src/com.elgato.template.sdPlugin/app.html +++ b/src/com.elgato.template.sdPlugin/app.html @@ -14,7 +14,7 @@ - + diff --git a/src/com.elgato.template.sdPlugin/app.js b/src/com.elgato.template.sdPlugin/app.js index c78446e..fd7efc5 100644 --- a/src/com.elgato.template.sdPlugin/app.js +++ b/src/com.elgato.template.sdPlugin/app.js @@ -1,19 +1,17 @@ /// -/// - -const streamDeck = new StreamDeck(); +/// /** * The first event fired when Stream Deck starts */ -streamDeck.onConnected(({actionInfo, appInfo, connection, messageType, port, uuid}) => { +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/'); + StreamDeck.openUrl('https://developer.elgato.com/documentation/stream-deck/sdk/overview/'); console.log('Your code goes here!'); - streamDeck.showOk(context); + StreamDeck.showOk(context); }); }); diff --git a/src/com.elgato.template.sdPlugin/libs/js/action.js b/src/com.elgato.template.sdPlugin/libs/js/action.js index 98a36a6..289afa5 100644 --- a/src/com.elgato.template.sdPlugin/libs/js/action.js +++ b/src/com.elgato.template.sdPlugin/libs/js/action.js @@ -4,7 +4,7 @@ * @class Action * A Stream Deck plugin action, where you can register callback functions for different events */ -class Action { +class ELGSDAction { UUID; #on = EventHandler.on; #removeListener = EventHandler.remove; @@ -159,3 +159,5 @@ class Action { return this.#removeListener(`${this.UUID}.${eventName}`); } } + +var Action = ELGSDAction; diff --git a/src/com.elgato.template.sdPlugin/libs/js/dynamic-styles.js b/src/com.elgato.template.sdPlugin/libs/js/dynamic-styles.js index 2bd903c..6f17830 100644 --- a/src/com.elgato.template.sdPlugin/libs/js/dynamic-styles.js +++ b/src/com.elgato.template.sdPlugin/libs/js/dynamic-styles.js @@ -8,7 +8,7 @@ const fadeColor = function (col, amt) { return '#' + (g | (b << 8) | (r << 16)).toString(16).padStart(6, 0); }; -new StreamDeck().onConnected(({ appInfo }) => { +StreamDeck.onConnected(({ appInfo }) => { if (appInfo?.colors) return; const clrs = appInfo.colors; const node = document.getElementById('#sdpi-dynamic-styles') || document.createElement('style'); diff --git a/src/com.elgato.template.sdPlugin/libs/js/event-handler.js b/src/com.elgato.template.sdPlugin/libs/js/event-handler.js index 9236ca0..bea3d24 100644 --- a/src/com.elgato.template.sdPlugin/libs/js/event-handler.js +++ b/src/com.elgato.template.sdPlugin/libs/js/event-handler.js @@ -1,41 +1,45 @@ -class EventHandler { - static eventList = new Map(); +class ELGSDEventHandler { + eventList = new Map(); - static on(name, fn) { - if (!EventHandler.eventList.has(name)) { - EventHandler.eventList.set(name, EventHandler.pubSub()); - } + on(name, fn) { + if (!EventHandler.eventList.has(name)) { + EventHandler.eventList.set(name, EventHandler.pubSub()); + } - return EventHandler.eventList.get(name).sub(fn); - } + return EventHandler.eventList.get(name).sub(fn); + } - static remove(name) { - this.eventList.delete(name) - } + 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)) - } + 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); - } + has(name) { + return EventHandler.eventList.has(name); + } - static emit(name, data) { - return EventHandler.eventList.has(name) && EventHandler.eventList.get(name).pub(data); - } + emit(name, data) { + return EventHandler.eventList.has(name) && EventHandler.eventList.get(name).pub(data); + } - static pubSub() { - const subscribers = new Set(); + pubSub() { + const subscribers = new Set(); - const sub = (fn) => { - subscribers.add(fn); - return () => { - subscribers.delete(fn); - }; - }; + const sub = (fn) => { + subscribers.add(fn); + return () => { + subscribers.delete(fn); + }; + }; - const pub = (data) => subscribers.forEach((fn) => fn(data)); - return Object.freeze({pub, sub}); - } + const pub = (data) => subscribers.forEach((fn) => fn(data)); + return Object.freeze({ pub, sub }); + } } + +var EventHandler = new ELGSDEventHandler(); diff --git a/src/com.elgato.template.sdPlugin/libs/js/deck.js b/src/com.elgato.template.sdPlugin/libs/js/stream-deck.js similarity index 97% rename from src/com.elgato.template.sdPlugin/libs/js/deck.js rename to src/com.elgato.template.sdPlugin/libs/js/stream-deck.js index f99244c..97e4e7b 100644 --- a/src/com.elgato.template.sdPlugin/libs/js/deck.js +++ b/src/com.elgato.template.sdPlugin/libs/js/stream-deck.js @@ -6,7 +6,7 @@ * StreamDeck object containing all required code to establish * communication with SD-Software and the Property Inspector */ -class StreamDeck { +class ELGSDStreamDeck { #port; #uuid; #messageType; @@ -21,11 +21,11 @@ class StreamDeck { #removeAllListeners = EventHandler.removeAll; constructor() { - if (StreamDeck.__instance) { - return StreamDeck.__instance; + if (ELGSDStreamDeck.__instance) { + return ELGSDStreamDeck.__instance; } - StreamDeck.__instance = this; + ELGSDStreamDeck.__instance = this; } /** @@ -330,6 +330,8 @@ class StreamDeck { } } +var StreamDeck = new ELGSDStreamDeck(); + /** * connectElgatoStreamDeckSocket * This is the first function StreamDeck Software calls, when @@ -341,5 +343,5 @@ class StreamDeck { * @param {string} actionInfo - Context is an internal identifier used to communicate to the host application. */ function connectElgatoStreamDeckSocket() { - new StreamDeck().connect(arguments); + StreamDeck.connect(arguments); }