main
parent 55fb00f20a
commit 3834afde74

@ -2,10 +2,30 @@ package main
import (
"context"
"encoding/json"
"fmt"
// "github.com/wailsapp/wails/v2/pkg/runtime"
"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
@ -27,3 +47,27 @@ func (a *App) startup(ctx context.Context) {
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.LogInfo(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"
}

@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8"/>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<script src="/wails/runtime.js"></script>
<title>server</title>
</head>
<body>

@ -1,7 +1,10 @@
<script>
import logo from './assets/images/logo-universal.png'
import {Greet} from '../wailsjs/go/main/App.js'
import {StartServer} from '../wailsjs/go/main/App.js'
import TailwindCss from './TailwindCSS.svelte';
import servers from './servers.js';
import {BrowserOpenURL} from '../wailsjs/runtime/runtime.js'
let resultText = "Ваше имя 👇"
let name
@ -9,75 +12,36 @@
function greet() {
Greet(name).then(result => resultText = result)
}
function start_server(server) {
let s = JSON.stringify(server)
console.log(s)
StartServer(s).then(result => {
resultText = result
console.log(resultText)
})
}
</script>
<TailwindCss />
<main>
<img alt="Wails logo" id="logo" src="{logo}">
<div class="result" id="result">{resultText}</div>
<h1 class="text-red-300 text-2xl">Проверка</h1>
<div class="input-box" id="input">
<input autocomplete="off" bind:value={name} class="input text-red-700" id="name" type="text"/>
<button class="btn w-96" on:click={greet}>Привет!</button>
</div>
<main class="container mx-auto pt-4 mb-8">
<h1 class="text-blue-200 text-2xl">СЕРВЕРА</h1>
{#each servers as server}
<div class="flex justify-between px-4">
<button
class="text-teal-400 hover:text-teal-200 hover:font-semibold cursor-pointer"
on:click={ () => start_server(server)}
>
{server.name}
</button>
<button class="text-neutral-300">
{server.run}
</button>
</div>
{/each}
</main>
<style>
#logo {
display: block;
width: 50%;
height: 50%;
margin: auto;
padding: 10% 0 0;
background-position: center;
background-repeat: no-repeat;
background-size: 100% 100%;
background-origin: content-box;
}
.result {
height: 20px;
line-height: 20px;
margin: 1.5rem auto;
}
.input-box .btn {
width: 60px;
height: 30px;
line-height: 30px;
border-radius: 3px;
border: none;
margin: 0 0 0 20px;
padding: 0 8px;
cursor: pointer;
}
.input-box .btn:hover {
background-image: linear-gradient(to top, #cfd9df 0%, #e2ebf0 100%);
color: #333333;
}
.input-box .input {
border: none;
border-radius: 3px;
outline: none;
height: 30px;
line-height: 30px;
padding: 0 10px;
background-color: rgba(240, 240, 240, 1);
-webkit-font-smoothing: antialiased;
}
.input-box .input:hover {
border: none;
background-color: rgba(255, 255, 255, 1);
}
.input-box .input:focus {
border: none;
background-color: rgba(255, 255, 255, 1);
}
</style>

@ -0,0 +1,32 @@
const servers = [
{
name: "books-web",
dir: "d:\\projects\\books-web",
cmd: ".\\books-web.exe",
port: "3000",
run: "idle"
},
{
name: "nano-tw",
dir: "d:\\projects\\nano-tw",
cmd: ".\\nano-tw.exe",
port: "4321",
run: "idle"
},
{
name: "trans-web",
dir: "d:\\projects\\trans-web",
cmd: ".\\trans-web.exe",
port: "4322",
run: "idle"
},
{
name: "stem",
dir: "d:\\projects\\stem",
cmd: ".\\stem.exe",
port: "4323",
run: "idle"
},
];
export default servers;

@ -2,3 +2,5 @@
// This file is automatically generated. DO NOT EDIT
export function Greet(arg1:string):Promise<string>;
export function StartServer(arg1:string):Promise<string>;

@ -5,3 +5,7 @@
export function Greet(arg1) {
return window['go']['main']['App']['Greet'](arg1);
}
export function StartServer(arg1) {
return window['go']['main']['App']['StartServer'](arg1);
}

@ -0,0 +1,4 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
export function Start():Promise<void>;

@ -0,0 +1,7 @@
// @ts-check
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
export function Start() {
return window['go']['main']['Server']['Start']();
}

@ -4,7 +4,10 @@ go 1.21
toolchain go1.22.0
require github.com/wailsapp/wails/v2 v2.8.0
require (
github.com/estebangarcia21/subprocess v0.0.0-20230526204252-a1a6de4773be
github.com/wailsapp/wails/v2 v2.8.0
)
require (
github.com/bep/debounce v1.2.1 // indirect

@ -3,6 +3,8 @@ github.com/bep/debounce v1.2.1/go.mod h1:H8yggRPQKLUhUoqrJC1bO2xNya7vanpDl7xR3IS
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/estebangarcia21/subprocess v0.0.0-20230526204252-a1a6de4773be h1:Mf6Xc0DgENbsDgKn10KNCNmW9FYSTcMr2bFsJ9uzvX0=
github.com/estebangarcia21/subprocess v0.0.0-20230526204252-a1a6de4773be/go.mod h1:PlHe6+WP6t7m4ghYrX6GBzB0KZLdOKWz2Ih3h0nusAY=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=

@ -17,16 +17,22 @@ func main() {
// Create application with options
err := wails.Run(&options.App{
Title: "server",
Width: 1024,
Height: 768,
Title: "server",
Width: 300,
Height: 600,
MinWidth: 200,
MinHeight: 400,
// Frameless: true,
AssetServer: &assetserver.Options{
Assets: assets,
},
BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 1},
OnStartup: app.startup,
// CSSDragProperty: "--wails-draggable",
// CSSDragValue: "drag",
Bind: []interface{}{
app,
&Server{},
},
})

Loading…
Cancel
Save