diff --git a/.gitignore b/.gitignore index 333c41db..a716087f 100644 --- a/.gitignore +++ b/.gitignore @@ -28,7 +28,7 @@ /chipper/vbuild/botpack.tar.gz /chipper/windows/tmp /chipper/windows/chipper.exe -/chipper/windows/wire-pod-win.zip +/chipper/windows/*.zip /chipper/vbuild/built-libs /chipper/windows/libs /chipper/windows/opus diff --git a/chipper/cmd/windows/main.go b/chipper/cmd/windows/main.go index c1e39158..19a60d4d 100755 --- a/chipper/cmd/windows/main.go +++ b/chipper/cmd/windows/main.go @@ -1,66 +1,64 @@ package main import ( - "image/color" + "fmt" "io" "net/http" "os" + "os/exec" + "runtime" + "strconv" "strings" - "gioui.org/app" - "gioui.org/font/gofont" - "gioui.org/io/system" - "gioui.org/layout" - "gioui.org/op" - "gioui.org/text" - "gioui.org/unit" - "gioui.org/widget" - "gioui.org/widget/material" + "github.com/digital-dream-labs/hugh/log" "github.com/getlantern/systray" "github.com/kercre123/chipper/pkg/logger" + "github.com/kercre123/chipper/pkg/wirepod/sdkapp" + botsetup "github.com/kercre123/chipper/pkg/wirepod/setup" stt "github.com/kercre123/chipper/pkg/wirepod/stt/vosk" "github.com/ncruces/zenity" ) -var ( - editor widget.Editor - list layout.List -) - var mBoxTitle = "wire-pod" -var mBoxNeedsSetupMsg = `Wire-pod is now running in the background. You must set it up by heading to "http://localhost:8080" in a browser.` var mBoxError = `There was an error starting wire-pod: ` var mBoxAlreadyRunning = "Wire-pod is already running. You must quit that instance before starting another one. Exiting." -var mBoxExit = `Wire-pod is exiting.` var mBoxSuccess = `Wire-pod has started successfully! It is now running in the background. It can be stopped in the system tray.` var mBoxIcon = "./icons/start-up-full.png" +func getNeedsSetupMsg() string { + return `Wire-pod is now running in the background. You must set it up by heading to http://` + botsetup.GetOutboundIP().String() + `:` + sdkapp.WebPort + ` in a browser.` +} + func main() { - hcl := http.Client{} - hcl.Timeout = 2 - resp, err := hcl.Get("http://localhost:8080/api/is_running") + if os.Getenv("WEBSERVER_PORT") != "" { + if _, err := strconv.Atoi(os.Getenv("WEBSERVER_PORT")); err == nil { + sdkapp.WebPort = os.Getenv("WEBSERVER_PORT") + } else { + logger.Println("WEBSERVER_PORT contains letters, using default of 8080") + sdkapp.WebPort = "8080" + } + } else { + sdkapp.WebPort = "8080" + } + resp, err := http.Get("http://" + botsetup.GetOutboundIP().String() + ":" + sdkapp.WebPort + "/api/is_running") if err == nil { body, _ := io.ReadAll(resp.Body) if strings.TrimSpace(string(body)) == "true" { zenity.Error(mBoxAlreadyRunning, + zenity.ErrorIcon, zenity.Title(mBoxTitle)) - os.Exit(0) + os.Exit(1) } else { - zenity.Error("Port 8080 is in use by another program. Close that program before starting wire-pod. Exiting.", + zenity.Error("Port "+sdkapp.WebPort+" is in use by another program. Close that program before starting wire-pod. Exiting.", + zenity.ErrorIcon, zenity.Title(mBoxTitle)) - os.Exit(0) + os.Exit(1) } } - go app.Main() systray.Run(onReady, onExit) } func onExit() { - zenity.Info( - mBoxExit, - zenity.Icon(mBoxIcon), - zenity.Title(mBoxTitle), - ) os.Exit(0) } @@ -83,20 +81,20 @@ func onReady() { systray.SetTitle("wire-pod") systray.SetTooltip("wire-pod is starting...") mQuit := systray.AddMenuItem("Quit", "Quit the whole app") - mLogs := systray.AddMenuItem("View Logs", "Open the logs") + mBrowse := systray.AddMenuItem("Web interface", "Open web UI") go func() { for { select { case <-mQuit.ClickedCh: zenity.Info( - mBoxExit, + "Wire-pod will now exit.", zenity.Icon(mBoxIcon), zenity.Title(mBoxTitle), ) os.Exit(0) - case <-mLogs.ClickedCh: - go ShowLogs() + case <-mBrowse.ClickedCh: + go openBrowser("http://" + botsetup.GetOutboundIP().String() + ":" + sdkapp.WebPort) } } }() @@ -104,43 +102,21 @@ func onReady() { StartFromProgramInit(stt.Init, stt.STT, stt.Name) } -func ShowLogs() error { - w := app.NewWindow(app.Title("wire-pod log viewer"), app.Size(unit.Dp(600), unit.Dp(400))) - th := material.NewTheme() - th.Shaper = text.NewShaper(text.WithCollection(gofont.Collection())) - - var ops op.Ops - editor := new(widget.Editor) - editor.SingleLine = false - editor.ReadOnly = true // Make the editor read-only - - go func() { - chann := logger.GetChan() - for range chann { - w.Invalidate() - } - }() - - for { - e := <-w.Events() - switch e := e.(type) { - case system.DestroyEvent: - return e.Err - case system.FrameEvent: - gtx := layout.NewContext(&ops, e) - - // Update the editor's text with logger.TrayLogList - editor.SetText(logger.TrayLogList) +func openBrowser(url string) { + var err error + + switch runtime.GOOS { + case "linux": + err = exec.Command("xdg-open", url).Start() + case "windows": + err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start() + case "darwin": + err = exec.Command("open", url).Start() + default: + err = fmt.Errorf("unsupported platform") + } - layout.Flex{Axis: layout.Vertical}.Layout(gtx, - layout.Rigid(func(gtx layout.Context) layout.Dimensions { - editor := material.Editor(th, editor, "") - editor.TextSize = unit.Sp(16) - editor.Color = color.NRGBA{R: 127, G: 0, B: 0, A: 255} - return editor.Layout(gtx) - }), - ) - e.Frame(gtx.Ops) - } + if err != nil { + log.Fatal(err) } } diff --git a/chipper/cmd/windows/win-initwirepod.go b/chipper/cmd/windows/win-initwirepod.go index e2e5754b..256c54d7 100644 --- a/chipper/cmd/windows/win-initwirepod.go +++ b/chipper/cmd/windows/win-initwirepod.go @@ -6,6 +6,7 @@ import ( "net" "net/http" "os" + "path/filepath" "time" chipperpb "github.com/digital-dream-labs/api/go/chipperpb" @@ -21,6 +22,7 @@ import ( "github.com/kercre123/chipper/pkg/vars" wpweb "github.com/kercre123/chipper/pkg/wirepod/config-ws" wp "github.com/kercre123/chipper/pkg/wirepod/preqs" + "github.com/kercre123/chipper/pkg/wirepod/sdkapp" sdkWeb "github.com/kercre123/chipper/pkg/wirepod/sdkapp" botsetup "github.com/kercre123/chipper/pkg/wirepod/setup" "github.com/ncruces/zenity" @@ -39,6 +41,31 @@ var voiceProcessor *wp.Server var epodIsPosting bool +var NotSetUp string = "Wire-pod is not setup. Use the webserver at port " + sdkapp.WebPort + " to set up wire-pod." + +func NeedsSetupMsg() { + go func() { + err := zenity.Info( + getNeedsSetupMsg(), + zenity.Icon(mBoxIcon), + zenity.Title(mBoxTitle), + zenity.ExtraButton("Open browser"), + ) + if err != nil { + if err == zenity.ErrExtraButton { + openBrowser("http://" + botsetup.GetOutboundIP().String() + ":" + sdkapp.WebPort) + } + } + }() +} + +func ErrMsg(err error) { + zenity.Error("wire-pod has run into an issue. The program will now exit. Error details: "+err.Error(), + zenity.ErrorIcon, + zenity.Title(mBoxTitle)) + os.Exit(1) +} + // grpcServer *grpc.Servervar var chipperServing bool = false @@ -102,41 +129,23 @@ func BeginWirepodSpecific(sttInitFunc func() error, sttHandlerFunc interface{}, func StartFromProgramInit(sttInitFunc func() error, sttHandlerFunc interface{}, voiceProcessorName string) { err := BeginWirepodSpecific(sttInitFunc, sttHandlerFunc, voiceProcessorName) if err != nil { - logger.Println("\033[33m\033[1mWire-pod is not setup. Use the webserver at port 8080 to set up wire-pod.\033[0m") + logger.Println("Wire-pod is not setup. Use the webserver at port " + sdkapp.WebPort + " to set up wire-pod.") vars.APIConfig.PastInitialSetup = false vars.WriteConfigToDisk() - go zenity.Info( - mBoxNeedsSetupMsg, - zenity.Icon(mBoxIcon), - zenity.Title(mBoxTitle), - ) - systray.SetTooltip("wire-pod must be set up at http://localhost:8080.") + NeedsSetupMsg() + systray.SetTooltip("wire-pod must be set up at http://" + botsetup.GetOutboundIP().String() + ":" + sdkapp.WebPort) } else if !vars.APIConfig.PastInitialSetup { - logger.Println("\033[33m\033[1mWire-pod is not setup. Use the webserver at port 8080 to set up wire-pod.\033[0m") - go zenity.Info( - mBoxNeedsSetupMsg, - zenity.Icon(mBoxIcon), - zenity.Title(mBoxTitle), - ) - systray.SetTooltip("wire-pod must be set up at http://localhost:8080.") + logger.Println("Wire-pod is not setup. Use the webserver at port " + sdkapp.WebPort + " to set up wire-pod.") + NeedsSetupMsg() + systray.SetTooltip("wire-pod must be set up at http://" + botsetup.GetOutboundIP().String() + ":" + sdkapp.WebPort) } else if vars.APIConfig.STT.Service == "vosk" && vars.APIConfig.STT.Language == "" { logger.Println("\033[33m\033[1mLanguage value is blank, but STT service is Vosk. Reinitiating setup process.\033[0m") - logger.Println("\033[33m\033[1mWire-pod is not setup. Use the webserver at port 8080 to set up wire-pod.\033[0m") - go zenity.Info( - mBoxNeedsSetupMsg, - zenity.Icon(mBoxIcon), - zenity.Title(mBoxTitle), - ) - systray.SetTooltip("wire-pod must be set up at http://localhost:8080.") + logger.Println("Wire-pod is not setup. Use the webserver at port " + sdkapp.WebPort + " to set up wire-pod.") + NeedsSetupMsg() + systray.SetTooltip("wire-pod must be set up at http://" + botsetup.GetOutboundIP().String() + ":" + sdkapp.WebPort) vars.APIConfig.PastInitialSetup = false } else { - go zenity.Info( - mBoxSuccess, - zenity.Icon(mBoxIcon), - zenity.Title(mBoxTitle), - ) - systray.SetTitle("wire-pod is running.") - go StartChipper() + go StartChipper(true) } // main thread is configuration ws wpweb.StartWebServer() @@ -154,11 +163,33 @@ func PostmDNS() { } } +func IfFileExist(name string) bool { + _, err := os.Stat(name) + if err != nil { + return false + } + return true +} + func CheckHostname() { hostname, _ := os.Hostname() - if hostname != "escapepod" && vars.APIConfig.Server.EPConfig { + confDir, _ := os.UserConfigDir() + warnFile := filepath.Join(confDir, vars.PodName) + "/NoPodWarn" + if hostname != "escapepod" && vars.APIConfig.Server.EPConfig && !IfFileExist(warnFile) { logger.Println("\033[31m\033[1mWARNING: You have chosen the Escape Pod config, but the system hostname is not 'escapepod'. This means your robot will not be able to communicate with wire-pod unless you have a custom network configuration.") logger.Println("Actual reported hostname: " + hostname + "\033[0m") + err := zenity.Warning( + "WARNING: You have selected the Escape Pod config, but the system hostname is not 'escapepod'. This means your robot will not be able to communicate with wire-pod unless you have a custom network configuration.", + zenity.ExtraButton("Don't show again"), + zenity.OKLabel("OK"), + zenity.WarningIcon, + zenity.Title(mBoxTitle), + ) + if err != nil { + if err == zenity.ErrExtraButton { + os.WriteFile(filepath.Join(confDir, vars.PodName)+"/NoPodWarn", []byte("true"), 0777) + } + } } } @@ -169,12 +200,15 @@ func RestartServer() { listenerOne.Close() listenerTwo.Close() } - go StartChipper() + go StartChipper(false) } -func StartChipper() { - if vars.APIConfig.Server.EPConfig && !epodIsPosting { - go PostmDNS() +func StartChipper(fromInit bool) { + // if vars.APIConfig.Server.EPConfig && !epodIsPosting { + // go PostmDNS() + // } + if vars.APIConfig.Server.EPConfig { + CheckHostname() } // load certs var certPub []byte @@ -182,6 +216,8 @@ func StartChipper() { if vars.APIConfig.Server.EPConfig { certPub, _ = os.ReadFile("./epod/ep.crt") certPriv, _ = os.ReadFile("./epod/ep.key") + vars.ChipperKey = certPriv + vars.ChipperCert = certPub } else { if !vars.ChipperKeysLoaded { var err error @@ -190,9 +226,7 @@ func StartChipper() { if err != nil { logger.Println("Unable to read certificates. wire-pod is not setup.") logger.Println(err) - zenity.Error("wire-pod has run into an issue. The program will now exist. Error details: "+err.Error(), - zenity.NoIcon, - zenity.Title(mBoxTitle)) + ErrMsg(err) os.Exit(1) return } @@ -204,8 +238,7 @@ func StartChipper() { logger.Println("Initiating TLS listener, cmux, gRPC handler, and REST handler") cert, err := tls.X509KeyPair(vars.ChipperCert, vars.ChipperKey) if err != nil { - zenity.Error("wire-pod has run into an issue. The program will now exist. Error details: "+err.Error(), - zenity.Title(mBoxTitle)) + ErrMsg(err) logger.Println(err) os.Exit(1) } @@ -215,9 +248,7 @@ func StartChipper() { CipherSuites: nil, }) if err != nil { - zenity.Error("wire-pod has run into an issue. The program will now exist. Error details: "+err.Error(), - zenity.NoIcon, - zenity.Title(mBoxTitle)) + ErrMsg(err) fmt.Println(err) os.Exit(1) } @@ -234,9 +265,7 @@ func StartChipper() { CipherSuites: nil, }) if err != nil { - zenity.Error("wire-pod has run into an issue. The program will now exist. Error details: "+err.Error(), - zenity.NoIcon, - zenity.Title(mBoxTitle)) + ErrMsg(err) fmt.Println(err) os.Exit(1) } @@ -248,6 +277,13 @@ func StartChipper() { } systray.SetTooltip("wire-pod is running.") + if fromInit { + go zenity.Info( + mBoxSuccess, + zenity.Icon(mBoxIcon), + zenity.Title(mBoxTitle), + ) + } fmt.Println("\033[33m\033[1mwire-pod started successfully!\033[0m") chipperServing = true diff --git a/chipper/go.mod b/chipper/go.mod index 713851e3..23b75f59 100755 --- a/chipper/go.mod +++ b/chipper/go.mod @@ -14,7 +14,6 @@ require ( ) require ( - gioui.org v0.3.1 github.com/Picovoice/leopard/binding/go v1.2.0 github.com/alphacep/vosk-api/go v0.3.45 github.com/fforchino/vector-go-sdk v0.0.0-20231108155304-62168f3595d6 @@ -29,8 +28,6 @@ require ( ) require ( - gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2 // indirect - gioui.org/shader v1.0.8 // indirect github.com/agnivade/levenshtein v1.1.1 // indirect github.com/akavel/rsrc v0.10.2 // indirect github.com/cenkalti/backoff v2.2.1+incompatible // indirect @@ -44,7 +41,6 @@ require ( github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f // indirect github.com/go-audio/riff v1.0.0 // indirect github.com/go-stack/stack v1.8.0 // indirect - github.com/go-text/typesetting v0.0.0-20230803102845-24e03d8b5372 // indirect github.com/josephspurrier/goversioninfo v1.4.0 // indirect github.com/miekg/dns v1.1.27 // indirect github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect @@ -54,7 +50,6 @@ require ( github.com/sourcegraph/conc v0.3.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect - golang.org/x/exp/shiny v0.0.0-20220827204233-334a2380cb91 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect ) diff --git a/chipper/go.sum b/chipper/go.sum index a590c1ef..1a5569b2 100755 --- a/chipper/go.sum +++ b/chipper/go.sum @@ -38,14 +38,6 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -eliasnaur.com/font v0.0.0-20230308162249-dd43949cb42d h1:ARo7NCVvN2NdhLlJE9xAbKweuI9L6UgfTbYb0YwPacY= -gioui.org v0.3.1 h1:hslYkrkIWvx28Mxe3A87opl+8s9mnWsnWmPDh11+zco= -gioui.org v0.3.1/go.mod h1:2atiYR4upH71/6ehnh6XsUELa7JZOrOHHNMDxGBZF0Q= -gioui.org/cpu v0.0.0-20210808092351-bfe733dd3334/go.mod h1:A8M0Cn5o+vY5LTMlnRoK3O5kG+rH0kWfJjeKd9QpBmQ= -gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2 h1:AGDDxsJE1RpcXTAxPG2B4jrwVUJGFDjINIPi1jtO6pc= -gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2/go.mod h1:A8M0Cn5o+vY5LTMlnRoK3O5kG+rH0kWfJjeKd9QpBmQ= -gioui.org/shader v1.0.8 h1:6ks0o/A+b0ne7RzEqRZK5f4Gboz2CfG+mVliciy6+qA= -gioui.org/shader v1.0.8/go.mod h1:mWdiME581d/kV7/iEhLmUgUK5iZ09XR5XpduXzbePVM= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= @@ -195,9 +187,6 @@ github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/go-text/typesetting v0.0.0-20230803102845-24e03d8b5372 h1:FQivqchis6bE2/9uF70M2gmmLpe82esEm2QadL0TEJo= -github.com/go-text/typesetting v0.0.0-20230803102845-24e03d8b5372/go.mod h1:evDBbvNR/KaVFZ2ZlDSOWWXIUKq0wCOEtzLxRM8SG3k= -github.com/go-text/typesetting-utils v0.0.0-20230616150549-2a7df14b6a22 h1:LBQTFxP2MfsyEDqSKmUBZaDuDHN1vpqDyOZjcqS7MYI= github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0= github.com/gobuffalo/depgen v0.0.0-20190329151759-d478694a28d3/go.mod h1:3STtPUQYuzV0gBVOY3vy6CfMm/ljR4pABfrTeHNLHUY= github.com/gobuffalo/depgen v0.1.0/go.mod h1:+ifsuy7fhi15RWncXQQKjWS9JPkdah5sZvtHc2RXGlg= @@ -600,8 +589,6 @@ golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMk golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw= golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa h1:FRnLl4eNAQl8hwxVVC17teOw8kdjVDVAiFMtgUdTSRQ= golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE= -golang.org/x/exp/shiny v0.0.0-20220827204233-334a2380cb91 h1:ryT6Nf0R83ZgD8WnFFdfI8wCeyqgdXWN4+CkFVNPAT0= -golang.org/x/exp/shiny v0.0.0-20220827204233-334a2380cb91/go.mod h1:VjAR7z0ngyATZTELrBSkxOOHhhlnVUxDye4mcjx5h/8= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.14.0 h1:tNgSxAFe3jC4uYqvZdTr84SZoM1KfwdC9SKIFrLjFn4= diff --git a/chipper/pkg/vars/vars.go b/chipper/pkg/vars/vars.go index 4ea035ef..63434854 100644 --- a/chipper/pkg/vars/vars.go +++ b/chipper/pkg/vars/vars.go @@ -16,9 +16,11 @@ import ( var ( JdocsPath string = "./jdocs/jdocs.json" + JdocsDir string = "./jdocs" CustomIntentsPath string = "./customIntents.json" BotConfigsPath string = "./botConfig.json" BotInfoPath string = "./jdocs/botSdkInfo.json" + BotInfoName string = "botSdkInfo.json" PodName string = "wire-pod" VoskModelPath string = "../vosk/models/" ) @@ -109,10 +111,11 @@ func Init() { confDir, _ := os.UserConfigDir() podDir := join(confDir, PodName) os.Mkdir(podDir, 0777) - JdocsPath = join(podDir, JdocsPath) + JdocsDir = join(podDir, JdocsDir) + JdocsPath = JdocsDir + "/jdocs.json" CustomIntentsPath = join(podDir, CustomIntentsPath) BotConfigsPath = join(podDir, BotConfigsPath) - BotInfoPath = join(podDir, BotInfoPath) + BotInfoPath = JdocsDir + "/" + BotInfoName VoskModelPath = join(podDir, "./vosk/models/") ApiConfigPath = join(podDir, ApiConfigPath) CertPath = join(podDir, "./certs/cert.crt") @@ -120,7 +123,7 @@ func Init() { ServerConfigPath = join(podDir, "./certs/server_config.json") Certs = join(podDir, "./certs") SessionCertPath = join(podDir, SessionCertPath) - os.Mkdir(strings.TrimSuffix(JdocsPath, "/jdocs.json"), 0777) + os.Mkdir(JdocsDir, 0777) os.Mkdir(SessionCertPath, 0777) os.Mkdir(Certs, 0777) } diff --git a/chipper/pkg/wirepod/config-ws/webserver.go b/chipper/pkg/wirepod/config-ws/webserver.go index 41fbd038..c52cdca2 100755 --- a/chipper/pkg/wirepod/config-ws/webserver.go +++ b/chipper/pkg/wirepod/config-ws/webserver.go @@ -3,9 +3,9 @@ package webserver import ( "encoding/json" "fmt" - "log" "net/http" "os" + "runtime" "strconv" "strings" @@ -13,7 +13,9 @@ import ( "github.com/kercre123/chipper/pkg/vars" "github.com/kercre123/chipper/pkg/wirepod/localization" processreqs "github.com/kercre123/chipper/pkg/wirepod/preqs" + "github.com/kercre123/chipper/pkg/wirepod/sdkapp" botsetup "github.com/kercre123/chipper/pkg/wirepod/setup" + "github.com/ncruces/zenity" ) var SttInitFunc func() error @@ -327,24 +329,21 @@ func certHandler(w http.ResponseWriter, r *http.Request) { } func StartWebServer() { - var webPort string botsetup.RegisterSSHAPI() http.HandleFunc("/api/", apiHandler) http.HandleFunc("/session-certs/", certHandler) webRoot := http.FileServer(http.Dir("./webroot")) http.Handle("/", webRoot) - if os.Getenv("WEBSERVER_PORT") != "" { - if _, err := strconv.Atoi(os.Getenv("WEBSERVER_PORT")); err == nil { - webPort = os.Getenv("WEBSERVER_PORT") - } else { - logger.Println("WEBSERVER_PORT contains letters, using default of 8080") - webPort = "8080" - } - } else { - webPort = "8080" - } - fmt.Printf("Starting webserver at port " + webPort + " (http://localhost:" + webPort + ")\n") - if err := http.ListenAndServe(":"+webPort, nil); err != nil { - log.Fatal(err) + fmt.Printf("Starting webserver at port " + sdkapp.WebPort + " (http://localhost:" + sdkapp.WebPort + ")\n") + if err := http.ListenAndServe(":"+sdkapp.WebPort, nil); err != nil { + logger.Println("Error binding to " + sdkapp.WebPort + ": " + err.Error()) + if runtime.GOOS == "windows" { + zenity.Error( + "FATAL: Wire-pod was unable to bind to port "+sdkapp.WebPort+". Another process is likely using it. Exiting.", + zenity.ErrorIcon, + zenity.Title("wire-pod"), + ) + } + os.Exit(1) } } diff --git a/chipper/pkg/wirepod/sdkapp/server.go b/chipper/pkg/wirepod/sdkapp/server.go index 7b96b3cd..3b183a63 100755 --- a/chipper/pkg/wirepod/sdkapp/server.go +++ b/chipper/pkg/wirepod/sdkapp/server.go @@ -9,6 +9,7 @@ import ( "io" "net/http" "os" + "runtime" "strconv" "strings" "time" @@ -17,8 +18,11 @@ import ( "github.com/kercre123/chipper/pkg/logger" "github.com/kercre123/chipper/pkg/vars" botsetup "github.com/kercre123/chipper/pkg/wirepod/setup" + "github.com/ncruces/zenity" ) +var WebPort string + const serverFiles string = "./webroot/sdkapp" func SdkapiHandler(w http.ResponseWriter, r *http.Request) { @@ -493,19 +497,25 @@ func BeginServer() { logger.Println("Starting SDK app") fmt.Printf("Starting server at port 80 for connCheck\n") ipAddr := botsetup.GetOutboundIP().String() - var webPort string if os.Getenv("WEBSERVER_PORT") != "" { if _, err := strconv.Atoi(os.Getenv("WEBSERVER_PORT")); err == nil { - webPort = os.Getenv("WEBSERVER_PORT") + WebPort = os.Getenv("WEBSERVER_PORT") } else { logger.Println("WEBSERVER_PORT contains letters, using default of 8080") - webPort = "8080" + WebPort = "8080" } } else { - webPort = "8080" + WebPort = "8080" } - logger.Println("\033[1;36mConfiguration page: http://" + ipAddr + ":" + webPort + "\033[0m") + logger.Println("\033[1;36mConfiguration page: http://" + ipAddr + ":" + WebPort + "\033[0m") if err := http.ListenAndServe(":80", nil); err != nil { + if runtime.GOOS == "windows" { + go zenity.Warning( + "A process is using port 80. Wire-pod will keep running, but connCheck functionality will not work, so your bot may not always stay connected to your wire-pod instance.", + zenity.Title("wire-pod"), + zenity.WarningIcon, + ) + } logger.Println("A process is already using port 80 - connCheck functionality will not work") } } diff --git a/chipper/windows/build.sh b/chipper/windows/build.sh index b256da1f..ecef43fc 100755 --- a/chipper/windows/build.sh +++ b/chipper/windows/build.sh @@ -17,8 +17,6 @@ fi export ORIGDIR="$(pwd)" export PODLIBS="${ORIGDIR}/libs" -export - mkdir -p "${PODLIBS}" if [[ ! -d ogg ]] || [[ ! -d "${PODLIBS}/ogg" ]]; then @@ -96,9 +94,9 @@ cp ${PODLIBS}/vosk/* tmp/wire-pod/chipper/ cd tmp -rm -rf ../wire-pod-win.zip +rm -rf ../wire-pod-win-${ARCHITECTURE}.zip -zip -r ../wire-pod-win.zip wire-pod +zip -r ../wire-pod-win-${ARCHITECTURE}.zip wire-pod cd .. rm -rf tmp