提交 de64065f 编写于 作者: P peterq

fix: windows 进程重启问题

上级 1a4b035c
package dep
import (
"io/ioutil"
"log"
"os"
"runtime"
"runtime/debug"
)
......@@ -35,6 +38,14 @@ func DoClose() {
closeCb = nil
}
func Reboot() {
if runtime.GOOS == "windows" {
ioutil.WriteFile(DataPath("reboot"), []byte("true"), 0664)
}
DoClose()
os.Exit(2)
}
var NotifyQml = func(event string, data map[string]interface{}) {
log.Println("not ready")
}
......@@ -35,8 +35,7 @@ var baseSyncRoutes = map[string]syncHandler{
},
// 重启
"reboot": func(p map[string]interface{}) (result interface{}) {
dep.DoClose()
os.Exit(2)
dep.Reboot()
return
},
// 退出
......@@ -57,8 +56,7 @@ var baseSyncRoutes = map[string]syncHandler{
storage.UserState.Logout = true
}
storage.Global.CurrentUser = "default"
dep.DoClose()
os.Exit(2)
dep.Reboot()
return
},
// 账号列表
......@@ -75,8 +73,7 @@ var baseSyncRoutes = map[string]syncHandler{
// 切换账号
"account.change": func(p map[string]interface{}) (result interface{}) {
storage.Global.CurrentUser = p["username"].(string)
dep.DoClose()
os.Exit(2)
dep.Reboot()
return
},
}
......
......@@ -5,9 +5,11 @@ package main
import (
"github.com/peterq/pan-light/pc/dep"
"github.com/peterq/pan-light/pc/gui"
"io/ioutil"
"log"
"os"
"os/exec"
"runtime"
"syscall"
)
......@@ -29,6 +31,12 @@ func main() {
const startCmd = "pan_light_start"
func master() {
if runtime.GOOS == "windows" {
windosMaster()
return
}
log.Println("master process")
START_PAN:
c := exec.Command(os.Args[0], os.Args[1:]...)
......@@ -43,7 +51,28 @@ START_PAN:
code := status.ExitStatus()
if code == 2 {
goto START_PAN
} else if code == 3221225477 {
}
}
}
}
log.Fatal(err)
}
func windosMaster() {
log.Println("master process")
START_PAN:
os.Remove(dep.DataPath("reboot"))
c := exec.Command(os.Args[0], os.Args[1:]...)
c.Args[0] = startCmd
c.Stderr = os.Stderr
c.Stdout = os.Stdout
c.Stdin = os.Stdin
err := c.Run()
if err != nil {
if exiterr, ok := err.(*exec.ExitError); ok {
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
code := status.ExitStatus()
if code == 3221225477 {
if os.Getenv("pan_light_render_exception_fix") != "true" {
os.Setenv("pan_light_render_exception_fix", "true")
goto START_PAN
......@@ -52,5 +81,9 @@ START_PAN:
}
}
}
bin, _ := ioutil.ReadFile(dep.DataPath("reboot"))
if string(bin) == "true" {
goto START_PAN
}
log.Fatal(err)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册