fix: find console window

This commit is contained in:
ShuheiKubota 2019-11-18 12:59:18 +09:00
parent e0fddf6b59
commit d0b7427efd

48
vvin.go
View file

@ -48,30 +48,48 @@ func (c *globalCmd) Before() error {
} }
an := ancestors() an := ancestors()
t := strings.ToLower(c.Target)
for _, w := range wins { if c.Target == "" {
ancestor := false loopConsole:
for _, p := range an { for _, p := range an {
if w.PID == p { for _, w := range wins {
ancestor = true if w.PID == p {
break if c.Debug {
rog.Printf("win: %#v", w)
}
c.targetHandle = w.Handle
break loopConsole
}
} }
} }
} else {
t := strings.ToLower(c.Target)
if c.Debug { for _, w := range wins {
rog.Printf("win: %#v (ancestor? %v)", w, ancestor) ancestor := false
} for _, p := range an {
if t != "" && !ancestor { if w.PID == p {
wt := strings.ToLower(w.Title) ancestor = true
break
}
}
if strings.Contains(wt, t) { if c.Debug {
rog.Printf("win: %#v (ancestor? %v)", w, ancestor)
}
if t != "" && !ancestor {
wt := strings.ToLower(w.Title)
if strings.Contains(wt, t) {
c.targetHandle = w.Handle
break
}
} else if t == "" && ancestor {
c.targetHandle = w.Handle c.targetHandle = w.Handle
break break
} }
} else if t == "" && ancestor {
c.targetHandle = w.Handle
break
} }
} }