loupedeck-commander 1.2.1 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/common/utils.mjs CHANGED
@@ -1,29 +1,29 @@
1
- import { readFileSync, writeFileSync } from 'node:fs'
2
-
3
- /**
4
- * Read a JSON File
5
- */
6
- export function readJSONFile (fileName) {
7
- let data
8
- try {
9
- data = readFileSync(fileName, 'utf8')
10
- return JSON.parse(data)
11
- } catch (error) {
12
- return data
13
- }
14
- }
15
-
16
- /**
17
- * Write a JSON File
18
- */
19
- export function writeJSONFile (fileName, jsonObj) {
20
- const data = JSON.stringify(jsonObj, null, 4)
21
- writeFileSync(fileName, data)
22
- }
23
-
24
- export function calcDelta (data, delta, max = 100) {
25
- data = data + delta
26
- if (data > max) { data = max }
27
- if (data < 0) { data = 0 }
28
- return data
29
- }
1
+ import { readFileSync, writeFileSync } from 'node:fs'
2
+
3
+ /**
4
+ * Read a JSON File
5
+ */
6
+ export function readJSONFile (fileName) {
7
+ let data
8
+ try {
9
+ data = readFileSync(fileName, 'utf8')
10
+ return JSON.parse(data)
11
+ } catch (error) {
12
+ return data
13
+ }
14
+ }
15
+
16
+ /**
17
+ * Write a JSON File
18
+ */
19
+ export function writeJSONFile (fileName, jsonObj) {
20
+ const data = JSON.stringify(jsonObj, null, 4)
21
+ writeFileSync(fileName, data)
22
+ }
23
+
24
+ export function calcDelta (data, delta, max = 100) {
25
+ data = data + delta
26
+ if (data > max) { data = max }
27
+ if (data < 0) { data = 0 }
28
+ return data
29
+ }
package/config.json CHANGED
@@ -1,9 +1,9 @@
1
- {
2
- "application": "Example",
3
- "profiles": [
4
- {
5
- "name": "profile1",
6
- "file": "profile-1.json"
7
- }
8
- ]
1
+ {
2
+ "application": "Example",
3
+ "profiles": [
4
+ {
5
+ "name": "profile1",
6
+ "file": "profile-1.json"
7
+ }
8
+ ]
9
9
  }
package/eslint.config.mjs CHANGED
@@ -1,9 +1,9 @@
1
- import globals from "globals";
2
- import pluginJs from "@eslint/js";
3
-
4
-
5
- /** @type {import('eslint').Linter.Config[]} */
6
- export default [
7
- {languageOptions: { globals: globals.browser }},
8
- pluginJs.configs.recommended,
1
+ import globals from "globals";
2
+ import pluginJs from "@eslint/js";
3
+
4
+
5
+ /** @type {import('eslint').Linter.Config[]} */
6
+ export default [
7
+ {languageOptions: { globals: globals.browser }},
8
+ pluginJs.configs.recommended,
9
9
  ];
@@ -1,44 +1,44 @@
1
- import { HAPTIC } from 'loupedeck'
2
- import { BaseLoupeDeckHandler } from '../common/BaseLoupeDeckHandler.mjs'
3
-
4
- /**
5
- * Our Special-Handler just used the Default - and adds Vibration after triggers through Button-Releases
6
- */
7
- export class ExampleDeviceHandler extends BaseLoupeDeckHandler {
8
- /**
9
- * Handle different Vibration-Feedback on OK (true), and NOK (false)
10
- * @param {*} ok
11
- */
12
- async vibrateHandler (ok) {
13
- if (ok) { await this.device.vibrate(HAPTIC.REV_FASTEST) } else {
14
- this.device.vibrate(HAPTIC.RUMBLE2)
15
- }
16
- }
17
-
18
- /**
19
- * Handle Button-Up Events with Vibration Handler
20
- * @param {*} event
21
- */
22
- async onButtonUp (event) {
23
- const res = await super.onButtonUp(event)
24
- await this.vibrateHandler(res)
25
- }
26
-
27
- /**
28
- * Handle Knob-Rotation Events with Vibration Handler
29
- * @param {*} event
30
- */
31
- async onRotate (event) {
32
- const res = await super.onRotate(event)
33
- await this.vibrateHandler(res)
34
- }
35
-
36
- /**
37
- * Handle Touch-End Events with Vibration Handler
38
- * @param {*} event
39
- */
40
- async onTouchEnd (event) {
41
- const res = await super.onTouchEnd(event)
42
- await this.vibrateHandler(res)
43
- }
44
- }
1
+ import { HAPTIC } from 'loupedeck'
2
+ import { BaseLoupeDeckHandler } from '../common/BaseLoupeDeckHandler.mjs'
3
+
4
+ /**
5
+ * Our Special-Handler just used the Default - and adds Vibration after triggers through Button-Releases
6
+ */
7
+ export class ExampleDeviceHandler extends BaseLoupeDeckHandler {
8
+ /**
9
+ * Handle different Vibration-Feedback on OK (true), and NOK (false)
10
+ * @param {*} ok
11
+ */
12
+ async vibrateHandler (ok) {
13
+ if (ok) { await this.device.vibrate(HAPTIC.REV_FASTEST) } else {
14
+ this.device.vibrate(HAPTIC.RUMBLE2)
15
+ }
16
+ }
17
+
18
+ /**
19
+ * Handle Button-Up Events with Vibration Handler
20
+ * @param {*} event
21
+ */
22
+ async onButtonUp (event) {
23
+ const res = await super.onButtonUp(event)
24
+ await this.vibrateHandler(res)
25
+ }
26
+
27
+ /**
28
+ * Handle Knob-Rotation Events with Vibration Handler
29
+ * @param {*} event
30
+ */
31
+ async onRotate (event) {
32
+ const res = await super.onRotate(event)
33
+ await this.vibrateHandler(res)
34
+ }
35
+
36
+ /**
37
+ * Handle Touch-End Events with Vibration Handler
38
+ * @param {*} event
39
+ */
40
+ async onTouchEnd (event) {
41
+ const res = await super.onTouchEnd(event)
42
+ await this.vibrateHandler(res)
43
+ }
44
+ }
@@ -1,21 +1,21 @@
1
- import { ExampleDeviceHandler } from './ExampleDeviceHandler.mjs'
2
-
3
- const handler = new ExampleDeviceHandler('config.json')
4
-
5
-
6
- /**
7
- * Stop the handlers when a signal like SIGINT or SIGTERM arrive
8
- * @param {*} signal
9
- */
10
- const stopHandler = async(signal) => {
11
- console.log(`Receiving ${signal} => Stopping processes.`)
12
- await handler.stop()
13
- }
14
-
15
- // Initiating the signal handlers:
16
- // see https://www.tutorialspoint.com/unix/unix-signals-traps.htm
17
- process.on('SIGINT', async (signal) => { stopHandler(signal) })
18
- process.on('SIGTERM', async (signal) => { stopHandler(signal) })
19
-
20
- // Initiating a process
21
- await handler.start()
1
+ import { ExampleDeviceHandler } from './ExampleDeviceHandler.mjs'
2
+
3
+ const handler = new ExampleDeviceHandler('config.json')
4
+
5
+
6
+ /**
7
+ * Stop the handlers when a signal like SIGINT or SIGTERM arrive
8
+ * @param {*} signal
9
+ */
10
+ const stopHandler = async(signal) => {
11
+ console.log(`Receiving ${signal} => Stopping processes.`)
12
+ await handler.stop()
13
+ }
14
+
15
+ // Initiating the signal handlers:
16
+ // see https://www.tutorialspoint.com/unix/unix-signals-traps.htm
17
+ process.on('SIGINT', async (signal) => { stopHandler(signal) })
18
+ process.on('SIGTERM', async (signal) => { stopHandler(signal) })
19
+
20
+ // Initiating a process
21
+ await handler.start()
package/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { BaseLoupeDeckHandler } from './common/BaseLoupeDeckHandler.mjs'
2
-
3
- export { BaseLoupeDeckHandler }
1
+ import { BaseLoupeDeckHandler } from './common/BaseLoupeDeckHandler.mjs'
2
+
3
+ export { BaseLoupeDeckHandler }
@@ -1,68 +1,69 @@
1
- import format from 'string-template'
2
-
3
- export class BaseIf {
4
- formattedCommand
5
- cmd
6
- options
7
- call (cmd, options = {}) {
8
- var res = this.Check(options)
9
- if (res < 0){
10
- LogError("Missing essential options in dictionary => Quitting\n",res,options)
11
- return false
12
- }
13
-
14
- this.cmd = cmd
15
- this.options = options
16
- this.formattedCommand = this.formatString(cmd, options)
17
- return this.formattedCommand
18
- }
19
-
20
- async stop (){
21
-
22
- }
23
-
24
- formatString (cmd, options = {}) {
25
- let f =""
26
- try{
27
- f = format(cmd, options)
28
- }catch(e){}
29
- return f
30
- }
31
-
32
- Check(options) {
33
- if (!"id" in options)
34
- return -1
35
- if (!"key" in options)
36
- return -2
37
- if (!"state" in options)
38
- return -3
39
- if (!"min" in options)
40
- return -4
41
- if (!"max" in options)
42
- return -5
43
- if (!"color" in options)
44
- return -6
45
- if (!"image" in options)
46
- return -7
47
- return 0
48
- }
49
-
50
- LogError(...args){
51
- let str = new String(args)
52
- process.stderr.write(str.toString())
53
- }
54
-
55
- LogDebug(...args){
56
- if (this.options && this.options.verbose){
57
- let str = new String(args)
58
- process.stdout.write(str.toString())
59
- }
60
- }
61
-
62
- LogInfo(...args){
63
- let str = new String(args)
64
- process.stdout.write(str.toString())
65
- }
66
- }
67
-
68
-
1
+ import format from 'string-template'
2
+ import { EventEmitter } from 'node:events'
3
+
4
+ export class BaseIf extends EventEmitter {
5
+ formattedCommand
6
+ cmd
7
+ options
8
+ call (cmd, options = {}) {
9
+ var res = this.Check(options)
10
+ if (res < 0){
11
+ LogError("Missing essential options in dictionary => Quitting\n",res,options)
12
+ return false
13
+ }
14
+
15
+ this.cmd = cmd
16
+ this.options = options
17
+ this.formattedCommand = this.formatString(cmd, options)
18
+ return this.formattedCommand
19
+ }
20
+
21
+ async stop (){
22
+
23
+ }
24
+
25
+ formatString (cmd, options = {}) {
26
+ let f =""
27
+ try{
28
+ f = format(cmd, options)
29
+ }catch(e){}
30
+ return f
31
+ }
32
+
33
+ Check(options) {
34
+ if (!"id" in options)
35
+ return -1
36
+ if (!"key" in options)
37
+ return -2
38
+ if (!"state" in options)
39
+ return -3
40
+ if (!"min" in options)
41
+ return -4
42
+ if (!"max" in options)
43
+ return -5
44
+ if (!"color" in options)
45
+ return -6
46
+ if (!"image" in options)
47
+ return -7
48
+ return 0
49
+ }
50
+
51
+ LogError(...args){
52
+ let str = new String(args)
53
+ process.stderr.write(str.toString())
54
+ }
55
+
56
+ LogDebug(...args){
57
+ if (this.options && this.options.verbose){
58
+ let str = new String(args)
59
+ process.stdout.write(str.toString())
60
+ }
61
+ }
62
+
63
+ LogInfo(...args){
64
+ let str = new String(args)
65
+ process.stdout.write(str.toString())
66
+ }
67
+ }
68
+
69
+
@@ -1,81 +1,81 @@
1
- import * as http from 'node:http'
2
- import url from 'node:url'
3
- import { BaseIf } from './baseif.mjs'
4
-
5
- /**
6
- * Our Special-Handler just used the Default - and adds Vibration after triggers through Button-Releases
7
- */
8
- export class HTTPif extends BaseIf {
9
- async call (url1, options = {}) {
10
- url1 = super.call(url1, options)
11
- let myURL
12
- try {
13
- myURL = new url.URL(url1)
14
- await this.get(myURL, options)
15
- } catch (e) {
16
- this.LogError(`HTTPif: error with URL: ${e.message}\n`)
17
- return false
18
- }
19
- return true
20
- }
21
-
22
- async stop(){
23
- this.LogInfo("HTTPif: Stopping\n")
24
-
25
- }
26
-
27
- Check(options) {
28
- var res= super.Check(options)
29
- if (res <0)
30
- return res
31
- if (!options.hostname)
32
- return -21
33
- return 0
34
- }
35
-
36
- /**
37
- * Handle a HTTP Get request with Basic Authentification
38
- * @param {*} myURL Uri
39
- */
40
- async get (myURL) {
41
- const auth = 'Basic ' + Buffer.from(myURL.username + ':' + myURL.password).toString('base64')
42
- const getOptions = {
43
- hostname: myURL.hostname,
44
- port: myURL.port,
45
- path: myURL.pathname,
46
- agent: false, // Create a new agent just for this one request
47
- headers: {
48
- Authorization: auth
49
- }
50
- }
51
-
52
- this.LogInfo(`HTTPIf: call URL ${myURL} ${getOptions}\n`)
53
-
54
-
55
- const prom = new Promise((resolve, reject) => {
56
- const req = http.get(getOptions, (response) => {
57
- const chunksOfData = []
58
-
59
- response.on('data', (fragments) => {
60
- chunksOfData.push(fragments)
61
- })
62
-
63
- response.on('end', () => {
64
- const responseBody = Buffer.concat(chunksOfData)
65
- resolve(responseBody.toString())
66
- })
67
-
68
- response.on('error', (error) => {
69
- resolve("")
70
- })
71
- })
72
-
73
- req.on('error', (e) => {
74
- this.LogError(`HTTPif: ignore other errors like ERRNOTCONNECTED: ${e.message}\n`)
75
- return false
76
- });
77
- }).catch(function (error) { // (*)
78
- return false
79
- })
80
- }
81
- }
1
+ import * as http from 'node:http'
2
+ import url from 'node:url'
3
+ import { BaseIf } from './baseif.mjs'
4
+
5
+ /**
6
+ * Our Special-Handler just used the Default - and adds Vibration after triggers through Button-Releases
7
+ */
8
+ export class HTTPif extends BaseIf {
9
+ async call (url1, options = {}) {
10
+ url1 = super.call(url1, options)
11
+ let myURL
12
+ try {
13
+ myURL = new url.URL(url1)
14
+ await this.get(myURL, options)
15
+ } catch (e) {
16
+ this.LogError(`HTTPif: error with URL: ${e.message}\n`)
17
+ return false
18
+ }
19
+ return true
20
+ }
21
+
22
+ async stop(){
23
+ this.LogInfo("HTTPif: Stopping\n")
24
+
25
+ }
26
+
27
+ Check(options) {
28
+ var res= super.Check(options)
29
+ if (res <0)
30
+ return res
31
+ if (!options.hostname)
32
+ return -21
33
+ return 0
34
+ }
35
+
36
+ /**
37
+ * Handle a HTTP Get request with Basic Authentification
38
+ * @param {*} myURL Uri
39
+ */
40
+ async get (myURL) {
41
+ const auth = 'Basic ' + Buffer.from(myURL.username + ':' + myURL.password).toString('base64')
42
+ const getOptions = {
43
+ hostname: myURL.hostname,
44
+ port: myURL.port,
45
+ path: myURL.pathname,
46
+ agent: false, // Create a new agent just for this one request
47
+ headers: {
48
+ Authorization: auth
49
+ }
50
+ }
51
+
52
+ this.LogInfo(`HTTPIf: call URL ${myURL} ${getOptions}\n`)
53
+
54
+
55
+ const prom = new Promise((resolve, reject) => {
56
+ const req = http.get(getOptions, (response) => {
57
+ const chunksOfData = []
58
+
59
+ response.on('data', (fragments) => {
60
+ chunksOfData.push(fragments)
61
+ })
62
+
63
+ response.on('end', () => {
64
+ const responseBody = Buffer.concat(chunksOfData)
65
+ resolve(responseBody.toString())
66
+ })
67
+
68
+ response.on('error', (error) => {
69
+ resolve("")
70
+ })
71
+ })
72
+
73
+ req.on('error', (e) => {
74
+ this.LogError(`HTTPif: ignore other errors like ERRNOTCONNECTED: ${e.message}\n`)
75
+ return false
76
+ });
77
+ }).catch(function (error) { // (*)
78
+ return false
79
+ })
80
+ }
81
+ }