Skip to content

Commit

Permalink
Fix build error
Browse files Browse the repository at this point in the history
  • Loading branch information
qianlifeng committed Dec 22, 2024
1 parent ccfdbc5 commit f702289
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
3 changes: 2 additions & 1 deletion wox.core/plugin/host/host_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package host
import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
"strings"
Expand Down Expand Up @@ -135,7 +136,7 @@ func (w *WebsocketHost) invokeMethod(ctx context.Context, metadata plugin.Metada
case response := <-resultChan:
util.GetLogger().Debug(ctx, fmt.Sprintf("inovke plugin <%s> method: %s finished, response time: %dms", metadata.Name, method, util.GetSystemTimestamp()-startTimestamp))
if response.Error != "" {
return "", fmt.Errorf(response.Error)
return "", errors.New(response.Error)
} else {
return response.Result, nil
}
Expand Down
22 changes: 21 additions & 1 deletion wox.core/util/open_linux.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package util

import "os/exec"
import (
"os"
"os/exec"
)

func ShellOpen(path string) error {
return exec.Command("xdg-open", path).Start()
Expand All @@ -18,6 +21,23 @@ func ShellRun(name string, arg ...string) (*exec.Cmd, error) {
return cmd, nil
}

func ShellRunWithEnv(name string, envs []string, arg ...string) (*exec.Cmd, error) {
if len(envs) == 0 {
return ShellRun(name, arg...)
}

cmd := exec.Command(name, arg...)
cmd.Stdout = GetLogger().GetWriter()
cmd.Stderr = GetLogger().GetWriter()
cmd.Env = append(os.Environ(), envs...)
cmdErr := cmd.Start()
if cmdErr != nil {
return nil, cmdErr
}

return cmd, nil
}

func ShellRunOutput(name string, arg ...string) ([]byte, error) {
cmd := exec.Command(name, arg...)
return cmd.Output()
Expand Down
17 changes: 17 additions & 0 deletions wox.core/util/open_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ func ShellRun(name string, arg ...string) (*exec.Cmd, error) {
return cmd, nil
}

func ShellRunWithEnv(name string, envs []string, arg ...string) (*exec.Cmd, error) {
if len(envs) == 0 {
return ShellRun(name, arg...)
}

cmd := exec.Command(name, arg...)
cmd.Stdout = GetLogger().GetWriter()
cmd.Stderr = GetLogger().GetWriter()
cmd.Env = append(os.Environ(), envs...)
cmdErr := cmd.Start()
if cmdErr != nil {
return nil, cmdErr
}

return cmd, nil
}

func ShellRunOutput(name string, arg ...string) ([]byte, error) {
cmd := exec.Command(name, arg...)
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} // Hide the window
Expand Down

0 comments on commit f702289

Please sign in to comment.