Win app: defer cleanup

This commit is contained in:
Chen-I Lim 2021-02-09 17:00:14 -08:00
parent 1a006f47a0
commit dae99c99a1

View file

@ -53,14 +53,26 @@ func main() {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
cmd := runServer(ctx) cmd := runServer(ctx)
defer func() {
fmt.Println("Cleanup")
cancel()
if err := cmd.Process.Kill(); err != nil {
log.Fatal("failed to kill server process: ", err)
}
if r := recover(); r != nil {
log.Fatal("ERROR: ", r)
}
}()
ui, err := lorca.New("", "", 1024, 768) ui, err := lorca.New("", "", 1024, 768)
if err != nil { if err != nil {
log.Fatal(err) log.Panic(err)
} }
// defer ui.Close() defer ui.Close()
if err := ui.Load("http://localhost:8088"); err != nil { if err := ui.Load("http://localhost:8088"); err != nil {
log.Fatal(err) log.Panic(err)
} }
script := fmt.Sprintf("localStorage.setItem('sessionId', '%s');", sessionToken) script := fmt.Sprintf("localStorage.setItem('sessionId', '%s');", sessionToken)
@ -73,10 +85,6 @@ func main() {
<-ui.Done() <-ui.Done()
log.Printf("App Closed") log.Printf("App Closed")
cancel()
if err := cmd.Process.Kill(); err != nil {
log.Fatal("failed to kill process: ", err)
}
} }
func hideConsole() { func hideConsole() {