diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2025-09-22 22:43:44 +0200 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2025-09-22 22:43:44 +0200 |
| commit | b19108ed8d4ad56e7bbf1ec59d0470e118275a49 (patch) | |
| tree | 630995aadb2a02bfc3e7a4af3c67c7ac5d786aa2 /widget/widget.go | |
| parent | 433bd54a8b319377166ae3247d705684572cc2a4 (diff) | |
feat(widget): api to handle easily hello
Diffstat (limited to 'widget/widget.go')
| -rw-r--r-- | widget/widget.go | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/widget/widget.go b/widget/widget.go index fa8a308..29a8f3a 100644 --- a/widget/widget.go +++ b/widget/widget.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "io" + "now/widget/api" "os" "os/exec" "strings" @@ -20,14 +21,10 @@ var ( ) type Widget struct { - Name string `json:"name"` - ID string `json:"id"` - Version uint `json:"version"` - Path string `json:"-"` + api.Hello + Path string `json:"-"` } -type Method string - func FromJson(data []byte) (*Widget, error) { var widget Widget return &widget, json.Unmarshal(data, &widget) @@ -71,7 +68,7 @@ func readPluginDir(dir []os.DirEntry, path string) ([]*Widget, error) { } c := make(chan any) ctx, cancel := context.WithTimeout(ctx, 5*time.Second) - go w.Request(ctx, "", c) + go w.Request(ctx, api.MethodHello, c) select { case <-ctx.Done(): cancel() @@ -95,7 +92,7 @@ func readPluginDir(dir []os.DirEntry, path string) ([]*Widget, error) { return widgets, nil } -func (w *Widget) Request(_ context.Context, m Method, c chan<- any, args ...string) { +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...) if cmd.Err != nil { |
