-
Notifications
You must be signed in to change notification settings - Fork 11
/
watch_client.go
54 lines (46 loc) · 1001 Bytes
/
watch_client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package client
import (
"fmt"
"github.com/atotto/clipboard"
"github.com/darmiel/yaxc/internal/common"
"time"
)
func WatchClient(c *Check, d time.Duration, done chan bool) {
t := time.NewTicker(d)
for {
select {
case <-done:
fmt.Println(common.StyleInfo(), "Stopping", common.WordClient(), "Watcher")
return
case <-t.C:
if err := c.CheckClient(); err != nil {
fmt.Println(common.StyleWarn(), err)
}
break
}
}
}
func (c *Check) CheckClient() (err error) {
// check if clipboard actions are available
if clipboard.Unsupported {
return ErrUnsupported
}
// lock
c.mu.Lock()
defer c.mu.Unlock()
// get clipboard
var cb string
cb, _ = common.GetClipboard(c.useBase64)
// ignore empty clipboard
if cb == "" {
return
}
if c.previousClipboard == cb {
return
}
c.previousClipboard = cb
// upload to server
err = c.a.SetContent(c.path, c.pass, cb)
fmt.Println(common.StyleUpdate(), common.WordServer(), "<-", common.PrettyLimit(cb, 48))
return
}