Skip to content

Commit

Permalink
fix: windows 进程重启问题
Browse files Browse the repository at this point in the history
  • Loading branch information
peterq committed Jun 28, 2019
1 parent 1a4b035 commit de64065
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
11 changes: 11 additions & 0 deletions pc/dep/dep.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package dep

import (
"io/ioutil"
"log"
"os"
"runtime"
"runtime/debug"
)

Expand Down Expand Up @@ -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")
}
9 changes: 3 additions & 6 deletions pc/functions/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
// 退出
Expand All @@ -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
},
// 账号列表
Expand All @@ -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
},
}
Expand Down
35 changes: 34 additions & 1 deletion pc/pan-light-pc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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:]...)
Expand All @@ -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
Expand All @@ -52,5 +81,9 @@ START_PAN:
}
}
}
bin, _ := ioutil.ReadFile(dep.DataPath("reboot"))
if string(bin) == "true" {
goto START_PAN
}
log.Fatal(err)
}

0 comments on commit de64065

Please sign in to comment.