Compare commits

...

2 Commits

Author SHA1 Message Date
Armilar
c6939efd70 Merge pull request #1149 from theknut/patch-1
feat: write button event to states
2024-01-23 18:16:19 +01:00
theknut
1746c876bd feat: write button event to states
Whenever a button is pressed there is no event triggered which lets the user easily implement triggers on this event.
This PR adds the functionality that the current button event is written to NSPanel objects structures as states under `0_userdata.0.NSPanel.1.Event.Button`:
- Action - whatever button was pressed (button, media-OnOff, volumeSlider, ...)
- Value -  auxillary value for this action (e.g. action `volumeSlider` - `Value` holds the value the slider was moved to)
- Id
  - Action == `button` - Id of the alias the button is connected to
  - else - Id of the current page item or the page to navigate to
2024-01-22 00:19:23 +01:00

View File

@@ -6312,6 +6312,10 @@ function HandleButtonEvent(words: any): void {
alwaysOn = false;
SendToPanel({ payload: 'timeout~' + getState(NSPanel_Path + 'Config.Screensaver.timeoutScreensaver').val });
}
setOrCreate(NSPanel_Path + "Event.Button.Action", buttonAction ?? words[2]);
setOrCreate(NSPanel_Path + "Event.Button.Value", words[4] != undefined ? words[4] : null);
setOrCreate(NSPanel_Path + "Event.Button.Id", id);
if (Debug) {
log('HandleButtonEvent buttonAction: ' + buttonAction, 'info');
@@ -7359,6 +7363,14 @@ function HandleButtonEvent(words: any): void {
}
}
function setOrCreate(id : string, value : any, forceCreation: boolean = true, common: Partial<iobJS.StateCommon> = { }, callback?: iobJS.SetStateCallback) {
if (!existsState(id)) {
createState(id, value, forceCreation, common, callback);
} else {
setState(id, value);
}
}
//Determination of page navigation (CustomSend-Payload)
function GetNavigationString(pageId: number): string {
try {