diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2025-09-22 23:00:18 +0200 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2025-09-22 23:00:18 +0200 |
| commit | 215ce412a8bf37f31f5e779fe45930b87b1bffec (patch) | |
| tree | 2d1ff059478e1546cb8b192739aa1becc6082c7c /widget/widget.go | |
| parent | b19108ed8d4ad56e7bbf1ec59d0470e118275a49 (diff) | |
feat(widget): creditsfeat/custom-widget
Diffstat (limited to 'widget/widget.go')
| -rw-r--r-- | widget/widget.go | 20 |
1 files changed, 20 insertions, 0 deletions
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...) |
