-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.go
56 lines (51 loc) · 872 Bytes
/
ui.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"embed"
"fmt"
"github.com/zserge/lorca"
"log"
"main/binds"
"net"
"net/http"
"os"
"os/signal"
"runtime"
)
//go:embed www
var fs embed.FS
var ui lorca.UI
var ln net.Listener
func updateScene() {
if ui != nil {
ui.Done()
ui.Close()
}
if ln != nil {
ln.Close()
}
args := []string{}
if runtime.GOOS == "linux" {
args = append(args, "--class=Lorca")
}
var err error
ui, err = lorca.New("", "", 1280, 720, args...)
if err != nil {
log.Fatal(err)
}
defer ui.Close()
binds.SetUp(ui)
ln, err = net.Listen("tcp", "127.0.0.1:0")
if err != nil {
log.Fatal(err)
}
defer ln.Close()
go http.Serve(ln, http.FileServer(http.FS(fs)))
ui.Load(fmt.Sprintf("http://%s/www", ln.Addr()))
sigc := make(chan os.Signal)
signal.Notify(sigc, os.Interrupt)
select {
case <-sigc:
case <-ui.Done():
}
log.Println("exiting...")
}