fix: Windows handler liest params statt data, exec via PowerShell (winget-kompatibel)
This commit is contained in:
parent
5eae071bf9
commit
557e59bfc5
@ -15,7 +15,8 @@ type Message struct {
|
||||
Command string `json:"command,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Data interface{} `json:"data,omitempty"`
|
||||
Params map[string]interface{} `json:"params,omitempty"` // Backend -> Agent
|
||||
Data interface{} `json:"data,omitempty"` // Agent -> Backend (Response)
|
||||
}
|
||||
|
||||
type Handler struct{}
|
||||
@ -65,7 +66,10 @@ func (h *Handler) Handle(raw []byte) []byte {
|
||||
func (h *Handler) handleExec(msg Message) Message {
|
||||
resp := Message{Type: "response", ID: msg.ID}
|
||||
|
||||
data, _ := msg.Data.(map[string]interface{})
|
||||
data := msg.Params
|
||||
if data == nil {
|
||||
data, _ = msg.Data.(map[string]interface{})
|
||||
}
|
||||
command, _ := data["command"].(string)
|
||||
if command == "" {
|
||||
resp.Status = "error"
|
||||
@ -107,7 +111,8 @@ func (h *Handler) handleWingetList(msg Message) Message {
|
||||
// handleWingetInstall installiert ein Paket
|
||||
func (h *Handler) handleWingetInstall(msg Message) Message {
|
||||
resp := Message{Type: "response", ID: msg.ID}
|
||||
data, _ := msg.Data.(map[string]interface{})
|
||||
data := msg.Params
|
||||
if data == nil { data, _ = msg.Data.(map[string]interface{}) }
|
||||
pkg, _ := data["package"].(string)
|
||||
if pkg == "" {
|
||||
resp.Status = "error"
|
||||
@ -130,7 +135,8 @@ func (h *Handler) handleWingetInstall(msg Message) Message {
|
||||
// handleWingetUpgrade aktualisiert ein Paket
|
||||
func (h *Handler) handleWingetUpgrade(msg Message) Message {
|
||||
resp := Message{Type: "response", ID: msg.ID}
|
||||
data, _ := msg.Data.(map[string]interface{})
|
||||
data := msg.Params
|
||||
if data == nil { data, _ = msg.Data.(map[string]interface{}) }
|
||||
pkg, _ := data["package"].(string)
|
||||
if pkg == "" {
|
||||
resp.Status = "error"
|
||||
@ -229,8 +235,9 @@ func (h *Handler) handleReboot(msg Message) Message {
|
||||
// Hilfsfunktionen
|
||||
|
||||
func runWithTimeout(command string, timeoutSecs int) (string, error) {
|
||||
cmd := exec.Command("cmd", "/C", command)
|
||||
cmd.SysProcAttr = nil
|
||||
// PowerShell verwenden — unterstuetzt winget, UTF-8, moderne Windows-Befehle
|
||||
cmd := exec.Command("powershell", "-NoProfile", "-NonInteractive",
|
||||
"-OutputEncoding", "UTF8", "-Command", command)
|
||||
out, err := withTimeout(cmd, time.Duration(timeoutSecs)*time.Second)
|
||||
return out, err
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user