mirror of
https://codeberg.org/PLG-Development/PLG-MuDiCS
synced 2026-07-06 00:47:09 +00:00
chore(display): support multiple screenshot tools
This commit is contained in:
+12
-4
@@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -73,13 +74,20 @@ func KeyboardInput(key int) error {
|
|||||||
func TakeScreenshot() (string, error) {
|
func TakeScreenshot() (string, error) {
|
||||||
tempFilePath := filepath.Join(os.TempDir(), fmt.Sprintf("screenshot_%d.png", time.Now().Unix()))
|
tempFilePath := filepath.Join(os.TempDir(), fmt.Sprintf("screenshot_%d.png", time.Now().Unix()))
|
||||||
|
|
||||||
cmd := exec.Command("gnome-screenshot", "-f", tempFilePath)
|
cmds := []*exec.Cmd{
|
||||||
commandOutput := RunShellCommand(cmd)
|
exec.Command("gnome-screenshot", "-f", tempFilePath),
|
||||||
if commandOutput.ExitCode != 0 {
|
exec.Command("xfce4-screenshooter", "-f", "-s", tempFilePath),
|
||||||
return "", errors.New(commandOutput.Stderr)
|
exec.Command("spectacle", "--fullscreen", "--background", "--output", tempFilePath),
|
||||||
}
|
}
|
||||||
|
for _, cmd := range cmds {
|
||||||
|
commandOutput := RunShellCommand(cmd)
|
||||||
|
if commandOutput.ExitCode == 0 {
|
||||||
return tempFilePath, nil
|
return tempFilePath, nil
|
||||||
}
|
}
|
||||||
|
slog.Warn("Screenshot error", "error", commandOutput.Stderr)
|
||||||
|
}
|
||||||
|
return "", errors.New("no screenshot utility found or all failed")
|
||||||
|
}
|
||||||
|
|
||||||
func RunShellCommand(cmd *exec.Cmd) CommandResponse {
|
func RunShellCommand(cmd *exec.Cmd) CommandResponse {
|
||||||
var stdout, stderr bytes.Buffer
|
var stdout, stderr bytes.Buffer
|
||||||
|
|||||||
Reference in New Issue
Block a user