This repository was archived by the owner on Jul 9, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
177 lines (159 loc) · 5.04 KB
/
Copy pathmain.go
File metadata and controls
177 lines (159 loc) · 5.04 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package main
import (
"bytes"
"flag"
"fmt"
"image/png"
"log"
"os"
"runtime"
"slices"
"sync"
"github.com/dweymouth/supersonic/backend"
"github.com/dweymouth/supersonic/backend/windows"
"github.com/dweymouth/supersonic/res"
"github.com/dweymouth/supersonic/res/wintaskbarthumbs"
"github.com/dweymouth/supersonic/ui"
"github.com/dweymouth/supersonic/ui/controller"
myTheme "github.com/dweymouth/supersonic/ui/theme"
"github.com/dweymouth/supersonic/ui/util"
"golang.org/x/term"
"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
}
if !term.IsTerminal(int(os.Stdin.Fd())) {
if *backend.FlagPlayAlbum {
fmt.Scanln(&backend.PlayAlbumCLIArg)
} else if *backend.FlagPlayPlaylist {
fmt.Scanln(&backend.PlayPlaylistCLIArg)
} else if *backend.FlagPlayTrack {
fmt.Scanln(&backend.PlayTrackCLIArg)
}
}
// 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")
}
if myApp.Config.Application.DisableDPIDetection {
os.Setenv("FYNE_DISABLE_DPI_DETECTION", "true")
}
// 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())
}
}
if runtime.GOOS == "windows" {
if err := initWindowsTaskbarIcons(); err != nil {
log.Printf("Error initializing taskbar thumbnail icons: %s", err.Error())
}
if err := windows.SetTaskbarButtonToolTips(
lang.L("Previous"),
lang.L("Next"),
lang.L("Play"),
lang.L("Pause"),
); err != nil {
log.Printf("error initializing taskbar button tool tips: %s", err.Error())
}
}
fyneApp := app.New()
fyneApp.SetIcon(res.ResAppicon256Png)
mainWindow := ui.NewMainWindow(fyneApp, res.AppName, res.DisplayName, res.AppVersion, myApp)
mainWindow.Window.SetMaster()
myApp.OnReactivate = util.FyneDoFunc(mainWindow.Show)
myApp.OnExit = util.FyneDoFunc(mainWindow.Quit)
myApp.OnReloadTheme = util.FyneDoFunc(mainWindow.ReloadTheme)
if runtime.GOOS == "windows" {
windowStartupTasks := sync.OnceFunc(func() {
mainWindow.Window.(driver.NativeWindow).RunNative(func(ctx any) {
hwnd := ctx.(driver.WindowsWindowContext).HWND
if myApp.Config.Application.EnableOSMediaPlayerAPIs {
myApp.SetupWindowsSMTC(hwnd)
}
myApp.SetupWindowsTaskbarButtons(hwnd)
})
})
fyneApp.Lifecycle().SetOnEnteredForeground(windowStartupTasks)
}
if *backend.FlagStartMinimized {
if err = myApp.LoginToDefaultServer(); err != nil {
log.Fatalf("failed to connect to server: %v", err.Error())
return
}
fyneApp.Run()
} else {
fyneApp.Lifecycle().SetOnStarted(func() {
if mode := fyne.CurrentApp().Settings().Theme().(*myTheme.MyTheme).AppearanceMode(); mode != myTheme.AppearanceAuto {
controller.SetWindowThemeMode(mainWindow.Window, mode)
}
defaultServer := myApp.ServerManager.GetDefaultServer()
if defaultServer == nil {
mainWindow.Controller.PromptForFirstServer()
} else if !*backend.FlagStartMinimized { // If the minimized start flag was passed, the connection is already established.
mainWindow.Controller.DoConnectToServerWorkflow(defaultServer)
}
})
mainWindow.ShowAndRun()
}
log.Println("Running shutdown tasks...")
myApp.Shutdown()
}
func initWindowsTaskbarIcons() error {
play, err := png.Decode(bytes.NewReader(wintaskbarthumbs.MediaPlayPNG))
if err != nil {
return err
}
pause, err := png.Decode(bytes.NewReader(wintaskbarthumbs.MediaPausePNG))
if err != nil {
return err
}
prev, err := png.Decode(bytes.NewReader(wintaskbarthumbs.MediaSeekPreviousPNG))
if err != nil {
return err
}
next, err := png.Decode(bytes.NewReader(wintaskbarthumbs.MediaSeekNextPNG))
if err != nil {
return err
}
windows.InitializeTaskbarIcons(prev, next, play, pause)
return nil
}