Skip to content

Commit

Permalink
fix(Streamdeck): simplify feedback update
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarpl committed Nov 22, 2023
1 parent 283fe59 commit b36616f
Showing 1 changed file with 16 additions and 28 deletions.
44 changes: 16 additions & 28 deletions packages/input-manager/src/integrations/streamdeck/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ export class StreamDeckDevice extends Device {

this.#isButtonDown[id] = true

this.updateFeedback(id, this.#isButtonDown[id] ?? false).catch((err) =>
this.logger.error(`Stream Deck: Error updating feedback: ${err}`)
)
this.quietUpdateFeedbackWithDownState(id)
})
this.#streamDeck.addListener('up', (key) => {
const id = `${key}`
Expand All @@ -75,9 +73,7 @@ export class StreamDeckDevice extends Device {

this.#isButtonDown[id] = false

this.updateFeedback(id, this.#isButtonDown[id] ?? false).catch((err) =>
this.logger.error(`Stream Deck: Error updating feedback: ${err}`)
)
this.quietUpdateFeedbackWithDownState(id)
})
this.#streamDeck.addListener('encoderDown', (encoder) => {
const id = `Enc${encoder}`
Expand All @@ -87,9 +83,7 @@ export class StreamDeckDevice extends Device {

this.#isButtonDown[id] = true

this.updateFeedback(id, this.#isButtonDown[id] ?? false).catch((err) =>
this.logger.error(`Stream Deck: Error updating feedback: ${err}`)
)
this.quietUpdateFeedbackWithDownState(id)
})
this.#streamDeck.addListener('encoderUp', (encoder) => {
const id = `Enc${encoder}`
Expand All @@ -99,9 +93,7 @@ export class StreamDeckDevice extends Device {

this.#isButtonDown[id] = false

this.updateFeedback(id, this.#isButtonDown[id] ?? false).catch((err) =>
this.logger.error(`Stream Deck: Error updating feedback: ${err}`)
)
this.quietUpdateFeedbackWithDownState(id)
})
this.#streamDeck.addListener('rotateLeft', (encoder, deltaValue) => {
const id = `Enc${encoder}`
Expand All @@ -115,9 +107,7 @@ export class StreamDeckDevice extends Device {
}
})

this.updateFeedback(id, this.#isButtonDown[id] ?? false).catch((err) =>
this.logger.error(`Stream Deck: Error updating feedback: ${err}`)
)
this.quietUpdateFeedbackWithDownState(id)
})
this.#streamDeck.addListener('rotateRight', (encoder, deltaValue) => {
const id = `Enc${encoder}`
Expand All @@ -131,9 +121,7 @@ export class StreamDeckDevice extends Device {
}
})

this.updateFeedback(id, this.#isButtonDown[id] ?? false).catch((err) =>
this.logger.error(`Stream Deck: Error updating feedback: ${err}`)
)
this.quietUpdateFeedbackWithDownState(id)
})
this.#streamDeck.addListener('lcdShortPress', (encoder, position) => {
const id = `Enc${encoder}`
Expand All @@ -147,9 +135,7 @@ export class StreamDeckDevice extends Device {
},
})

this.updateFeedback(id, this.#isButtonDown[id] ?? false).catch((err) =>
this.logger.error(`Stream Deck: Error updating feedback: ${err}`)
)
this.quietUpdateFeedbackWithDownState(id)
})
this.#streamDeck.addListener('lcdLongPress', (encoder, position) => {
const id = `Enc${encoder}`
Expand All @@ -163,9 +149,7 @@ export class StreamDeckDevice extends Device {
},
})

this.updateFeedback(id, this.#isButtonDown[id] ?? false).catch((err) =>
this.logger.error(`Stream Deck: Error updating feedback: ${err}`)
)
this.quietUpdateFeedbackWithDownState(id)
})
this.#streamDeck.addListener('lcdSwipe', (fromEncoder, toEncoder, from, to) => {
const id = `Enc${fromEncoder}`
Expand All @@ -183,9 +167,7 @@ export class StreamDeckDevice extends Device {
},
})

this.updateFeedback(id, this.#isButtonDown[id] ?? false).catch((err) =>
this.logger.error(`Stream Deck: Error updating feedback: ${err}`)
)
this.quietUpdateFeedbackWithDownState(id)
})
this.#streamDeck.addListener('error', (err) => {
this.logger.error(String(err))
Expand Down Expand Up @@ -257,6 +239,12 @@ export class StreamDeckDevice extends Device {
}
}

private quietUpdateFeedbackWithDownState(trigger: string): void {
this.updateFeedback(trigger, this.#isButtonDown[trigger] ?? false).catch((err) =>
this.logger.error(`Stream Deck: Error updating feedback: ${err}`)
)
}

async setFeedback(triggerId: string, feedback: SomeFeedback): Promise<void> {
if (!this.#streamDeck) return

Expand All @@ -268,7 +256,7 @@ export class StreamDeckDevice extends Device {
}

async clearFeedbackAll(): Promise<void> {
for (const keyStr of this.#feedbacks.allFeedbacks()) {
for (const keyStr of this.#feedbacks.allFeedbackIds()) {
const key = keyStr
await this.updateFeedback(key, false)
}
Expand Down

0 comments on commit b36616f

Please sign in to comment.