pan-light-pc.go 1.1 KB
Newer Older
1
// +build !plugin
P
peterq 已提交
2

3
package main
P
peterq 已提交
4

P
peterq 已提交
5 6 7
import (
	"github.com/peterq/pan-light/pc/dep"
	"github.com/peterq/pan-light/pc/gui"
8 9 10 11
	"log"
	"os"
	"os/exec"
	"syscall"
P
peterq 已提交
12
)
P
peterq 已提交
13

P
peterq 已提交
14
//go:generate protoc --go_out=. storage/types.proto
P
peterq 已提交
15
//go:generate protoc --go_out=. downloader/internal/types.proto
P
peterq 已提交
16
func main() {
17 18 19 20 21
	log.SetFlags(log.LstdFlags | log.Lshortfile)
	if os.Args[0] != startCmd {
		master()
	}
	log.Println("pan-light process")
P
peterq 已提交
22 23 24 25
	defer func() {
		dep.DoClose()
	}()
	dep.DoInit()
26
	gui.StartGui()
P
peterq 已提交
27
}
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

const startCmd = "pan_light_start"

func master() {
	log.Println("master process")
START_PAN:
	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 == 2 {
					goto START_PAN
P
peterq 已提交
46 47 48 49 50
				} else if code == 3221225477 {
					if os.Getenv("pan_light_render_exception_fix") != "true" {
						os.Setenv("pan_light_render_exception_fix", "true")
						goto START_PAN
					}
51 52 53 54 55 56
				}
			}
		}
	}
	log.Fatal(err)
}