Add UI binary to windows installer (#285)

This PR adds Desktop UI to Windows installer
This commit is contained in:
Givi Khojanashvili
2022-03-23 21:24:25 +04:00
committed by GitHub
parent 97ab8f4c34
commit a15d52b263
2 changed files with 42 additions and 1 deletions

View File

@ -4,8 +4,13 @@ import (
"context"
"flag"
"fmt"
"io/ioutil"
"os"
"path"
"runtime"
"strconv"
"strings"
"syscall"
"time"
_ "embed"
@ -22,6 +27,11 @@ import (
func main() {
var daemonAddr string
if err := checkPIDFile(); err != nil {
fmt.Println(err)
return
}
defaultDaemonAddr := "unix:///var/run/wiretrustee.sock"
if runtime.GOOS == "windows" {
defaultDaemonAddr = "tcp://127.0.0.1:41731"
@ -214,3 +224,19 @@ func (s *serviceClient) client() (proto.DaemonServiceClient, error) {
s.conn = proto.NewDaemonServiceClient(conn)
return s.conn, nil
}
// checkPIDFile exists and return error, or write new.
func checkPIDFile() error {
pidFile := path.Join(os.TempDir(), "wiretrustee-ui.pid")
if piddata, err := ioutil.ReadFile(pidFile); err == nil {
if pid, err := strconv.Atoi(string(piddata)); err == nil {
if process, err := os.FindProcess(pid); err == nil {
if err := process.Signal(syscall.Signal(0)); err == nil {
return fmt.Errorf("process already exists: %d", pid)
}
}
}
}
return ioutil.WriteFile(pidFile, []byte(fmt.Sprintf("%d", os.Getpid())), 0o664)
}