github.com/pojntfx/hydrapp/hydrapp@v0.0.0-20240516002902-d08759d6ca9f/pkg/generators/main_vanillajs_forms.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 13 "{{ .GoMod }}/pkg/frontend" 14 "github.com/pojntfx/hydrapp/hydrapp/pkg/browser" 15 "github.com/pojntfx/hydrapp/hydrapp/pkg/config" 16 _ "github.com/pojntfx/hydrapp/hydrapp/pkg/fixes" 17 "github.com/pojntfx/hydrapp/hydrapp/pkg/update" 18 "github.com/pojntfx/hydrapp/hydrapp/pkg/utils" 19 ) 20 21 //go:embed hydrapp.yaml 22 var configFile []byte 23 24 func main() { 25 ctx, cancel := context.WithCancel(context.Background()) 26 defer cancel() 27 28 cfg, err := config.Parse(bytes.NewBuffer(configFile)) 29 if err != nil { 30 utils.HandlePanic("App", "could not parse config file", err) 31 32 return 33 } 34 35 // Apply the self-update 36 browserState := &update.BrowserState{} 37 go update.Update( 38 ctx, 39 40 cfg, 41 browserState, 42 utils.HandlePanic, 43 ) 44 45 // Start the frontend 46 frontendURL, stopFrontend, err := frontend.StartServer(ctx, os.Getenv(utils.EnvFrontendLaddr), true) 47 if err != nil { 48 utils.HandlePanic(cfg.App.Name, "could not start frontend", err) 49 } 50 defer stopFrontend() 51 52 log.Println("Frontend URL:", frontendURL) 53 54 browser.LaunchBrowser( 55 frontendURL, 56 cfg.App.Name, 57 cfg.App.ID, 58 59 os.Getenv(utils.EnvBrowser), 60 os.Getenv(utils.EnvType), 61 62 browser.ChromiumLikeBrowsers, 63 browser.FirefoxLikeBrowsers, 64 browser.EpiphanyLikeBrowsers, 65 browser.LynxLikeBrowsers, 66 67 browserState, 68 func(msg string, err error) { 69 utils.HandlePanic(cfg.App.Name, msg, err) 70 }, 71 ) 72 }