Fix keyring unlock blocking the Fyne event loop on startup (#900)
GetServerPassword can block while the system keyring daemon shows its unlock dialog. Calling it synchronously on the Fyne main thread froze the event loop, causing Wayland compositors to hide the window. Move the keyring lookup into a goroutine and dispatch back to the Fyne thread to show the connecting dialog and attempt the connection.
This commit is contained in:
@@ -49,14 +49,24 @@ func (m *Controller) PromptForFirstServer() {
|
|||||||
|
|
||||||
// DoConnectToServerWorkflow does the workflow for connecting to the last active server on startup
|
// DoConnectToServerWorkflow does the workflow for connecting to the last active server on startup
|
||||||
func (c *Controller) DoConnectToServerWorkflow(server *backend.ServerConfig) {
|
func (c *Controller) DoConnectToServerWorkflow(server *backend.ServerConfig) {
|
||||||
pass, err := c.App.ServerManager.GetServerPassword(server.ID)
|
// GetServerPassword may block on keyring unlock (showing a system dialog),
|
||||||
if err != nil {
|
// so run it in a goroutine to avoid freezing the Fyne event loop.
|
||||||
log.Printf("error getting password from keyring: %v", err)
|
go func() {
|
||||||
c.PromptForLoginAndConnect()
|
pass, err := c.App.ServerManager.GetServerPassword(server.ID)
|
||||||
return
|
if err != nil {
|
||||||
}
|
log.Printf("error getting password from keyring: %v", err)
|
||||||
|
fyne.Do(c.PromptForLoginAndConnect)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// try connecting to last used server - set up cancelable modal dialog
|
// Password retrieved; show the dialog and connect from the Fyne thread
|
||||||
|
fyne.Do(func() {
|
||||||
|
c.doConnectWithPassword(server, pass)
|
||||||
|
})
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Controller) doConnectWithPassword(server *backend.ServerConfig, pass string) {
|
||||||
canceled := false
|
canceled := false
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
dlg := dialog.NewCustom(lang.L("Connecting"), lang.L("Cancel"),
|
dlg := dialog.NewCustom(lang.L("Connecting"), lang.L("Cancel"),
|
||||||
|
|||||||
Reference in New Issue
Block a user