forked from dweymouth/supersonic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (61 loc) · 1.73 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
package main
import (
"log"
"path"
"supersonic/backend"
"supersonic/ui"
"supersonic/ui/theme"
"time"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"github.com/20after4/configdir"
)
const (
appname = "supersonic"
displayName = "Supersonic"
appVersion = "0.0.1-alpha1"
configFile = "config.toml"
)
func configPath() string {
return path.Join(configdir.LocalConfig(appname), configFile)
}
func main() {
myApp, err := backend.StartupApp()
if err != nil {
log.Fatalf("fatal startup error: %v", err.Error())
}
fyneApp := app.New()
fyneApp.Settings().SetTheme(&theme.MyTheme{})
w := float32(myApp.Config.Application.WindowWidth)
if w <= 1 {
w = 1000
}
h := float32(myApp.Config.Application.WindowHeight)
if h <= 1 {
h = 800
}
mainWindow := ui.NewMainWindow(fyneApp, displayName, appVersion, myApp, fyne.NewSize(w, h))
// TODO: There is some race condition with running this initial startup
// task immediately before showing and running the window/Fyne main loop where
// the window can occasionally get misdrawn on startup. (Only seen on Ubuntu so far).
// This makes it much less likely to occur (not seen on dozens of startups)
// but is a hacky "solution"!
go func() {
time.Sleep(250 * time.Millisecond)
defaultServer := myApp.Config.GetDefaultServer()
if defaultServer == nil {
mainWindow.Controller.PromptForFirstServer()
} else {
mainWindow.Controller.DoConnectToServerWorkflow(defaultServer)
}
}()
mainWindow.Show()
mainWindow.Window.SetCloseIntercept(func() {
myApp.Config.Application.WindowHeight = int(mainWindow.Canvas().Size().Height)
myApp.Config.Application.WindowWidth = int(mainWindow.Canvas().Size().Width)
mainWindow.Window.Close()
})
fyneApp.Run()
// shutdown tasks
myApp.Shutdown()
}