You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
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()
|
|
|
|
|
}
|