mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-02 05:41:10 -08:00
parent
46992bc7e0
commit
be06c89627
|
@ -57,21 +57,14 @@ func getWindowText(hwnd syscall.Handle, str *uint16, maxCount int32) (length int
|
|||
|
||||
func getWindowFileName(handle syscall.Handle) (string, error) {
|
||||
var pid int
|
||||
// get pid
|
||||
_, _, err := procGetWindowThreadProcessID.Call(uintptr(handle), uintptr(unsafe.Pointer(&pid)))
|
||||
if err != nil && err.Error() != "The operation completed successfully." {
|
||||
return "", errors.New("unable to get window process pid")
|
||||
}
|
||||
_, _, _ = procGetWindowThreadProcessID.Call(uintptr(handle), uintptr(unsafe.Pointer(&pid)))
|
||||
const query = windows.PROCESS_QUERY_INFORMATION | windows.PROCESS_VM_READ
|
||||
h, err := windows.OpenProcess(query, false, uint32(pid))
|
||||
if err != nil {
|
||||
return "", errors.New("unable to open window process")
|
||||
}
|
||||
buf := [1024]byte{}
|
||||
length, _, err := getModuleBaseNameA.Call(uintptr(h), 0, uintptr(unsafe.Pointer(&buf)), 1024)
|
||||
if err != nil && err.Error() != "The operation completed successfully." {
|
||||
return "", errors.New("unable to get window process name")
|
||||
}
|
||||
length, _, _ := getModuleBaseNameA.Call(uintptr(h), 0, uintptr(unsafe.Pointer(&buf)), 1024)
|
||||
filename := string(buf[:length])
|
||||
return strings.ToLower(filename), nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue