github.com/pojntfx/hydrapp/hydrapp@v0.0.0-20240516002902-d08759d6ca9f/pkg/generators/main_react_panrpc.go.tpl (about) 1 //go:build !android 2 // +build !android 3 4 package main 5 6 import ( 7 "bytes" 8 "context" 9 _ "embed" 10 "log" 11 "os" 12 "time" 13 14 "{{ .GoMod }}/pkg/backend" 15 "{{ .GoMod }}/pkg/frontend" 16 "github.com/pojntfx/hydrapp/hydrapp/pkg/browser" 17 "github.com/pojntfx/hydrapp/hydrapp/pkg/config" 18 _ "github.com/pojntfx/hydrapp/hydrapp/pkg/fixes" 19 "github.com/pojntfx/hydrapp/hydrapp/pkg/update" 20 "github.com/pojntfx/hydrapp/hydrapp/pkg/utils" 21 ) 22 23 //go:embed hydrapp.yaml 24 var configFile []byte 25 26 func main() { 27 ctx, cancel := context.WithCancel(context.Background()) 28 defer cancel() 29 30 cfg, err := config.Parse(bytes.NewBuffer(configFile)) 31 if err != nil { 32 utils.HandlePanic("App", "could not parse config file", err) 33 34 return 35 } 36 37 // Apply the self-update 38 browserState := &update.BrowserState{} 39 go update.Update( 40 ctx, 41 42 cfg, 43 browserState, 44 utils.HandlePanic, 45 ) 46 47 // Start the backend 48 backendURL, stopBackend, err := backend.StartServer(ctx, os.Getenv(utils.EnvBackendLaddr), time.Second*10, true) 49 if err != nil { 50 utils.HandlePanic(cfg.App.Name, "could not start backend", err) 51 } 52 defer stopBackend() 53 54 log.Println("Backend URL:", backendURL) 55 56 // Start the frontend 57 frontendURL, stopFrontend, err := frontend.StartServer(ctx, os.Getenv(utils.EnvFrontendLaddr), backendURL, true) 58 if err != nil { 59 utils.HandlePanic(cfg.App.Name, "could not start frontend", err) 60 } 61 defer stopFrontend() 62 63 log.Println("Frontend URL:", frontendURL) 64 65 browser.LaunchBrowser( 66 frontendURL, 67 cfg.App.Name, 68 cfg.App.ID, 69 70 os.Getenv(utils.EnvBrowser), 71 os.Getenv(utils.EnvType), 72 73 browser.ChromiumLikeBrowsers, 74 browser.FirefoxLikeBrowsers, 75 browser.EpiphanyLikeBrowsers, 76 browser.LynxLikeBrowsers, 77 78 browserState, 79 func(msg string, err error) { 80 utils.HandlePanic(cfg.App.Name, msg, err) 81 }, 82 ) 83 }