Author: Amiel Martin [amiel.martin@gmail.com]
Hash: 064d2f0341a671b98190f22fa5978cbd548d4f97
Timestamp: Wed, 13 Oct 2021 23:26:42 +0000 (3 years ago)

+21 -17 +/-2 browse
Use a separate socket path to publish so pomo can publish and listen on different sockets
1diff --git a/pkg/internal/config.go b/pkg/internal/config.go
2index 04d3a44..d76fe4b 100644
3--- a/pkg/internal/config.go
4+++ b/pkg/internal/config.go
5 @@ -27,6 +27,8 @@ type Config struct {
6 // PublishJson pushes socket updates as a JSON
7 // encoded status message instead of string formatted
8 PublishJson bool `json:"publishJson"`
9+ // If Publish is true, provide a socket path to publish to
10+ PublishSocketPath string `json:"publishSocketPath"`
11 }
12
13 type ColorMap struct {
14 diff --git a/pkg/internal/server.go b/pkg/internal/server.go
15index 03e7443..5866a73 100644
16--- a/pkg/internal/server.go
17+++ b/pkg/internal/server.go
18 @@ -12,12 +12,12 @@ import (
19 // Server listens on a Unix domain socket
20 // for Pomo status requests
21 type Server struct {
22- listener net.Listener
23- runner *TaskRunner
24- running bool
25- publish bool
26- publishJson bool
27- socketPath string
28+ listener net.Listener
29+ runner *TaskRunner
30+ running bool
31+ publish bool
32+ publishJson bool
33+ publishSocketPath string
34 }
35
36 func (s *Server) listen() {
37 @@ -38,7 +38,7 @@ func (s *Server) listen() {
38 func (s *Server) push() {
39 ticker := time.NewTicker(1 * time.Second)
40 for s.running {
41- conn, err := net.Dial("unix", s.socketPath)
42+ conn, err := net.Dial("unix", s.publishSocketPath)
43 if err != nil {
44 <-ticker.C
45 continue
46 @@ -59,9 +59,9 @@ func (s *Server) Start() {
47 s.running = true
48 if s.publish {
49 go s.push()
50- } else {
51- go s.listen()
52 }
53+
54+ go s.listen()
55 }
56
57 func (s *Server) Stop() {
58 @@ -72,13 +72,6 @@ func (s *Server) Stop() {
59 }
60
61 func NewServer(runner *TaskRunner, config *Config) (*Server, error) {
62- if config.Publish {
63- return &Server{
64- runner: runner,
65- publish: true,
66- publishJson: config.PublishJson,
67- socketPath: config.SocketPath}, nil
68- }
69 //check if socket file exists
70 if _, err := os.Stat(config.SocketPath); err == nil {
71 _, err := net.Dial("unix", config.SocketPath)
72 @@ -94,7 +87,16 @@ func NewServer(runner *TaskRunner, config *Config) (*Server, error) {
73 if err != nil {
74 return nil, err
75 }
76- return &Server{listener: listener, runner: runner}, nil
77+
78+ server := &Server{
79+ listener: listener,
80+ runner: runner,
81+ publish: config.Publish,
82+ publishJson: config.PublishJson,
83+ publishSocketPath: config.PublishSocketPath,
84+ }
85+
86+ return server, nil
87 }
88
89 // Client makes requests to a listening