forked from dweymouth/supersonic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
97 lines (84 loc) · 2.44 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
97
package main
import (
"flag"
"fmt"
"log"
"os"
"runtime"
"time"
"github.com/dweymouth/supersonic/backend"
"github.com/dweymouth/supersonic/res"
"github.com/dweymouth/supersonic/ui"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/lang"
)
func main() {
// parse cmd line flags - see backend/cmdlineoptions.go
flag.Parse()
if *backend.FlagVersion {
fmt.Println(res.AppVersion)
return
}
if *backend.FlagHelp {
flag.Usage()
return
}
// rest of flag actions are handled in backend.StartupApp
myApp, err := backend.StartupApp(res.AppName, res.DisplayName, res.AppVersionTag, res.LatestReleaseURL)
if err != nil {
if err != backend.ErrAnotherInstance {
log.Fatalf("fatal startup error: %v", err.Error())
}
return
}
if myApp.Config.Application.UIScaleSize == "Smaller" {
os.Setenv("FYNE_SCALE", "0.85")
} else if myApp.Config.Application.UIScaleSize == "Larger" {
os.Setenv("FYNE_SCALE", "1.1")
}
lang.AddTranslationsFS(res.Translations, "translations")
fyneApp := app.New()
fyneApp.SetIcon(res.ResAppicon256Png)
mainWindow := ui.NewMainWindow(fyneApp, res.AppName, res.DisplayName, res.AppVersion, myApp)
myApp.OnReactivate = mainWindow.Show
myApp.OnExit = mainWindow.Quit
go func() {
defaultServer := myApp.ServerManager.GetDefaultServer()
if defaultServer == nil {
mainWindow.Controller.PromptForFirstServer()
} else {
mainWindow.Controller.DoConnectToServerWorkflow(defaultServer)
}
// hacky workaround for https://github.com/fyne-io/fyne/issues/4964
if runtime.GOOS == "linux" {
time.Sleep(350 * time.Millisecond)
canvas := mainWindow.Window.Canvas()
size := canvas.Size()
desired := mainWindow.DesiredSize()
if !inDelta(size, desired, 1) {
// window drawn at incorrect size on startup
scale := canvas.Scale()
for i := 0; i < 3 && !inDelta(size, desired, 1); i++ {
if i > 0 {
// if resize didn't work the first time, try again with slightly
// different desired size
desired.Subtract(fyne.NewSize(2, 2))
}
SendResizeToPID(os.Getpid(), int(desired.Width*scale), int(desired.Height*scale))
time.Sleep(100 * time.Millisecond)
size = canvas.Size()
}
}
}
}()
mainWindow.ShowAndRun()
log.Println("Running shutdown tasks...")
myApp.Shutdown()
}
func inDelta(a, b fyne.Size, delta float32) bool {
diffW := a.Width - b.Width
diffH := a.Height - b.Height
return diffW < delta && diffW > -delta &&
diffH < delta && diffH > -delta
}