From a1f237c1c81e4d414eb5993fd3ab784b2746eed6 Mon Sep 17 00:00:00 2001 From: Zack Hoherchak Date: Thu, 3 Mar 2022 16:37:41 -0500 Subject: [PATCH] switchToProfile --- src/com.elgato.template.sdPlugin/app.js | 109 +++++++++--------- .../libs/js/action.js | 22 ++-- .../libs/js/stream-deck.js | 4 +- .../libs/js/utils.js | 2 +- 4 files changed, 66 insertions(+), 71 deletions(-) diff --git a/src/com.elgato.template.sdPlugin/app.js b/src/com.elgato.template.sdPlugin/app.js index 5c144d2..9a66ff7 100644 --- a/src/com.elgato.template.sdPlugin/app.js +++ b/src/com.elgato.template.sdPlugin/app.js @@ -4,63 +4,60 @@ /** * The first event fired when Stream Deck starts */ - $SD.onConnected(({ actionInfo, appInfo, connection, messageType, port, uuid }) => { +$SD.onConnected(({ actionInfo, appInfo, connection, messageType, port, uuid }) => { // TODO: Remove this test logging code and replace with simple action console.log({ object: 'stream-deck', event: 'onConnected' }); - - new Action('com.elgato.template.action') - .onDidReceiveGlobalSettings(() => { - console.log({ object: 'action', event: 'onDidReceiveGlobalSettings' }); - }) - .onDidReceiveSettings(() => { - console.log({ object: 'action', event: 'onDidReceiveSettings' }); - }) - .onKeyDown(({context, device}) => { - console.log(jsn); - console.log({ object: 'action', event: 'onKeyDown' }); - $SD.switchToProfile(device, 'HUD XL'); - }) - .onKeyUp(() => { - console.log({ object: 'action', event: 'onKeyUp' }); - }) - .onWillAppear(() => { - console.log({ object: 'action', event: 'onWillAppear' }); - }) - .onWillDisappear(() => { - console.log({ object: 'action', event: 'onWillDisappear' }); - }) - .onTitleParametersDidChange(() => { - console.log({ object: 'action', event: 'onTitleParametersDidChange' }); - }) - .onPropertyInspectorDidAppear(() => { - console.log({ object: 'action', event: 'onPropertyInspectorDidAppear' }); - }) - .onPropertyInspectorDidDisappear(() => { - console.log({ object: 'action', event: 'onPropertyInspectorDidDisappear' }); - }) - .onSendToPlugin(() => { - console.log({ object: 'action', event: 'onSendToPlugin' }); - }) - .onSendToPropertyInspector(() => { - console.log({ object: 'action', event: 'onSendToPropertyInspector' }); - }); - - $SD.onDeviceDidConnect(() => { +}) + .onDeviceDidConnect(() => { console.log({ object: 'stream-deck', event: 'onDeviceDidConnect' }); }) - .onDeviceDidDisconnect(() => { - console.log({ object: 'stream-deck', event: 'onDeviceDidDisconnect' }); - }) - .onSendToPropertyInspector(() => { - console.log({ object: 'stream-deck', event: 'onSendToPropertyInspector' }); - }) - .onApplicationDidLaunch(() => { - console.log({ object: 'stream-deck', event: 'onApplicationDidLaunch' }); - }) - .onApplicationDidTerminate(() => { - console.log({ object: 'stream-deck', event: 'onApplicationDidTerminate' }); - }) - .onSystemDidWakeUp(() => { - console.log({ object: 'stream-deck', event: 'onSystemDidWakeUp' }); - }); -}); + .onDeviceDidDisconnect(() => { + console.log({ object: 'stream-deck', event: 'onDeviceDidDisconnect' }); + }) + .onSendToPropertyInspector(() => { + console.log({ object: 'stream-deck', event: 'onSendToPropertyInspector' }); + }) + .onApplicationDidLaunch(() => { + console.log({ object: 'stream-deck', event: 'onApplicationDidLaunch' }); + }) + .onApplicationDidTerminate(() => { + console.log({ object: 'stream-deck', event: 'onApplicationDidTerminate' }); + }) + .onSystemDidWakeUp(() => { + console.log({ object: 'stream-deck', event: 'onSystemDidWakeUp' }); + }); + +new Action('com.elgato.template.action') + .onDidReceiveGlobalSettings(() => { + console.log({ object: 'action', event: 'onDidReceiveGlobalSettings' }); + }) + .onDidReceiveSettings(() => { + console.log({ object: 'action', event: 'onDidReceiveSettings' }); + }) + .onKeyDown(() => { + console.log({ object: 'action', event: 'onKeyDown' }); + }) + .onKeyUp(() => { + console.log({ object: 'action', event: 'onKeyUp' }); + }) + .onWillAppear(() => { + console.log({ object: 'action', event: 'onWillAppear' }); + }) + .onWillDisappear(() => { + console.log({ object: 'action', event: 'onWillDisappear' }); + }) + .onTitleParametersDidChange(() => { + console.log({ object: 'action', event: 'onTitleParametersDidChange' }); + }) + .onPropertyInspectorDidAppear(() => { + console.log({ object: 'action', event: 'onPropertyInspectorDidAppear' }); + }) + .onPropertyInspectorDidDisappear(() => { + console.log({ object: 'action', event: 'onPropertyInspectorDidDisappear' }); + }) + .onSendToPlugin(() => { + console.log({ object: 'action', event: 'onSendToPlugin' }); + }) + .onSendToPropertyInspector(() => { + console.log({ object: 'action', event: 'onSendToPropertyInspector' }); + }); diff --git a/src/com.elgato.template.sdPlugin/libs/js/action.js b/src/com.elgato.template.sdPlugin/libs/js/action.js index 5e4c957..ad77177 100644 --- a/src/com.elgato.template.sdPlugin/libs/js/action.js +++ b/src/com.elgato.template.sdPlugin/libs/js/action.js @@ -14,7 +14,7 @@ class ELGSDAction { /** * Registers a callback function for the didReceiveSettings event, which fires when calling getSettings - * @param {*} fn + * @param {function} fn */ onDidReceiveSettings(fn) { this.#on(`${this.UUID}.${Events.didReceiveSettings}`, (jsn) => fn(jsn)); @@ -23,7 +23,7 @@ class ELGSDAction { /** * Registers a callback function for the didReceiveGlobalSettings event, which fires when calling getGlobalSettings - * @param {*} fn + * @param {function} fn */ onDidReceiveGlobalSettings(fn) { this.#on(Events.didReceiveGlobalSettings, (jsn) => fn(jsn)); @@ -32,7 +32,7 @@ class ELGSDAction { /** * Registers a callback function for the keyDown event, which fires when pressing a key down - * @param {*} fn + * @param {function} fn */ onKeyDown(fn) { this.#on(`${this.UUID}.${Events.keyDown}`, (jsn) => fn(jsn)); @@ -41,7 +41,7 @@ class ELGSDAction { /** * Registers a callback function for the keyUp event, which fires when releasing a key - * @param {*} fn + * @param {function} fn */ onKeyUp(fn) { this.#on(`${this.UUID}.${Events.keyUp}`, (jsn) => fn(jsn)); @@ -50,7 +50,7 @@ class ELGSDAction { /** * Registers a callback function for the willAppear event, which fires when an action appears on the canvas - * @param {*} fn + * @param {function} fn */ onWillAppear(fn) { this.#on(`${this.UUID}.${Events.willAppear}`, (jsn) => fn(jsn)); @@ -59,7 +59,7 @@ class ELGSDAction { /** * Registers a callback function for the willAppear event, which fires when an action disappears on the canvas - * @param {*} fn + * @param {function} fn */ onWillDisappear(fn) { this.#on(`${this.UUID}.${Events.willDisappear}`, (jsn) => fn(jsn)); @@ -68,7 +68,7 @@ class ELGSDAction { /** * Registers a callback function for the titleParametersDidChange event, which fires when a user changes the key title - * @param {*} fn + * @param {function} fn */ onTitleParametersDidChange(fn) { this.#on(`${this.UUID}.${Events.titleParametersDidChange}`, (jsn) => fn(jsn)); @@ -77,7 +77,7 @@ class ELGSDAction { /** * Registers a callback function for the propertyInspectorDidAppear event, which fires when the property inspector is displayed - * @param {*} fn + * @param {function} fn */ onPropertyInspectorDidAppear(fn) { this.#on(`${this.UUID}.${Events.propertyInspectorDidAppear}`, (jsn) => fn(jsn)); @@ -86,7 +86,7 @@ class ELGSDAction { /** * Registers a callback function for the propertyInspectorDidDisappear event, which fires when the property inspector is closed - * @param {*} fn + * @param {function} fn */ onPropertyInspectorDidDisappear(fn) { this.#on(`${this.UUID}.${Events.propertyInspectorDidDisappear}`, (jsn) => fn(jsn)); @@ -95,7 +95,7 @@ class ELGSDAction { /** * Registers a callback function for the sendToPlugin event, which fires when the property inspector uses the sendToPlugin api - * @param {*} fn + * @param {function} fn */ onSendToPlugin(fn) { this.#on(`${this.UUID}.${Events.sendToPlugin}`, (jsn) => fn(jsn)); @@ -104,7 +104,7 @@ class ELGSDAction { /** * Registers a callback function for the sendToPropertyInspector event, which fires when the plugin uses the sendToPropertyInspector api - * @param {*} fn + * @param {function} fn */ onSendToPropertyInspector(fn) { this.#on(`${this.UUID}.${Events.sendToPropertyInspector}`, (jsn) => fn(jsn)); diff --git a/src/com.elgato.template.sdPlugin/libs/js/stream-deck.js b/src/com.elgato.template.sdPlugin/libs/js/stream-deck.js index 78e80f6..48e4bda 100644 --- a/src/com.elgato.template.sdPlugin/libs/js/stream-deck.js +++ b/src/com.elgato.template.sdPlugin/libs/js/stream-deck.js @@ -1,7 +1,6 @@ /// /// -// TODO: switchToProfile (see https://elgato.slack.com/archives/D02LPKC0M9D/p1645183819000839 ) // TODO: See if we can add params for the call back function, so that the IDE will provide the jsn object with "context, device, etc" // TODO: https://stackoverflow.com/questions/24214962/whats-the-proper-way-to-document-callbacks-with-jsdoc @@ -307,9 +306,8 @@ class ELGSDStreamDeck { }); } - //TODO: fix profile switch not working /** - * Switches to profile or returns to previous profile + * Switches to a readonly profile or returns to previous profile * @param {string} device * @param {string} [profile] */ diff --git a/src/com.elgato.template.sdPlugin/libs/js/utils.js b/src/com.elgato.template.sdPlugin/libs/js/utils.js index 8342899..6471e1d 100644 --- a/src/com.elgato.template.sdPlugin/libs/js/utils.js +++ b/src/com.elgato.template.sdPlugin/libs/js/utils.js @@ -69,7 +69,7 @@ class Utils { /** * This provides a slight delay before processing rapid events * @param {*} wait - delay before processing function (recommended time 150ms) - * @param {*} fn + * @param {function} fn * @returns */ static debounce(wait, fn) {