|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/estebangarcia21/subprocess"
|
|
|
|
"github.com/wailsapp/wails/v2/pkg/runtime"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Server struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Dir string `json:"dir"`
|
|
|
|
Cmd string `json:"cmd"`
|
|
|
|
Url string `json:"url"`
|
|
|
|
Port string `json:"port"`
|
|
|
|
Run string `json:"run"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) Start() {
|
|
|
|
os.Chdir(s.Dir)
|
|
|
|
//s := subprocess.New(".\\"+name+".exe")
|
|
|
|
p := subprocess.New(s.Cmd)
|
|
|
|
p.ExecAsync()
|
|
|
|
}
|
|
|
|
|
|
|
|
// App struct
|
|
|
|
type App struct {
|
|
|
|
ctx context.Context
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// runtime.WindowFullscreen(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Greet returns a greeting for the given name
|
|
|
|
func (a *App) Greet(name string) string {
|
|
|
|
return fmt.Sprintf("Hello %s, It's show time!", name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func startLocalServer(name, dir, cmd string) {
|
|
|
|
//os.Chdir("d:\\projects\\" + name);
|
|
|
|
os.Chdir(dir)
|
|
|
|
//s := subprocess.New(".\\"+name+".exe")
|
|
|
|
s := subprocess.New(cmd)
|
|
|
|
s.ExecAsync()
|
|
|
|
}
|
|
|
|
|
|
|
|
// StartServer - запускает сервер на выполение
|
|
|
|
func (a *App) StartServer(s string) string {
|
|
|
|
runtime.LogInfo(a.ctx, s)
|
|
|
|
var server Server
|
|
|
|
if err := json.Unmarshal([]byte(s), &server); err != nil {
|
|
|
|
runtime.LogError(a.ctx, err.Error())
|
|
|
|
}
|
|
|
|
runtime.LogInfo(a.ctx, fmt.Sprintf("server: %v", server))
|
|
|
|
|
|
|
|
server.Url = fmt.Sprintf("http://localhost:%s", server.Port)
|
|
|
|
server.Start()
|
|
|
|
runtime.BrowserOpenURL(a.ctx, server.Url)
|
|
|
|
|
|
|
|
return "starting server"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *App) Weed() {
|
|
|
|
os.Chdir("d:\\projects\\sw4-nano\\util")
|
|
|
|
//s := subprocess.New(".\\"+name+".exe")
|
|
|
|
cmd := "py scanpics.py"
|
|
|
|
s := subprocess.New(cmd)
|
|
|
|
err := s.Exec()
|
|
|
|
if err != nil {
|
|
|
|
runtime.LogError(a.ctx, err.Error())
|
|
|
|
}
|
|
|
|
runtime.LogInfo(a.ctx, fmt.Sprintf("команда выполнена успешно"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *App) GetStatus() string {
|
|
|
|
pics, err := os.ReadDir("d:\\pics")
|
|
|
|
if err != nil {
|
|
|
|
runtime.LogError(a.ctx, err.Error())
|
|
|
|
return "error: " + err.Error()
|
|
|
|
}
|
|
|
|
return fmt.Sprint(len(pics))
|
|
|
|
}
|