Skip to content

Commit

Permalink
cockpit-actions: Allow new actions to be created on the fly
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaellehmkuhl committed Oct 2, 2024
1 parent 6fc12b0 commit a64b49a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/libs/joystick/protocols/cockpit-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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'),
Expand Down Expand Up @@ -70,6 +70,10 @@ interface CallbackEntry {
export class CockpitActionsManager {
actionsCallbacks: Record<string, CallbackEntry> = {}

registerNewAction = (action: CockpitAction): void => {
availableCockpitActions[action.id] = action
}

registerActionCallback = (action: CockpitAction, callback: CockpitActionCallback): string => {
this.actionsCallbacks[action.id] = { action, callback }
return action.id
Expand Down

0 comments on commit a64b49a

Please sign in to comment.