4 Commits

Author SHA1 Message Date
16d2e8e8fd recycle json decoder 2025-08-23 12:36:36 +02:00
713a6bd6be renamed Action method to DoAction 2025-07-30 10:09:22 +02:00
580b7d5a3a changed string type of output reference to OutputName 2025-07-30 10:04:09 +02:00
837fec3f8f make Outputname a string alias 2025-07-29 16:39:53 +02:00
4 changed files with 6 additions and 4 deletions

2
do.go
View File

@ -5,7 +5,7 @@ import (
"fmt" "fmt"
) )
func (c *Client) Action(action Action) error { func (c *Client) DoAction(action Action) error {
// print request and response to console: // print request and response to console:
// //
// io.Copy(os.Stdout, asJsonReader(action)) // io.Copy(os.Stdout, asJsonReader(action))

View File

@ -2,7 +2,7 @@ package niri
import "encoding/json" import "encoding/json"
type OutputName string type OutputName = string
type Output struct { type Output struct {
Name OutputName `json:"name"` Name OutputName `json:"name"`

View File

@ -7,7 +7,7 @@ type WorkspaceID int
type Workspace struct { type Workspace struct {
ID WorkspaceID `json:"id"` ID WorkspaceID `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Output string `json:"output"` Output OutputName `json:"output"`
Urgent bool `json:"is_urgent"` Urgent bool `json:"is_urgent"`
Active bool `json:"is_active"` Active bool `json:"is_active"`
Focused bool `json:"is_focused"` Focused bool `json:"is_focused"`

View File

@ -77,9 +77,11 @@ func readSocketGeneric[T any](ctx context.Context, socket string, body io.Reader
defer close(out) defer close(out)
defer r.Close() defer r.Close()
dec := json.NewDecoder(r)
for ctx.Err() == nil { for ctx.Err() == nil {
value := new(T) value := new(T)
if err := json.NewDecoder(r).Decode(value); err != nil { if err := dec.Decode(value); err != nil {
if errors.Is(err, io.EOF) { if errors.Is(err, io.EOF) {
return return
} else { } else {