From d6b2f72b379a4ce54f12d7720c7ad8113b2ccd8b Mon Sep 17 00:00:00 2001 From: Julian Waller Date: Mon, 27 Nov 2023 22:36:02 +0000 Subject: [PATCH] feat: allow specifying 'learn' function timeout --- src/host-api/api.ts | 8 +++++--- src/internal/actions.ts | 1 + src/internal/feedback.ts | 1 + src/module-api/action.ts | 7 +++++++ src/module-api/feedback.ts | 7 +++++++ 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/host-api/api.ts b/src/host-api/api.ts index b91755b..a021859 100644 --- a/src/host-api/api.ts +++ b/src/host-api/api.ts @@ -103,9 +103,10 @@ export interface SetActionDefinitionsMessage { actions: Array<{ id: string name: string - description?: string + description: string | undefined options: EncodeIsVisible[] // TODO module-lib - versioned types? hasLearn: boolean + learnTimeout: number | undefined }> } @@ -113,12 +114,13 @@ export interface SetFeedbackDefinitionsMessage { feedbacks: Array<{ id: string name: string - description?: string + description: string | undefined options: EncodeIsVisible[] // TODO module-lib - versioned types? type: 'boolean' | 'advanced' - defaultStyle?: Partial + defaultStyle?: CompanionFeedbackButtonStyleResult hasLearn: boolean showInvert: boolean | undefined + learnTimeout: number | undefined }> } diff --git a/src/internal/actions.ts b/src/internal/actions.ts index df0fcad..4e778cf 100644 --- a/src/internal/actions.ts +++ b/src/internal/actions.ts @@ -196,6 +196,7 @@ export class ActionManager { description: action.description, options: serializeIsVisibleFn(action.options), hasLearn: !!action.learn, + learnTimeout: action.learnTimeout, }) // Remember the definition locally diff --git a/src/internal/feedback.ts b/src/internal/feedback.ts index 038f894..bd5f0fc 100644 --- a/src/internal/feedback.ts +++ b/src/internal/feedback.ts @@ -393,6 +393,7 @@ export class FeedbackManager { type: feedback.type, defaultStyle: feedback.type === 'boolean' ? feedback.defaultStyle : undefined, hasLearn: !!feedback.learn, + learnTimeout: feedback.learnTimeout, showInvert: feedback.type === 'boolean' ? feedback.showInvert : false, }) diff --git a/src/module-api/action.ts b/src/module-api/action.ts index 4eef7cb..f5eaa15 100644 --- a/src/module-api/action.ts +++ b/src/module-api/action.ts @@ -56,6 +56,13 @@ export interface CompanionActionDefinition { action: CompanionActionEvent, context: CompanionActionContext ) => CompanionOptionValues | undefined | Promise + + /** + * Timeout for the 'learn' function (in milliseconds) + * Companion sets a default value of 5s, to ensure that the learn does not get stuck never completing + * You can change this if this number does not work for you, but you should keep it to a sensible value + */ + learnTimeout?: number } /** diff --git a/src/module-api/feedback.ts b/src/module-api/feedback.ts index 903f870..9191354 100644 --- a/src/module-api/feedback.ts +++ b/src/module-api/feedback.ts @@ -115,6 +115,13 @@ export interface CompanionFeedbackDefinitionBase { action: CompanionFeedbackInfo, context: CompanionFeedbackContext ) => CompanionOptionValues | undefined | Promise + + /** + * Timeout for the 'learn' function (in milliseconds) + * Companion sets a default value of 5s, to ensure that the learn does not get stuck never completing + * You can change this if this number does not work for you, but you should keep it to a sensible value + */ + learnTimeout?: number } /**