-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconnection.go
53 lines (43 loc) · 924 Bytes
/
connection.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
package lcuapi
import "sync/atomic"
type Driver struct {
authKey string
port string
isRunning uint32
*Inquirer
*Watcher
}
func NewDriver() (c *Driver) {
c = &Driver{}
return
}
func (c *Driver) Start(startFunc ...func() error) (keepalive chan error, err error) {
// get lcu process commandline map
mp, err := GetUxProcessCommandlineMapByCmd()
if err != nil {
return
}
c.authKey = mp["remoting-auth-token"]
c.port = mp["app-port"]
c.Inquirer = NewInquirer(c.authKey, c.port)
c.Watcher, err = NewWatcher(c.authKey, c.port)
if err != nil {
return
}
atomic.StoreUint32(&c.isRunning, 1)
for i := range startFunc {
err = startFunc[i]()
if err != nil {
return
}
}
keepalive = make(chan error)
go func() {
defer atomic.StoreUint32(&c.isRunning, 0)
keepalive <- c.Watcher.watch()
}()
return
}
func (c *Driver) IsRunning() bool {
return atomic.LoadUint32(&c.isRunning) == 1
}