Skip to content

Commit

Permalink
examples:wowjump control goroutine.
Browse files Browse the repository at this point in the history
  • Loading branch information
whtiehack committed Sep 10, 2019
1 parent 6525584 commit 1d73421
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
7 changes: 5 additions & 2 deletions examples/wowjump/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/whtiehack/wingui"
"io/ioutil"
"log"
"os"
"strconv"
"syscall"
)
Expand All @@ -29,7 +30,8 @@ var config = &Config{
}

func init() {
file, err := ioutil.ReadFile("wowjump_config.txt")
configDir, _ := os.UserConfigDir()
file, err := ioutil.ReadFile(configDir + "/wowjump/wowjump_config.txt")
if err != nil {
return
}
Expand All @@ -48,7 +50,8 @@ func (c *Config) Save() {
config.InputTime, _ = strconv.Atoi(c.editInputTime.Text())
config.CharWaitTime, _ = strconv.Atoi(c.editCharWaitTime.Text())
file, _ := json.MarshalIndent(c, "", " ")
ioutil.WriteFile("wowjump_config.txt", file, 777)
configDir, _ := os.UserConfigDir()
ioutil.WriteFile(configDir+"/wowjump/wowjump_config.txt", file, 777)
}

func (c *Config) InitVal() {
Expand Down
33 changes: 33 additions & 0 deletions examples/wowjump/control.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import "log"

func process() {
defer func() {
err := recover()
log.Println("process end??", err)
if err != nil {
go process()
}
}()
var selfLogout = make([]*Logout, 0, 10)
for {
mux.Lock()
if !running || logouts == nil || len(logouts) == 0 {
mux.Unlock()
sleep(1000)
continue
}
selfLogout = make([]*Logout, len(logouts))
copy(selfLogout, logouts)
mux.Unlock()
for _, logout := range selfLogout {
// 处理逻辑
if !logout.IsValid() {
continue
}
logout.Update()
}
randomSleep(5000, 2500)
}
}
4 changes: 3 additions & 1 deletion examples/wowjump/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func init() {
win.MessageBox(0, &syscall.StringToUTF16("进程已经开启了,不可以多开")[0], nil, 0)
os.Exit(-1)
}
// control
go process()
}

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

0 comments on commit 1d73421

Please sign in to comment.