- Physical displays blanked via overlay - Remote video and input keep working - Exclude overlay from screen capture - Add blackout API and UI toggle - Wire flag through capture protocol
58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
//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, omitLayered, 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, omitLayered)
|
|
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, omitLayered bool) (img models.CapturedImage, err error) {
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
err = fmt.Errorf("panic: %v", r)
|
|
}
|
|
}()
|
|
screenshot.SetOmitLayered(omitLayered)
|
|
return screenshot.CaptureMonitor(monitor, format, quality)
|
|
}
|