Fix #595: fix a few missed threading/fyne.Do conversions in controller
This commit is contained in:
@@ -57,7 +57,7 @@ func (m *Controller) connectTracklistActionsWithReplayGainMode(tracklist *widget
|
||||
}
|
||||
tracklist.OnDownload = m.ShowDownloadDialog
|
||||
tracklist.OnShare = func(trackID string) {
|
||||
go m.ShowShareDialog(trackID)
|
||||
m.ShowShareDialog(trackID)
|
||||
}
|
||||
tracklist.OnShowTrackInfo = m.ShowTrackInfoDialog
|
||||
tracklist.OnPlaySongRadio = func(track *mediaprovider.Track) {
|
||||
@@ -104,7 +104,9 @@ func (m *Controller) ConnectAlbumGridActions(grid *widgets.GridView) {
|
||||
log.Printf("error loading album: %s", err.Error())
|
||||
return
|
||||
}
|
||||
m.DoAddTracksToPlaylistWorkflow(sharedutil.TracksToIDs(album.Tracks))
|
||||
fyne.Do(func() {
|
||||
m.DoAddTracksToPlaylistWorkflow(sharedutil.TracksToIDs(album.Tracks))
|
||||
})
|
||||
}()
|
||||
}
|
||||
grid.OnDownload = func(albumID string) {
|
||||
@@ -114,11 +116,13 @@ func (m *Controller) ConnectAlbumGridActions(grid *widgets.GridView) {
|
||||
log.Printf("error loading album: %s", err.Error())
|
||||
return
|
||||
}
|
||||
m.ShowDownloadDialog(album.Tracks, album.Name)
|
||||
fyne.Do(func() {
|
||||
m.ShowDownloadDialog(album.Tracks, album.Name)
|
||||
})
|
||||
}()
|
||||
}
|
||||
grid.OnShare = func(albumID string) {
|
||||
go m.ShowShareDialog(albumID)
|
||||
m.ShowShareDialog(albumID)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +136,7 @@ func (m *Controller) ConnectArtistGridActions(grid *widgets.GridView) {
|
||||
go m.App.PlaybackManager.LoadTracks(m.GetArtistTracks(artistID), backend.Append, false)
|
||||
}
|
||||
grid.OnAddToPlaylist = func(artistID string) {
|
||||
go m.DoAddTracksToPlaylistWorkflow(
|
||||
m.DoAddTracksToPlaylistWorkflow(
|
||||
sharedutil.TracksToIDs(m.GetArtistTracks(artistID)))
|
||||
}
|
||||
grid.OnFavorite = func(artistID string, favorite bool) {
|
||||
@@ -148,11 +152,13 @@ func (m *Controller) ConnectArtistGridActions(grid *widgets.GridView) {
|
||||
log.Printf("error getting artist: %v", err.Error())
|
||||
return
|
||||
}
|
||||
m.ShowDownloadDialog(tracks, tist.Name)
|
||||
fyne.Do(func() {
|
||||
m.ShowDownloadDialog(tracks, tist.Name)
|
||||
})
|
||||
}()
|
||||
}
|
||||
grid.OnShare = func(artistID string) {
|
||||
go m.ShowShareDialog(artistID)
|
||||
m.ShowShareDialog(artistID)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -400,7 +400,7 @@ func (c *Controller) ShowShareDialog(id string) {
|
||||
container.NewHBox(
|
||||
hyperlink,
|
||||
widget.NewButtonWithIcon("", theme.ContentCopyIcon(), func() {
|
||||
c.MainWindow.Clipboard().SetContent(hyperlink.Text)
|
||||
fyne.CurrentApp().Clipboard().SetContent(hyperlink.Text)
|
||||
}),
|
||||
widget.NewButtonWithIcon("", theme.ViewRefreshIcon(), func() {
|
||||
if shareUrl, err := c.createShareURL(id); err == nil {
|
||||
@@ -486,8 +486,10 @@ func (c *Controller) downloadTrack(track *mediaprovider.Track, filePath string)
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("Saved song %s to: %s\n", track.Title, filePath)
|
||||
c.sendNotification(fmt.Sprintf(lang.L("Download completed")+": %s", track.Title), fmt.Sprintf(lang.L("Saved at")+": %s", filePath))
|
||||
log.Printf("Saved track %q to: %s\n", track.Title, filePath)
|
||||
fyne.Do(func() {
|
||||
c.sendNotification(fmt.Sprintf(lang.L("Download completed")+": %s", track.Title), fmt.Sprintf(lang.L("Saved at")+": %s", filePath))
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Controller) downloadTracks(tracks []*mediaprovider.Track, filePath, downloadName string) {
|
||||
@@ -525,7 +527,9 @@ func (c *Controller) downloadTracks(tracks []*mediaprovider.Track, filePath, dow
|
||||
log.Printf("Saved song %s to: %s\n", track.Title, filePath)
|
||||
}
|
||||
|
||||
c.sendNotification(fmt.Sprintf(lang.L("Download completed")+": %s", downloadName), fmt.Sprintf("Saved at: %s", filePath))
|
||||
fyne.Do(func() {
|
||||
c.sendNotification(fmt.Sprintf(lang.L("Download completed")+": %s", downloadName), fmt.Sprintf("Saved at: %s", filePath))
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Controller) sendNotification(title, content string) {
|
||||
|
||||
@@ -22,8 +22,10 @@ func (m *Controller) PromptForFirstServer() {
|
||||
go func() {
|
||||
if m.testConnectionAndUpdateDialogText(d) {
|
||||
// connection is good
|
||||
pop.Hide()
|
||||
m.doModalClosed()
|
||||
fyne.Do(func() {
|
||||
pop.Hide()
|
||||
m.doModalClosed()
|
||||
})
|
||||
conn := backend.ServerConnection{
|
||||
ServerType: d.ServerType,
|
||||
Hostname: d.Host,
|
||||
@@ -35,8 +37,9 @@ func (m *Controller) PromptForFirstServer() {
|
||||
if err := m.trySetPasswordAndConnectToServer(server, d.Password); err != nil {
|
||||
log.Printf("error connecting to server: %s", err.Error())
|
||||
}
|
||||
} else {
|
||||
fyne.Do(d.EnableSubmit)
|
||||
}
|
||||
d.EnableSubmit()
|
||||
}()
|
||||
}
|
||||
m.haveModal = true
|
||||
@@ -227,8 +230,9 @@ func (c *Controller) tryConnectToServer(ctx context.Context, server *backend.Ser
|
||||
return nil
|
||||
}
|
||||
|
||||
// should be called from goroutine
|
||||
func (c *Controller) testConnectionAndUpdateDialogText(dlg *dialogs.AddEditServerDialog) bool {
|
||||
dlg.SetInfoText(lang.L("Testing connection") + "...")
|
||||
fyne.Do(func() { dlg.SetInfoText(lang.L("Testing connection") + "...") })
|
||||
conn := backend.ServerConnection{
|
||||
ServerType: dlg.ServerType,
|
||||
Hostname: dlg.Host,
|
||||
@@ -240,10 +244,14 @@ func (c *Controller) testConnectionAndUpdateDialogText(dlg *dialogs.AddEditServe
|
||||
defer cancel()
|
||||
err := c.App.ServerManager.TestConnectionAndAuth(ctx, conn, dlg.Password)
|
||||
if err == backend.ErrUnreachable {
|
||||
dlg.SetErrorText(lang.L("Could not reach server") + fmt.Sprintf(" (%s?)", lang.L("wrong URL")))
|
||||
fyne.Do(func() {
|
||||
dlg.SetErrorText(lang.L("Could not reach server") + fmt.Sprintf(" (%s?)", lang.L("wrong URL")))
|
||||
})
|
||||
return false
|
||||
} else if err != nil {
|
||||
dlg.SetErrorText(lang.L("Authentication failed") + fmt.Sprintf(" (%s)", lang.L("wrong username/password")))
|
||||
fyne.Do(func() {
|
||||
dlg.SetErrorText(lang.L("Authentication failed") + fmt.Sprintf(" (%s)", lang.L("wrong username/password")))
|
||||
})
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user