Commit
+26 -17 +/-2 browse
1 | diff --git a/pkg/internal/config.go b/pkg/internal/config.go |
2 | index 04d3a44..0df5cfb 100644 |
3 | --- a/pkg/internal/config.go |
4 | +++ b/pkg/internal/config.go |
5 | @@ -2,6 +2,7 @@ package pomo |
6 | |
7 | import ( |
8 | "encoding/json" |
9 | + "fmt" |
10 | "io/ioutil" |
11 | "os" |
12 | "path" |
13 | @@ -27,6 +28,8 @@ type Config struct { |
14 | // PublishJson pushes socket updates as a JSON |
15 | // encoded status message instead of string formatted |
16 | PublishJson bool `json:"publishJson"` |
17 | + // If Publish is true, provide a socket path to publish to |
18 | + PublishSocketPath string `json:"publishSocketPath"` |
19 | } |
20 | |
21 | type ColorMap struct { |
22 | @@ -116,5 +119,9 @@ func LoadConfig(configPath string, config *Config) error { |
23 | if config.IconPath == "" { |
24 | config.IconPath = path.Join(config.BasePath, "/icon.png") |
25 | } |
26 | + if config.Publish && (config.PublishSocketPath == "" || config.PublishSocketPath == config.SocketPath) { |
27 | + return fmt.Errorf("'publish' option now requires 'publishSocketPath' which must not be the same as 'socketPath'") |
28 | + } |
29 | + |
30 | return nil |
31 | } |
32 | diff --git a/pkg/internal/server.go b/pkg/internal/server.go |
33 | index 03e7443..5866a73 100644 |
34 | --- a/pkg/internal/server.go |
35 | +++ b/pkg/internal/server.go |
36 | @@ -12,12 +12,12 @@ import ( |
37 | // Server listens on a Unix domain socket |
38 | // for Pomo status requests |
39 | type Server struct { |
40 | - listener net.Listener |
41 | - runner *TaskRunner |
42 | - running bool |
43 | - publish bool |
44 | - publishJson bool |
45 | - socketPath string |
46 | + listener net.Listener |
47 | + runner *TaskRunner |
48 | + running bool |
49 | + publish bool |
50 | + publishJson bool |
51 | + publishSocketPath string |
52 | } |
53 | |
54 | func (s *Server) listen() { |
55 | @@ -38,7 +38,7 @@ func (s *Server) listen() { |
56 | func (s *Server) push() { |
57 | ticker := time.NewTicker(1 * time.Second) |
58 | for s.running { |
59 | - conn, err := net.Dial("unix", s.socketPath) |
60 | + conn, err := net.Dial("unix", s.publishSocketPath) |
61 | if err != nil { |
62 | <-ticker.C |
63 | continue |
64 | @@ -59,9 +59,9 @@ func (s *Server) Start() { |
65 | s.running = true |
66 | if s.publish { |
67 | go s.push() |
68 | - } else { |
69 | - go s.listen() |
70 | } |
71 | + |
72 | + go s.listen() |
73 | } |
74 | |
75 | func (s *Server) Stop() { |
76 | @@ -72,13 +72,6 @@ func (s *Server) Stop() { |
77 | } |
78 | |
79 | func NewServer(runner *TaskRunner, config *Config) (*Server, error) { |
80 | - if config.Publish { |
81 | - return &Server{ |
82 | - runner: runner, |
83 | - publish: true, |
84 | - publishJson: config.PublishJson, |
85 | - socketPath: config.SocketPath}, nil |
86 | - } |
87 | //check if socket file exists |
88 | if _, err := os.Stat(config.SocketPath); err == nil { |
89 | _, err := net.Dial("unix", config.SocketPath) |
90 | @@ -94,7 +87,16 @@ func NewServer(runner *TaskRunner, config *Config) (*Server, error) { |
91 | if err != nil { |
92 | return nil, err |
93 | } |
94 | - return &Server{listener: listener, runner: runner}, nil |
95 | + |
96 | + server := &Server{ |
97 | + listener: listener, |
98 | + runner: runner, |
99 | + publish: config.Publish, |
100 | + publishJson: config.PublishJson, |
101 | + publishSocketPath: config.PublishSocketPath, |
102 | + } |
103 | + |
104 | + return server, nil |
105 | } |
106 | |
107 | // Client makes requests to a listening |