mirror of
https://codeberg.org/superseriousbusiness/gotosocial.git
synced 2024-12-22 17:10:20 +03:00
014d7ac131
Bumps [github.com/spf13/cobra](https://github.com/spf13/cobra) from 1.6.1 to 1.7.0. - [Release notes](https://github.com/spf13/cobra/releases) - [Commits](https://github.com/spf13/cobra/compare/v1.6.1...v1.7.0) --- updated-dependencies: - dependency-name: github.com/spf13/cobra dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package mousetrap
|
|
|
|
import (
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
func getProcessEntry(pid int) (*syscall.ProcessEntry32, error) {
|
|
snapshot, err := syscall.CreateToolhelp32Snapshot(syscall.TH32CS_SNAPPROCESS, 0)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer syscall.CloseHandle(snapshot)
|
|
var procEntry syscall.ProcessEntry32
|
|
procEntry.Size = uint32(unsafe.Sizeof(procEntry))
|
|
if err = syscall.Process32First(snapshot, &procEntry); err != nil {
|
|
return nil, err
|
|
}
|
|
for {
|
|
if procEntry.ProcessID == uint32(pid) {
|
|
return &procEntry, nil
|
|
}
|
|
err = syscall.Process32Next(snapshot, &procEntry)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
}
|
|
|
|
// StartedByExplorer returns true if the program was invoked by the user double-clicking
|
|
// on the executable from explorer.exe
|
|
//
|
|
// It is conservative and returns false if any of the internal calls fail.
|
|
// It does not guarantee that the program was run from a terminal. It only can tell you
|
|
// whether it was launched from explorer.exe
|
|
func StartedByExplorer() bool {
|
|
pe, err := getProcessEntry(syscall.Getppid())
|
|
if err != nil {
|
|
return false
|
|
}
|
|
return "explorer.exe" == syscall.UTF16ToString(pe.ExeFile[:])
|
|
}
|