Skip to content

Commit

Permalink
platform
Browse files Browse the repository at this point in the history
  • Loading branch information
lerte committed Apr 12, 2024
1 parent 40d1d3d commit 345b57b
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 273 deletions.
23 changes: 8 additions & 15 deletions app_windows.go → app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import (
"fmt"
"net/http"
"os"
"os/exec"
"strings"
"syscall"

"github.com/gofiber/fiber/v2/log"
"github.com/wailsapp/wails/v2/pkg/runtime"
Expand All @@ -20,8 +18,6 @@ type App struct {
ctx context.Context
}

var zrokCommand = "./resources/zrok.exe"


// NewApp creates a new App application struct
func NewApp() *App {
Expand Down Expand Up @@ -71,9 +67,9 @@ func writeToFile(name string, data string) error {
}

func (a *App) Invite(email string) string {
cmd := exec.Command(zrokCommand, "status")
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
output, _ := cmd.Output()
status := []string{"status"}
output, _ := zrokCmd(status).Output()

xurlsStrict := xurls.Strict()
find := xurlsStrict.FindAllString(string(output), -1)
apiEndpoint := find[0]
Expand All @@ -88,16 +84,14 @@ func (a *App) Invite(email string) string {
}

func (a *App) Version() string {
cmd := exec.Command(zrokCommand, "version")
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
output, _ := cmd.Output()
version := []string{"version"}
output, _ := zrokCmd(version).Output()
return string(output)
}

func (a *App) Overview() string {
cmd := exec.Command(zrokCommand, "overview")
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
output, _ := cmd.Output()
overview := []string{"overview"}
output, _ := zrokCmd(overview).Output()
return string(output)
}

Expand All @@ -106,8 +100,7 @@ func (a *App) Zrok(args []string) string {
log.Info("Zrok", args)
writeToFile("./resources/logs.txt", strings.Join(args, " "))

cmd := exec.Command(zrokCommand, args...)
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
cmd := zrokCmd(args)
// 创建一个缓冲区来保存标准错误输出
var stdout bytes.Buffer
var stderr bytes.Buffer
Expand Down
129 changes: 0 additions & 129 deletions app_linux.go

This file was deleted.

129 changes: 0 additions & 129 deletions app_unix.go

This file was deleted.

13 changes: 13 additions & 0 deletions zrok_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"os/exec"
"syscall"
)

func zrokCmd(args []string) (*exec.Cmd) {
zrokBin := "./resources/darwin-x64-zrok"
cmd := exec.Command(zrokBin, args...)
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true, Pgid: 0}
return cmd
}
13 changes: 13 additions & 0 deletions zrok_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"os/exec"
"syscall"
)

func zrokCmd(args []string) (*exec.Cmd) {
zrokBin := "./resources/linux-x64-zrok"
cmd := exec.Command(zrokBin, args...)
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true, Pgid: 0}
return cmd
}
13 changes: 13 additions & 0 deletions zrok_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"os/exec"
"syscall"
)

func zrokCmd(args []string) (*exec.Cmd) {
zrokBin := "./resources/zrok.exe"
cmd := exec.Command(zrokBin, args...)
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
return cmd
}

0 comments on commit 345b57b

Please sign in to comment.