-
-
Notifications
You must be signed in to change notification settings - Fork 49
/
main.go
116 lines (103 loc) · 3.08 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package main
import (
"flag"
"fmt"
"log"
"os"
"runtime"
"slices"
"sync"
"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/driver"
"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.AppVersion, 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")
}
// load configured app language, or all otherwise
lIdx := slices.IndexFunc(res.TranslationsInfo, func(t res.TranslationInfo) bool {
return t.Name == myApp.Config.Application.Language
})
success := false
if lIdx >= 0 {
tr := res.TranslationsInfo[lIdx]
content, err := res.Translations.ReadFile("translations/" + tr.TranslationFileName)
if err == nil {
// "trick" Fyne into loading translations for configured language
// by pretending it's the translation for the system locale
name := lang.SystemLocale().LanguageString()
lang.AddTranslations(fyne.NewStaticResource(name+".json", content))
success = true
} else {
log.Printf("Error loading translation file %s: %s\n", tr.TranslationFileName, err.Error())
}
}
if !success {
if err := lang.AddTranslationsFS(res.Translations, "translations"); err != nil {
log.Printf("Error loading translations: %s", err.Error())
}
}
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)
}
}()
// slightly hacky workaround for https://github.com/fyne-io/fyne/issues/4964
if runtime.GOOS == "linux" {
workaroundWindowSize := sync.OnceFunc(func() {
go func() {
isWayland := false
mainWindow.Window.(driver.NativeWindow).RunNative(func(ctx any) {
_, isWayland = ctx.(*driver.WaylandWindowContext)
})
if !isWayland {
time.Sleep(50 * time.Millisecond)
s := mainWindow.DesiredSize()
mainWindow.Window.Resize(s.Subtract(fyne.NewSize(4, 0)))
time.Sleep(50 * time.Millisecond)
mainWindow.Window.Resize(s) // back to desired size
}
}()
})
fyneApp.Lifecycle().SetOnEnteredForeground(func() {
workaroundWindowSize()
})
}
mainWindow.ShowAndRun()
log.Println("Running shutdown tasks...")
myApp.Shutdown()
}