forked from dryark/ios_remote_provider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
151 lines (120 loc) · 3.58 KB
/
main.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
log "github.com/sirupsen/logrus"
uc "github.com/nanoscopic/uclop/mod"
)
func main() {
uclop := uc.NewUclop()
commonOpts := uc.OPTS{
uc.OPT("-debug","Use debug log level",uc.FLAG),
uc.OPT("-warn","Use warn log level",uc.FLAG),
uc.OPT("-config","Config file to use",0),
uc.OPT("-defaults","Defaults config file to use",0),
}
uclop.AddCmd( "run", "Run ControlFloor", runMain, commonOpts )
uclop.AddCmd( "register", "Register against ControlFloor", runRegister, commonOpts )
uclop.AddCmd( "cleanup", "Cleanup leftover processes", runCleanup, nil )
clickOpts := uc.OPTS{
uc.OPT("-el","Element name to click",0),
}
uclop.AddCmd( "click", "Click element", runClick, clickOpts )
uclop.AddCmd( "wda", "Just run WDA", runWDA, nil )
uclop.Run()
}
func wdaForDev1() (*WDA,*DeviceTracker) {
config := NewConfig( "config.json", "default.json" )
devs := GetDevs( config )
dev1 := devs[0]
fmt.Printf("Dev id: %s\n", dev1)
tracker := NewDeviceTracker( config, false )
iifDev := NewIIFDev( tracker.bridge.(*IIFBridge), dev1, "x" )
dev := NewDevice( config, tracker, dev1, iifDev )
iifDev.setProcTracker( tracker )
wda := NewWDA( config, tracker, dev, 8100 )
return wda,tracker
}
func runWDA( cmd *uc.Cmd ) {
runCleanup( cmd )
_,tracker := wdaForDev1()
dotLoop( cmd, tracker )
}
func dotLoop( cmd *uc.Cmd, tracker *DeviceTracker ) {
c := make(chan os.Signal)
stop := make(chan bool)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<- c
stop <- true
tracker.shutdown()
}()
exit := 0
for {
select {
case <- stop:
exit = 1
break
default:
}
if exit == 1 { break }
fmt.Printf(". ")
time.Sleep( time.Second * 1 )
}
runCleanup( cmd )
}
func runClick( cmd *uc.Cmd ) {
runCleanup( cmd )
wda,tracker := wdaForDev1()
startChan := make( chan bool )
wda.startChan = startChan
<- startChan
wda.ensureSession()
wda.OpenControlCenter()
recBtn := wda.ElByName( "Screen Recording" )
fmt.Printf("recBtn:%s\n", recBtn )
wda.ElForceTouch( recBtn, 2000 )
dotLoop( cmd, tracker )
}
func common( cmd *uc.Cmd ) *Config {
debug := cmd.Get("-debug").Bool()
warn := cmd.Get("-warn").Bool()
configPath := cmd.Get("-config").String()
if configPath == "" { configPath = "config.json" }
defaultsPath := cmd.Get("-defaults").String()
if defaultsPath == "" { defaultsPath = "default.json" }
setupLog( debug, warn )
return NewConfig( configPath, defaultsPath )
}
func runCleanup( *uc.Cmd ) {
config := NewConfig( "config.json", "default.json" )
cleanup_procs( config )
}
func runRegister( cmd *uc.Cmd ) {
config := common( cmd )
doregister( config )
}
func runMain( cmd *uc.Cmd ) {
config := common( cmd )
cleanup_procs( config )
devTracker := NewDeviceTracker( config, true )
coro_sigterm( config, devTracker )
coroHttpServer( devTracker )
}
func setupLog( debug bool, warn bool ) {
//log.SetFormatter(&log.JSONFormatter{})
log.SetOutput(os.Stdout)
if debug {
log.SetLevel( log.DebugLevel )
} else if warn {
log.SetLevel( log.WarnLevel )
} else {
log.SetLevel( log.InfoLevel )
}
}
func censorUuid( uuid string ) (string) {
return "***" + uuid[len(uuid)-4:]
}