-
Notifications
You must be signed in to change notification settings - Fork 27
/
main.go
46 lines (41 loc) · 959 Bytes
/
main.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
//go:generate go-winres make --product-version=git-tag
package main
import (
"embed"
"fmt"
"os"
"os/signal"
"sync"
server "synk/server"
"github.com/zserge/lorca"
)
//go:embed server/frontend/dist/*
var FS embed.FS
func recoverFromError() {
if r := recover(); r != nil {
fmt.Println("Recovering from panic:", r)
}
}
func main() {
var endWaiter sync.WaitGroup
endWaiter.Add(1)
start := make(chan int)
end := make(chan interface{})
go server.Run(start, end)
go func(start chan int, quit chan interface{}) {
port := <-start
defer recoverFromError()
ui, _ := lorca.New(fmt.Sprintf("http://127.0.0.1:%d/static/index.html", port), "", 800, 600, "--disable-sync", " --disable-translate")
defer ui.Close()
quit <- (<-ui.Done())
}(start, end)
signalChannel := make(chan os.Signal, 1)
signal.Notify(signalChannel, os.Interrupt)
select {
case <-signalChannel:
endWaiter.Done()
case <-end:
endWaiter.Done()
}
endWaiter.Wait()
}