forked from mololab/valoline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
80 lines (66 loc) · 1.84 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"fmt"
"net"
"net/http"
"os"
"os/signal"
"runtime"
"github.com/parvineyvazov/valoline/core"
"github.com/zserge/lorca"
)
//go:generate goversioninfo -icon=www/assets/desktop_favicon.ico -manifest=Valoline.exe.manifest
func main() {
args := []string{}
prepareArgsForLorcaBootstrap(args)
// create and launch the app
ui, err := lorca.New("", "", 800, 600, args...)
genericErrHandler(err, "initializing the app UI")
defer ui.Close()
// ON START BIND
err = ui.Bind("onStart", func(dateInString string) {
// perform the server side task here
fmt.Println("app started", dateInString)
// ui.Eval(fmt.Sprintf(`onStartAck(%v);`, time.Now().UnixNano()))
})
core.HandleError(err)
// MODE CHANGER BIND
err = ui.Bind("onModeChange", func(mode string) {
core.OnModeChange(mode, &ui)
})
core.HandleError(err)
// connect to FS (fileServer pointing to folder www)
listener, err := net.Listen("tcp", "127.0.0.1:0")
genericErrHandler(err, "connecting to the fileServer (e.g. www folder)")
defer listener.Close()
// start the server by binding the listener
go http.Serve(listener, http.FileServer(FS))
err = ui.Load(fmt.Sprintf("http://%s", listener.Addr()))
genericErrHandler(err, "load the index.html")
// os signal handling
sigc := make(chan os.Signal)
signal.Notify(sigc, os.Interrupt)
select {
case <-sigc:
case <-ui.Done():
}
// can exit now
fmt.Println("Thanks for using the app!")
}
func genericErrHandler(err error, description ...string) {
if err != nil {
if description != nil {
fmt.Println(fmt.Sprintf("oops! something is wrong! %v\n", description[0]))
}
panic(err)
}
}
/**
* prepare bootstrap arguments for different OS (for the moment, only Linux)
*/
func prepareArgsForLorcaBootstrap(args []string) []string {
if runtime.GOOS == "linux" {
args = append(args, "--class=Lorca")
}
return args
}