diff options
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 { |
