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/app" ) 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") } 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() { // TODO: There is a race condition with laying out the window before the // window creation animation on Ubuntu (and other DEs?) finishes, where // the window will be misdrawn into a smaller area if the animation hasn't finished. // This makes it much less likely to occur (not seen on dozens of startups) // but is a hacky "solution"! if runtime.GOOS == "linux" { time.Sleep(250 * time.Millisecond) } defaultServer := myApp.ServerManager.GetDefaultServer() if defaultServer == nil { mainWindow.Controller.PromptForFirstServer() } else { mainWindow.Controller.DoConnectToServerWorkflow(defaultServer) } }() mainWindow.Show() mainWindow.Window.SetCloseIntercept(func() { mainWindow.SaveWindowSize() if myApp.Config.Application.CloseToSystemTray && mainWindow.HaveSystemTray() { mainWindow.Window.Hide() } else { fyneApp.Quit() } }) fyneApp.Run() log.Println("Running shutdown tasks...") myApp.Shutdown() }