From 215ce412a8bf37f31f5e779fe45930b87b1bffec Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Mon, 22 Sep 2025 23:00:18 +0200 Subject: feat(widget): credits --- widget/widget.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'widget/widget.go') diff --git a/widget/widget.go b/widget/widget.go index 29a8f3a..140cbf1 100644 --- a/widget/widget.go +++ b/widget/widget.go @@ -92,6 +92,26 @@ func readPluginDir(dir []os.DirEntry, path string) ([]*Widget, error) { return widgets, nil } +func (w *Widget) FetchCredits(ctx context.Context) (*api.Credits, error) { + c := make(chan any) + go w.Request(ctx, api.MethodCredits, c) + select { + case <-ctx.Done(): + return nil, ctx.Err() + case out := <-c: + err, ok := out.(error) + if ok { + return nil, err + } + b, ok := out.([]byte) + if !ok { + return nil, errors.Join(ErrUnexceptedType, fmt.Errorf("got %T instead of []byte", out)) + } + var credits api.Credits + return &credits, json.Unmarshal(b, &credits) + } +} + func (w *Widget) Request(_ context.Context, m api.Method, c chan<- any, args ...string) { args = append([]string{string(m)}, args...) cmd := exec.Command(fmt.Sprintf("./plugins/%s", w.Path), args...) -- cgit v1.2.3