-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
96 lines (76 loc) · 1.88 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//go:build !android
// +build !android
package main
import (
"bytes"
"context"
_ "embed"
"errors"
"fmt"
"log"
"os"
"time"
"github.com/loopholelabs/latensee/pkg/backend"
"github.com/loopholelabs/latensee/pkg/frontend"
"github.com/pojntfx/hydrapp/hydrapp/pkg/config"
_ "github.com/pojntfx/hydrapp/hydrapp/pkg/fixes"
"github.com/pojntfx/hydrapp/hydrapp/pkg/ui"
)
//go:embed hydrapp.yaml
var configFile []byte
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cfg, err := config.Parse(bytes.NewBuffer(configFile))
if err != nil {
ui.HandleFatalPanic("App", errors.Join(fmt.Errorf("could not parse config file"), err))
return
}
// Apply the self-update
browserState := &ui.BrowserState{}
go func() {
if err := ui.SelfUpdate(
ctx,
cfg,
browserState,
); err != nil {
ui.HandleFatalPanic(cfg.App.Name, err)
}
}()
// Start the backend
backendURL, stopBackend, err := backend.StartServer(ctx, os.Getenv(ui.EnvBackendLaddr), time.Second*10, true)
if err != nil {
ui.HandleFatalPanic(cfg.App.Name, errors.Join(fmt.Errorf("could not start backend"), err))
}
defer stopBackend()
log.Println("Backend URL:", backendURL)
// Start the frontend
frontendURL, stopFrontend, err := frontend.StartServer(ctx, os.Getenv(ui.EnvFrontendLaddr), backendURL, true)
if err != nil {
ui.HandleFatalPanic(cfg.App.Name, errors.Join(fmt.Errorf("could not start frontend"), err))
}
defer stopFrontend()
log.Println("Frontend URL:", frontendURL)
for {
retry, err := ui.LaunchBrowser(
ctx,
frontendURL,
cfg.App.Name,
cfg.App.ID,
os.Getenv(ui.EnvBrowser),
os.Getenv(ui.EnvType),
ui.ChromiumLikeBrowsers,
ui.FirefoxLikeBrowsers,
ui.EpiphanyLikeBrowsers,
ui.LynxLikeBrowsers,
browserState,
ui.ConfigureBrowser,
)
if err != nil {
ui.HandleFatalPanic(cfg.App.Name, err)
}
if !retry {
return
}
}
}