forked from wailsapp/wails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
application_dev.go
50 lines (43 loc) · 1.31 KB
/
application_dev.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
//go:build !production
package application
import (
"github.com/zappie/wails/v3/internal/assetserver"
"net/http"
"time"
)
var devMode = false
func (a *App) preRun() error {
// Check for frontend server url
frontendURL := assetserver.GetDevServerURL()
if frontendURL != "" {
devMode = true
// We want to check if the frontend server is running by trying to http get the url
// and if it is not, we wait 500ms and try again for a maximum of 10 times. If it is
// still not available, we return an error.
// This is to allow the frontend server to start up before the backend server.
client := http.Client{}
a.Logger.Info("Waiting for frontend dev server to start...", "url", frontendURL)
for i := 0; i < 10; i++ {
_, err := client.Get(frontendURL)
if err == nil {
a.Logger.Info("Connected to frontend dev server!")
return nil
}
// Wait 500ms
time.Sleep(500 * time.Millisecond)
if i%2 == 0 {
a.Logger.Info("Retrying...")
}
}
a.fatal("unable to connect to frontend server. Please check it is running", "FRONTEND_DEVSERVER_URL", frontendURL)
}
return nil
}
func (a *App) postQuit() {
if devMode {
a.Logger.Info("The application has terminated, but the watcher is still running.")
a.Logger.Info("To terminate the watcher, press CTRL+C")
}
}
func (a *App) enableDevTools() {
}