Merge pull request #4 from dweymouth/develop

hacky solution to avoid occasional window misdrawing on startup
This commit is contained in:
Drew Weymouth
2022-12-27 18:23:59 -08:00
committed by GitHub
+24 -15
View File
@@ -5,6 +5,7 @@ import (
"path"
"supersonic/backend"
"supersonic/ui"
"time"
"fyne.io/fyne/v2/app"
"github.com/20after4/configdir"
@@ -28,24 +29,32 @@ func main() {
fyneApp := app.New()
mainWindow := ui.NewMainWindow(fyneApp, appname, myApp)
defaultServer := myApp.Config.GetDefaultServer()
if defaultServer == nil {
mainWindow.PromptForFirstServer(func(nick, host, user, pass string) {
server := myApp.Config.AddServer(nick, host, user)
err := keyring.Set(appname, server.ID.String(), pass)
if err != nil {
log.Printf("error setting keyring credentials: %v", err)
// TODO: handle?
}
setupServer(myApp, server)
})
} else {
setupServer(myApp, defaultServer)
}
// 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(75 * time.Millisecond)
defaultServer := myApp.Config.GetDefaultServer()
if defaultServer == nil {
mainWindow.PromptForFirstServer(func(nick, host, user, pass string) {
server := myApp.Config.AddServer(nick, host, user)
err := keyring.Set(appname, server.ID.String(), pass)
if err != nil {
log.Printf("error setting keyring credentials: %v", err)
// TODO: handle?
}
setupServer(myApp, server)
})
} else {
setupServer(myApp, defaultServer)
}
}()
mainWindow.Show()
fyneApp.Run()
myApp.Config.WriteConfigFile(configPath())
myApp.Shutdown()