main
parent fbda311e00
commit e9af91c756

@ -0,0 +1,38 @@
package main
import (
//"os"
)
const css = `
body {
background-color: #222;
color: #aaa;
font-size: 1rem;
font-family: "Source Sans Pro", 'JetBrains Mono', 'Fira Code', "Segoe UI"
}
.main-title {
color: teal;
margin-top: 0;
text-align: center;
}
.container {
display: flex;
margin-left: 8px;
margin-right: 8px;
justify-content: space-between;
}
.server {
color: darkcyan;
cursor: pointer;
}
.server:hover {
text-decoration: underline;
color: cyan;
}
`

@ -0,0 +1,8 @@
module servers
go 1.22.0
require (
github.com/estebangarcia21/subprocess v0.0.0-20230526204252-a1a6de4773be
github.com/webview/webview_go v0.0.0-20230901181450-5a14030a9070
)

@ -0,0 +1,4 @@
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/webview/webview_go v0.0.0-20230901181450-5a14030a9070 h1:imZLWyo1ondeQjqfb/eHuYgFiOAYg6ugSMCnGfPTPmg=
github.com/webview/webview_go v0.0.0-20230901181450-5a14030a9070/go.mod h1:yE65LFCeWf4kyWD5re+h4XNvOHJEXOCOuJZ4v8l5sgk=

@ -0,0 +1,26 @@
package main
const html = `
<h1 class="main-title">Сервера</h1>
<div class="container">
<div class="server" onclick="start_server('books-web')">books-web</div>
<div id="books-web">3000</div>
</div>
<div class="container">
<div class="server" onclick="start_server('nano-tw')">nano-tw</div>
<div id="nano-tw">4321</div>
</div>
<div class="container">
<div class="server" onclick="start_server('trans-web')">trans-web</div>
<div id="trans-web">4322</div>
</div>
<div class="container">
<div class="server" onclick="start_server('stem')">stem</div>
<div id="stem">4323</div>
</div>
`

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

18
js.go

@ -0,0 +1,18 @@
package main
import (
//"os"
)
const js = `
function start_server(name){
const e = document.getElementById(name)
e.innerHTML = "работает.."
let result = server(name)
}
window.onload = function() {
noop();
}
`

@ -0,0 +1,54 @@
package main
import (
"log"
"os"
"fmt"
webview "github.com/webview/webview_go"
"github.com/estebangarcia21/subprocess"
)
func startServer(name string) {
os.Chdir("d:\\projects\\" + name);
s := subprocess.New(".\\"+name+".exe")
s.ExecAsync()
}
const mainhtml = `<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
</head>
<style>%s</style>
<body>%s</body>
<script>%s</script>
</html>`
func main() {
w := webview.New(false)
defer w.Destroy()
w.SetTitle("Сервера")
w.SetSize(280, 320, webview.HintNone)
//w.SetHtml("Thanks for using webview!")
//w.SetHtml(`<a href="http://localhost:4321">test</a>`)
// Регистрируем функцию JavaScript для прослушивания события от веб-страницы
w.Bind("noop", func() string {
log.Println("hello")
return "hello"
})
w.Bind("server", func(name string) string {
log.Printf("start server: %s", name)
startServer(name)
return "start"
})
// Загружаем HTML-страницу с JavaScript кодом, который будет отправлять сообщения
resulthtml := fmt.Sprintf(mainhtml, css, html, js)
w.SetHtml(resulthtml)
//w.Navigate("http://localhost:9999")
// Запускаем цикл событий окна браузера
w.Run()
}
Loading…
Cancel
Save