|
|
@ -10,25 +10,37 @@ import (
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
chChomrDie := make(chan struct{})
|
|
|
|
|
|
|
|
chBackendDie := make(chan struct{})
|
|
|
|
go server.Run()
|
|
|
|
go server.Run()
|
|
|
|
cmd := startBrowser()
|
|
|
|
go startBrowser(chChomrDie, chBackendDie)
|
|
|
|
chSingal := listen2Interrupt()
|
|
|
|
chSingal := listen2Interrupt()
|
|
|
|
select {
|
|
|
|
for {
|
|
|
|
case <-chSingal:
|
|
|
|
select {
|
|
|
|
cmd.Process.Kill()
|
|
|
|
case <-chSingal:
|
|
|
|
|
|
|
|
chBackendDie <- struct{}{}
|
|
|
|
|
|
|
|
case <-chChomrDie:
|
|
|
|
|
|
|
|
os.Exit(0)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func startBrowser() *exec.Cmd {
|
|
|
|
func startBrowser(chChomrDie chan struct{}, chBackendDie chan struct{}) {
|
|
|
|
chromePath := "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
|
|
|
|
chromePath := "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
|
|
|
|
cmd := exec.Command(chromePath, "--app=http://127.0.0.1:"+config.GetPort()+"/static/index.html")
|
|
|
|
cmd := exec.Command(chromePath, "--app=http://127.0.0.1:"+config.GetPort()+"/static/index.html")
|
|
|
|
cmd.Start()
|
|
|
|
cmd.Start()
|
|
|
|
return cmd
|
|
|
|
go func() {
|
|
|
|
|
|
|
|
<-chBackendDie
|
|
|
|
|
|
|
|
cmd.Process.Kill()
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
|
|
|
|
cmd.Wait()
|
|
|
|
|
|
|
|
chChomrDie <- struct{}{}
|
|
|
|
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//监听中断信号
|
|
|
|
//监听中断信号
|
|
|
|
func listen2Interrupt() chan os.Signal {
|
|
|
|
func listen2Interrupt() <-chan os.Signal {
|
|
|
|
chSignal := make(chan os.Signal, 1)
|
|
|
|
chSignal := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(chSignal, os.Interrupt)
|
|
|
|
signal.Notify(chSignal, os.Interrupt)
|
|
|
|
return chSignal
|
|
|
|
return chSignal
|
|
|
|