main
parent 3366f0c8d9
commit 16064e92d2

@ -4,6 +4,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/fs"
"os" "os"
"github.com/estebangarcia21/subprocess" "github.com/estebangarcia21/subprocess"
@ -56,7 +57,7 @@ func startLocalServer(name, dir, cmd string) {
s.ExecAsync() s.ExecAsync()
} }
// StartServer - запускает сервер на выполение // StartServer - запускает сервер на выполнение
func (a *App) StartServer(s string) string { func (a *App) StartServer(s string) string {
runtime.LogInfo(a.ctx, s) runtime.LogInfo(a.ctx, s)
var server Server var server Server
@ -84,11 +85,38 @@ func (a *App) Weed() {
runtime.LogInfo(a.ctx, fmt.Sprintf("команда выполнена успешно")) runtime.LogInfo(a.ctx, fmt.Sprintf("команда выполнена успешно"))
} }
func (a *App) GetStatus() string { func getCountPics(dir string) int {
pics, err := os.ReadDir("d:\\pics") pics, err := os.ReadDir("d:\\pics")
if err != nil { if err != nil {
runtime.LogError(a.ctx, err.Error()) return -1
return "error: " + err.Error()
} }
return fmt.Sprint(len(pics)) return len(pics)
}
// The `getCountReady` function is counting the number of files (excluding directories) in a
// specified directory. It uses the `fs.WalkDir` function to walk through the file tree starting
// from the given directory within a file system. For each file encountered during the walk, it
// increments a counter if the file is not a directory. Finally, it returns the total count of
// files found in the directory.
func getCountReady(ctx context.Context, dir string) int {
root := dir
fileSystem := os.DirFS(root)
cnt := 0
fs.WalkDir(fileSystem, ".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
runtime.LogError(ctx, err.Error())
}
if !d.IsDir() {
cnt += 1
}
return nil
})
return cnt
}
func (a *App) GetStatus() string {
pics := getCountPics("d:\\pics")
ready := getCountReady(a.ctx, "d:\\pics-move")
return fmt.Sprintf("%d/%d", pics, ready)
} }

@ -33,6 +33,11 @@
GetStatus().then((result) => { GetStatus().then((result) => {
console.log("result:", result) console.log("result:", result)
cnt_pic = result; cnt_pic = result;
// сразу сбросим признак работающего сервера
local = local.map ( server => {
server.run = "idle"
return server
})
}); });
} }
@ -72,7 +77,7 @@
class="text-teal-600 hover:text-teal-200 hover:font-normal hover:underline hover:underline-offset-2 cursor-pointer" class="text-teal-600 hover:text-teal-200 hover:font-normal hover:underline hover:underline-offset-2 cursor-pointer"
on:click={weed} on:click={weed}
> >
Загрузка в weed Weed (python)
</button> </button>
<div class="text-neutral-300"> <div class="text-neutral-300">
@ -110,6 +115,5 @@
</button> </button>
</div> </div>
<style> <style>
</style> </style>

@ -1,41 +1,41 @@
const servers = [ const servers = [
{ {
name: "books-web", name: "books-web:3000",
dir: "d:\\projects\\books-web", dir: "d:\\projects\\books-web",
cmd: ".\\books-web.exe", cmd: ".\\books-web.exe",
port: "3000", port: "3000",
run: "idle" run: "idle"
}, },
{ {
name: "nano-tw", name: "nano-tw:5321",
dir: "d:\\projects\\nano-tw", dir: "d:\\projects\\nano-tw",
cmd: ".\\nano-tw.exe", cmd: ".\\nano-tw.exe",
port: "4321", port: "5321",
run: "idle" run: "idle"
}, },
{ {
name: "trans-web", name: "trans-web:4322",
dir: "d:\\projects\\trans-web", dir: "d:\\projects\\trans-web",
cmd: ".\\trans-web.exe", cmd: ".\\trans-web.exe",
port: "4322", port: "4322",
run: "idle" run: "idle"
}, },
{ {
name: "stem", name: "stem:4323",
dir: "d:\\projects\\stem", dir: "d:\\projects\\stem",
cmd: ".\\stem.exe", cmd: ".\\stem.exe",
port: "4323", port: "4323",
run: "idle" run: "idle"
}, },
{ {
name: "sw4-nano", name: "sw4-nano:4321",
dir: "d:\\projects\\sw4-nano", dir: "d:\\projects\\sw4-nano",
cmd: ".\\sw4-nano.exe", cmd: ".\\sw4-nano.exe",
port: "4321", port: "4321",
run: "idle" run: "idle"
}, },
{ {
name: "pionier", name: "pionier:4327",
dir: "d:\\projects\\pionier-daisy", dir: "d:\\projects\\pionier-daisy",
cmd: ".\\pionier-daisy.exe", cmd: ".\\pionier-daisy.exe",
port: "4327", port: "4327",

@ -2,6 +2,8 @@ package main
import ( import (
"embed" "embed"
"fmt"
"os"
"github.com/wailsapp/wails/v2" "github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/options" "github.com/wailsapp/wails/v2/pkg/options"
@ -40,3 +42,13 @@ func main() {
println("Error:", err.Error()) println("Error:", err.Error())
} }
} }
// ============================ разные утилиты ==========================
// Проверяет наличие ошибки
func checkError(src string, err error) {
if err != nil {
fmt.Printf("(%s): %s\n", src, err)
os.Exit(1)
}
}

Loading…
Cancel
Save