From a64b49a136848a6ba07c0fedfb36a0632b4e07cf Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Wed, 2 Oct 2024 15:17:28 -0300 Subject: [PATCH] cockpit-actions: Allow new actions to be created on the fly --- src/libs/joystick/protocols/cockpit-actions.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libs/joystick/protocols/cockpit-actions.ts b/src/libs/joystick/protocols/cockpit-actions.ts index 0c509b5c9..60fd2aa27 100644 --- a/src/libs/joystick/protocols/cockpit-actions.ts +++ b/src/libs/joystick/protocols/cockpit-actions.ts @@ -23,7 +23,7 @@ export enum CockpitActionsFunction { * An action to be performed by Cockpit itself */ export class CockpitAction implements ProtocolAction { - id: CockpitActionsFunction + id: CockpitActionsFunction | string name: string readonly protocol = JoystickProtocol.CockpitAction @@ -35,7 +35,7 @@ export class CockpitAction implements ProtocolAction { } // Available actions -export const availableCockpitActions: { [key in CockpitActionsFunction]: CockpitAction } = { +export const availableCockpitActions: { [key in CockpitActionsFunction | string]: CockpitAction } = { [CockpitActionsFunction.go_to_next_view]: new CockpitAction(CockpitActionsFunction.go_to_next_view, 'Go to next view'), [CockpitActionsFunction.go_to_previous_view]: new CockpitAction(CockpitActionsFunction.go_to_previous_view, 'Go to previous view'), [CockpitActionsFunction.toggle_full_screen]: new CockpitAction(CockpitActionsFunction.toggle_full_screen, 'Toggle full screen'), @@ -70,6 +70,10 @@ interface CallbackEntry { export class CockpitActionsManager { actionsCallbacks: Record = {} + registerNewAction = (action: CockpitAction): void => { + availableCockpitActions[action.id] = action + } + registerActionCallback = (action: CockpitAction, callback: CockpitActionCallback): string => { this.actionsCallbacks[action.id] = { action, callback } return action.id