main
parent 54439a870e
commit 0d290d0930

@ -7,11 +7,12 @@ import (
"io/fs"
"os"
//"path/filepath"
"path/filepath"
//"time"
"github.com/estebangarcia21/subprocess"
"github.com/wailsapp/wails/v2/pkg/runtime"
"golang.org/x/sys/windows"
)
type Server struct {
@ -65,6 +66,69 @@ func (a *App) GetProjects() []Project {
return projects
}
type Disk struct {
Name string
Free uint64
}
func getFileCountAndSize(dir string) (int, int64, error) {
var fileCount int
var totalSize int64
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() { // Проверяем, что это не каталог
fileCount++
totalSize += info.Size() // Добавляем размер файла
}
return nil
})
if err != nil {
return 0, 0, err
}
return fileCount, totalSize, nil
}
func (a *App) GetDownloads() string {
cnt, size, err := getFileCountAndSize("C:\\Users\\admin\\Downloads")
checkError("getDownloads", err)
info := fmt.Sprintf("%d(%d Mb)", cnt, size/1024/1024)
return info
}
// StartFarDownloads - запускает far
func (a *App) StartFarDownloads() string {
cmd := `far "D:\soft" "C:\Users\admin\Downloads"`
far := subprocess.New(cmd)
err := far.Exec()
if err != nil {
runtime.LogError(a.ctx, err.Error())
}
runtime.LogInfo(a.ctx, "команда выполнена успешно")
return "ok"
}
func (a *App) GetDisks() []Disk {
var disks = []Disk{}
var freeBytes, totalBytes, totalFreeBytes uint64
err := windows.GetDiskFreeSpaceEx(windows.StringToUTF16Ptr("C:\\"), &freeBytes, &totalBytes, &totalFreeBytes)
checkError("free space c:", err)
free_C := freeBytes / 1024 / 1024 / 1024
disks = append(disks, Disk{Name: "C:", Free: free_C})
err = windows.GetDiskFreeSpaceEx(windows.StringToUTF16Ptr("D:\\"), &freeBytes, &totalBytes, &totalFreeBytes)
checkError("free space d:", err)
free_D := freeBytes / 1024 / 1024 / 1024
disks = append(disks, Disk{Name: "D:", Free: free_D})
return disks
//fmt.Printf("Свободное место на диске: %dGB\n", freeGB)
}
// 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)
@ -94,7 +158,7 @@ func (a *App) StartServer(s string) string {
return "starting server"
}
// StartServer - запускает сервер на выполнение
// StartFar - запускает far
func (a *App) StartFar(s string) string {
runtime.LogInfo(a.ctx, s)
cmd := fmt.Sprintf("far \"%s\" \"%s\"", s, s)

@ -1,6 +1,14 @@
<script>
import logo from "./assets/images/logo-universal.png";
import { GetStatus, Weed, GetProjects, StartFar } from "../wailsjs/go/main/App.js";
import {
GetStatus,
Weed,
GetProjects,
StartFar,
GetDisks,
GetDownloads,
StartFarDownloads} from "../wailsjs/go/main/App.js";
import { StartServer } from "../wailsjs/go/main/App.js";
import TailwindCss from "./TailwindCSS.svelte";
import servers from "./servers.js";
@ -9,12 +17,37 @@ import servers from "./servers.js";
let resultText = "Ваше имя 👇";
let local = servers;
let projects = [];
let disks = [];
let downloads = "";
let cnt_pic = "0";
let normal = true;
let pics = true;
function get_disks() {
console.log("get disks")
GetDisks().then((result) => {
console.log("получена информация о дисках:", result)
disks = result;
normal = (disks[0].Free > 10) && (disks[1].Free > 50);
})
}
function get_downloads() {
console.log("get downloads")
GetDownloads().then((result) => {
console.log("получена информация о downloads:", result)
downloads = result
})
}
function start_far(project) {
StartFar(project.last_directory_path)
}
function far_downloads() {
StartFarDownloads()
}
function start_server(server) {
let s = JSON.stringify(server);
console.log(s);
@ -34,6 +67,12 @@ function weed() {
}
function get_status() {
console.log("запрос downloads");
get_downloads()
console.log("запрос дисков");
get_disks()
console.log("запрос статуса");
GetStatus().then((result) => {
console.log("result:", result);
@ -57,6 +96,17 @@ get_status();
<TailwindCss />
<div class="container mx-auto pt-4 mb-4">
<div class="disk-panel text-neutral-300">
{#each disks as disk}
<div>
{disk.Name}
<span class={normal ? 'info' : 'danger'}>{disk.Free} Gb</span>
</div>
{/each}
</div>
</div>
<div class="container mx-auto pt-4 mb-4">
<h1 class="text-blue-200 text-2xl">СЕРВЕРА</h1>
{#each local as server}
@ -92,11 +142,20 @@ get_status();
</button>
<div class="text-neutral-300">
<span>
{cnt_pic}
</span>
<span class={pics ? 'warning' : 'info'}>{cnt_pic}</span>
</div>
</div>
<div class="flex justify-between px-4">
<button
class="text-teal-600 hover:text-teal-200 hover:font-normal hover:underline hover:underline-offset-2 cursor-pointer"
on:click={far_downloads}
>
Download
</button>
<div class="text-neutral-300">
<span class="info">{downloads}</span>
</div>
</div>
</div>
</div>
</div>
@ -115,7 +174,7 @@ get_status();
</button>
<div class="text-neutral-300">
<span> {project.name} </span>
<span class="info"> {project.name} </span>
</div>
</div>
{/each}
@ -129,8 +188,8 @@ get_status();
p-2 rounded-full">
<svg
xmlns="http://www.w3.org/2000/svg"
width="36"
height="36"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
@ -143,4 +202,17 @@ get_status();
</button>
<style>
.disk-panel {
display: flex;
justify-content: space-around;
}
.info {
color: lightgreen;
}
.danger {
color: red;
}
.warning {
color: orange;
}
</style>

@ -2,6 +2,10 @@
// This file is automatically generated. DO NOT EDIT
import {main} from '../models';
export function GetDisks():Promise<Array<main.Disk>>;
export function GetDownloads():Promise<string>;
export function GetProjects():Promise<Array<main.Project>>;
export function GetStatus():Promise<string>;
@ -10,6 +14,8 @@ export function Greet(arg1:string):Promise<string>;
export function StartFar(arg1:string):Promise<string>;
export function StartFarDownloads():Promise<string>;
export function StartServer(arg1:string):Promise<string>;
export function Weed():Promise<void>;

@ -2,6 +2,14 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
export function GetDisks() {
return window['go']['main']['App']['GetDisks']();
}
export function GetDownloads() {
return window['go']['main']['App']['GetDownloads']();
}
export function GetProjects() {
return window['go']['main']['App']['GetProjects']();
}
@ -18,6 +26,10 @@ export function StartFar(arg1) {
return window['go']['main']['App']['StartFar'](arg1);
}
export function StartFarDownloads() {
return window['go']['main']['App']['StartFarDownloads']();
}
export function StartServer(arg1) {
return window['go']['main']['App']['StartServer'](arg1);
}

@ -1,5 +1,19 @@
export namespace main {
export class Disk {
Name: string;
Free: number;
static createFrom(source: any = {}) {
return new Disk(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.Name = source["Name"];
this.Free = source["Free"];
}
}
export class Project {
name: string;
last_directory: string;

@ -5,6 +5,7 @@ go 1.23.1
require (
github.com/estebangarcia21/subprocess v0.0.0-20230526204252-a1a6de4773be
github.com/wailsapp/wails/v2 v2.10.1
golang.org/x/sys v0.30.0
)
require (
@ -32,6 +33,5 @@ require (
github.com/wailsapp/mimetype v1.4.1 // indirect
golang.org/x/crypto v0.33.0 // indirect
golang.org/x/net v0.35.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/text v0.22.0 // indirect
)

Loading…
Cancel
Save