diff --git a/cmd/streamdeck/action_page.go b/cmd/streamdeck/action_page.go index 0c9ecfc..79594a5 100644 --- a/cmd/streamdeck/action_page.go +++ b/cmd/streamdeck/action_page.go @@ -1,6 +1,10 @@ package main -import "github.com/pkg/errors" +import ( + "math" + + "github.com/pkg/errors" +) func init() { registerAction("page", actionPage{}) @@ -9,10 +13,18 @@ func init() { type actionPage struct{} func (actionPage) Execute(attributes map[string]interface{}) error { - name, ok := attributes["name"].(string) - if !ok { - return errors.New("No page name supplied") + name, nameOk := attributes["name"].(string) + relative, relativeOk := attributes["relative"].(int) + + if nameOk && name != "" { + return errors.Wrap(togglePage(name), "switch page") } - return errors.Wrap(togglePage(name), "Unable to switch page") + if absRel := int(math.Abs(float64(relative))); relativeOk && absRel != 0 && absRel < len(pageStack) { + nextPage := pageStack[absRel] + pageStack = pageStack[absRel+1:] + return errors.Wrap(togglePage(nextPage), "switch relative page") + } + + return errors.New("no page name or relative move supplied") } diff --git a/cmd/streamdeck/main.go b/cmd/streamdeck/main.go index 5f50dfb..466f0b8 100644 --- a/cmd/streamdeck/main.go +++ b/cmd/streamdeck/main.go @@ -34,6 +34,7 @@ var ( activePageCtxCancel context.CancelFunc activePageName string activeLoops []refreshingDisplayElement + pageStack []string sd *streamdeck.Client @@ -245,6 +246,11 @@ func togglePage(page string) error { }(idx, kd) } + pageStack = append([]string{page}, pageStack...) + if len(pageStack) > 100 { + pageStack = pageStack[:100] + } + return nil }