Skip to content

Commit 1d73421

Browse files
committed
examples:wowjump control goroutine.
1 parent 6525584 commit 1d73421

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

examples/wowjump/config.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/whtiehack/wingui"
77
"io/ioutil"
88
"log"
9+
"os"
910
"strconv"
1011
"syscall"
1112
)
@@ -29,7 +30,8 @@ var config = &Config{
2930
}
3031

3132
func init() {
32-
file, err := ioutil.ReadFile("wowjump_config.txt")
33+
configDir, _ := os.UserConfigDir()
34+
file, err := ioutil.ReadFile(configDir + "/wowjump/wowjump_config.txt")
3335
if err != nil {
3436
return
3537
}
@@ -48,7 +50,8 @@ func (c *Config) Save() {
4850
config.InputTime, _ = strconv.Atoi(c.editInputTime.Text())
4951
config.CharWaitTime, _ = strconv.Atoi(c.editCharWaitTime.Text())
5052
file, _ := json.MarshalIndent(c, "", " ")
51-
ioutil.WriteFile("wowjump_config.txt", file, 777)
53+
configDir, _ := os.UserConfigDir()
54+
ioutil.WriteFile(configDir+"/wowjump/wowjump_config.txt", file, 777)
5255
}
5356

5457
func (c *Config) InitVal() {

examples/wowjump/control.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package main
2+
3+
import "log"
4+
5+
func process() {
6+
defer func() {
7+
err := recover()
8+
log.Println("process end??", err)
9+
if err != nil {
10+
go process()
11+
}
12+
}()
13+
var selfLogout = make([]*Logout, 0, 10)
14+
for {
15+
mux.Lock()
16+
if !running || logouts == nil || len(logouts) == 0 {
17+
mux.Unlock()
18+
sleep(1000)
19+
continue
20+
}
21+
selfLogout = make([]*Logout, len(logouts))
22+
copy(selfLogout, logouts)
23+
mux.Unlock()
24+
for _, logout := range selfLogout {
25+
// 处理逻辑
26+
if !logout.IsValid() {
27+
continue
28+
}
29+
logout.Update()
30+
}
31+
randomSleep(5000, 2500)
32+
}
33+
}

examples/wowjump/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ func init() {
3131
win.MessageBox(0, &syscall.StringToUTF16("进程已经开启了,不可以多开")[0], nil, 0)
3232
os.Exit(-1)
3333
}
34+
// control
35+
go process()
3436
}
3537

3638
var btn *wingui.Button
@@ -102,7 +104,7 @@ func btnClick() {
102104
}
103105
out.SetText("")
104106
log.Printf("找到 %d 个 WOW窗口\n", len(logouts))
105-
text = "关闭"
107+
text = "停止"
106108
//str := skillKey.Text()
107109
//config.SkillKey = str
108110
//randomSkill.ParseSkillKey(str)

0 commit comments

Comments
 (0)