Skip to content

Commit

Permalink
support multiple actions (so refresh works alongside others) #626
Browse files Browse the repository at this point in the history
  • Loading branch information
matryer committed Mar 11, 2021
1 parent 9a77bc0 commit ecd1e01
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions pkg/plugins/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,36 @@ func (i *Item) Action() ActionFunc {
if i.Plugin != nil {
debugf = i.Plugin.Debugf
}
var actions []ActionFunc
if i.Params.Href != "" {
return actionHref(debugf, i.Params.Href)
actions = append(actions, actionHref(debugf, i.Params.Href))
}
if i.Params.Shell != "" {
return actionShell(debugf, i, i.Params.Shell, i.Params.ShellParams)
actions = append(actions, actionShell(debugf, i, i.Params.Shell, i.Params.ShellParams))
}
if i.Params.Refresh == true {
return actionRefresh(debugf, func(_ context.Context) {
actions = append(actions, actionRefresh(debugf, func(ctx context.Context) {
i.Plugin.TriggerRefresh()
})
}))
}
if len(actions) == 0 {
return nil // no actions
}
return actionFuncs(actions...)
}

// actionFuncs makes an ActionFunc that runs multuple functions
// in order.
func actionFuncs(actions ...ActionFunc) ActionFunc {
return func(ctx context.Context) {
for i := range actions {
if err := ctx.Err(); err != nil {
return // don't bother - context cancelled
}
fn := actions[i]
fn(ctx)
}
}
return nil // no action
}

// actionHref gets an ActionFunc that opens a URL.
Expand Down

0 comments on commit ecd1e01

Please sign in to comment.