-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
330 additions
and
1,526 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
"syscall" | ||
|
||
"github.com/gofiber/fiber/v2/log" | ||
"github.com/wailsapp/wails/v2/pkg/runtime" | ||
"mvdan.cc/xurls/v2" | ||
) | ||
|
||
// App struct | ||
type App struct { | ||
ctx context.Context | ||
} | ||
|
||
var zrokCommand = "./resources/linux-x64-zrok" | ||
|
||
|
||
// NewApp creates a new App application struct | ||
func NewApp() *App { | ||
return &App{} | ||
} | ||
|
||
// startup is called when the app starts. The context is saved | ||
// so we can call the runtime methods | ||
func (a *App) startup(ctx context.Context) { | ||
a.ctx = ctx | ||
} | ||
|
||
func (a *App) Minimize() { | ||
runtime.WindowMinimise(a.ctx) | ||
} | ||
|
||
func (a *App) Maximize() { | ||
if runtime.WindowIsMaximised(a.ctx) { | ||
runtime.WindowUnmaximise(a.ctx) | ||
} else{ | ||
runtime.WindowMaximise(a.ctx) | ||
} | ||
} | ||
|
||
func (a *App) Quit() { | ||
runtime.Quit(a.ctx) | ||
} | ||
|
||
func (a *App) ChooseFolder() (string, error) { | ||
folder,_ := runtime.OpenDirectoryDialog(a.ctx, runtime.OpenDialogOptions{ | ||
Title: "Choose a folder", | ||
}) | ||
return folder,nil | ||
} | ||
|
||
func writeToFile(name string, data string) error { | ||
f, err := os.OpenFile(name, os.O_CREATE | os.O_APPEND | os.O_WRONLY, 0644) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
_, err = f.WriteString(data+"\n") | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (a *App) Invite(email string) string { | ||
cmd := exec.Command(zrokCommand, "status") | ||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true, Pgid: 0} | ||
output, _ := cmd.Output() | ||
xurlsStrict := xurls.Strict() | ||
find := xurlsStrict.FindAllString(string(output), -1) | ||
apiEndpoint := find[0] | ||
|
||
requestBody := []byte(fmt.Sprintf(`{"email": "%s"}`, email)) | ||
resp, err := http.Post(apiEndpoint+"/api/v1/invite", "application/zrok.v1+json", bytes.NewBuffer(requestBody)) | ||
if err != nil { | ||
log.Error("发送请求时出错:", err) | ||
} | ||
defer resp.Body.Close() | ||
return resp.Status | ||
} | ||
|
||
func (a *App) Version() string { | ||
cmd := exec.Command(zrokCommand, "version") | ||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true, Pgid: 0} | ||
output, _ := cmd.Output() | ||
return string(output) | ||
} | ||
|
||
func (a *App) Overview() string { | ||
cmd := exec.Command(zrokCommand, "overview") | ||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true, Pgid: 0} | ||
output, _ := cmd.Output() | ||
return string(output) | ||
} | ||
|
||
// Zrok | ||
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{Setpgid: true, Pgid: 0} | ||
// 创建一个缓冲区来保存标准错误输出 | ||
var stdout bytes.Buffer | ||
var stderr bytes.Buffer | ||
cmd.Stdout = &stdout | ||
cmd.Stderr = &stderr | ||
// 执行命令 | ||
err := cmd.Run() | ||
if err != nil { | ||
// 如果命令执行出错,则打印标准错误输出 | ||
log.Error("执行命令时出错:", err) | ||
log.Error("标准错误输出:", stderr.String()) | ||
return stderr.String() | ||
} | ||
// 如果命令执行成功,则打印标准输出 | ||
|
||
log.Info("标准输出:", stdout.String()) | ||
return stdout.String() | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
"syscall" | ||
|
||
"github.com/gofiber/fiber/v2/log" | ||
"github.com/wailsapp/wails/v2/pkg/runtime" | ||
"mvdan.cc/xurls/v2" | ||
) | ||
|
||
// App struct | ||
type App struct { | ||
ctx context.Context | ||
} | ||
|
||
var zrokCommand = "./resources/darwin-x64-zrok" | ||
|
||
|
||
// NewApp creates a new App application struct | ||
func NewApp() *App { | ||
return &App{} | ||
} | ||
|
||
// startup is called when the app starts. The context is saved | ||
// so we can call the runtime methods | ||
func (a *App) startup(ctx context.Context) { | ||
a.ctx = ctx | ||
} | ||
|
||
func (a *App) Minimize() { | ||
runtime.WindowMinimise(a.ctx) | ||
} | ||
|
||
func (a *App) Maximize() { | ||
if runtime.WindowIsMaximised(a.ctx) { | ||
runtime.WindowUnmaximise(a.ctx) | ||
} else{ | ||
runtime.WindowMaximise(a.ctx) | ||
} | ||
} | ||
|
||
func (a *App) Quit() { | ||
runtime.Quit(a.ctx) | ||
} | ||
|
||
func (a *App) ChooseFolder() (string, error) { | ||
folder,_ := runtime.OpenDirectoryDialog(a.ctx, runtime.OpenDialogOptions{ | ||
Title: "Choose a folder", | ||
}) | ||
return folder,nil | ||
} | ||
|
||
func writeToFile(name string, data string) error { | ||
f, err := os.OpenFile(name, os.O_CREATE | os.O_APPEND | os.O_WRONLY, 0644) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
_, err = f.WriteString(data+"\n") | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (a *App) Invite(email string) string { | ||
cmd := exec.Command(zrokCommand, "status") | ||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true, Pgid: 0} | ||
output, _ := cmd.Output() | ||
xurlsStrict := xurls.Strict() | ||
find := xurlsStrict.FindAllString(string(output), -1) | ||
apiEndpoint := find[0] | ||
|
||
requestBody := []byte(fmt.Sprintf(`{"email": "%s"}`, email)) | ||
resp, err := http.Post(apiEndpoint+"/api/v1/invite", "application/zrok.v1+json", bytes.NewBuffer(requestBody)) | ||
if err != nil { | ||
log.Error("发送请求时出错:", err) | ||
} | ||
defer resp.Body.Close() | ||
return resp.Status | ||
} | ||
|
||
func (a *App) Version() string { | ||
cmd := exec.Command(zrokCommand, "version") | ||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true, Pgid: 0} | ||
output, _ := cmd.Output() | ||
return string(output) | ||
} | ||
|
||
func (a *App) Overview() string { | ||
cmd := exec.Command(zrokCommand, "overview") | ||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true, Pgid: 0} | ||
output, _ := cmd.Output() | ||
return string(output) | ||
} | ||
|
||
// Zrok | ||
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{Setpgid: true, Pgid: 0} | ||
// 创建一个缓冲区来保存标准错误输出 | ||
var stdout bytes.Buffer | ||
var stderr bytes.Buffer | ||
cmd.Stdout = &stdout | ||
cmd.Stderr = &stderr | ||
// 执行命令 | ||
err := cmd.Run() | ||
if err != nil { | ||
// 如果命令执行出错,则打印标准错误输出 | ||
log.Error("执行命令时出错:", err) | ||
log.Error("标准错误输出:", stderr.String()) | ||
return stderr.String() | ||
} | ||
// 如果命令执行成功,则打印标准输出 | ||
|
||
log.Info("标准输出:", stdout.String()) | ||
return stdout.String() | ||
} | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.