refactor: move browser open into shared modules

This commit is contained in:
2025-11-04 17:21:23 +01:00
parent fa3d5198d2
commit 4ebac7d7fc
7 changed files with 91 additions and 56 deletions
+33 -3
View File
@@ -1,8 +1,38 @@
package shared
import (
_ "embed"
"bytes"
"errors"
"os/exec"
)
//go:embed splash_screen.html
var SplashScreenTemplate string
type CommandResponse struct {
Stdout string `json:"stdout"`
Stderr string `json:"stderr"`
ExitCode int `json:"exitCode"`
}
func RunShellCommand(cmd *exec.Cmd) CommandResponse {
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
commandOutput := CommandResponse{
Stdout: stdout.String(),
Stderr: stderr.String(),
ExitCode: cmd.ProcessState.ExitCode(),
}
if err != nil {
var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
commandOutput.ExitCode = exitErr.ExitCode()
} else {
commandOutput.Stderr = err.Error()
}
}
return commandOutput
}