Add notification when a download is completed
- fyne notication looks for the app icon to display it in the notication, so I setted the icon in `main.go`. - deleting points after "Download" option in grid view that I mistakenly leave it in a previous PR. - adding the new paremeter `downloadName` Screenshot: Fixes #202
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/dweymouth/supersonic/backend"
|
||||
"github.com/dweymouth/supersonic/res"
|
||||
"github.com/dweymouth/supersonic/ui"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
@@ -28,6 +29,7 @@ func main() {
|
||||
}
|
||||
|
||||
fyneApp := app.New()
|
||||
fyneApp.SetIcon(res.ResAppicon256Png)
|
||||
|
||||
w := float32(myApp.Config.Application.WindowWidth)
|
||||
if w <= 1 {
|
||||
|
||||
@@ -202,7 +202,13 @@ func NewAlbumPageHeader(page *AlbumPage) *AlbumPageHeader {
|
||||
sharedutil.TracksToIDs(a.page.tracks))
|
||||
}),
|
||||
fyne.NewMenuItem("Download", func() {
|
||||
a.page.contr.ShowDownloadDialog(a.page.tracks)
|
||||
go func() {
|
||||
album, err := a.page.mp.GetAlbum(a.albumID)
|
||||
if err != nil {
|
||||
log.Print("Error while getting the album: ", album)
|
||||
}
|
||||
a.page.contr.ShowDownloadDialog(a.page.tracks, album.Name)
|
||||
}()
|
||||
}))
|
||||
pop = widget.NewPopUpMenu(menu, fyne.CurrentApp().Driver().CanvasForObject(a))
|
||||
}
|
||||
|
||||
@@ -262,7 +262,7 @@ func NewPlaylistPageHeader(page *PlaylistPage) *PlaylistPageHeader {
|
||||
sharedutil.TracksToIDs(a.page.tracks))
|
||||
}),
|
||||
fyne.NewMenuItem("Download", func() {
|
||||
a.page.contr.ShowDownloadDialog(a.page.tracks)
|
||||
a.page.contr.ShowDownloadDialog(a.page.tracks, a.playlistInfo.Name)
|
||||
}))
|
||||
pop = widget.NewPopUpMenu(menu, fyne.CurrentApp().Driver().CanvasForObject(a))
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ func (a *PlaylistsPage) createGridView(playlists []*mediaprovider.Playlist) {
|
||||
log.Printf("error loading playlist: %s", err.Error())
|
||||
return
|
||||
}
|
||||
a.contr.ShowDownloadDialog(pl.Tracks)
|
||||
a.contr.ShowDownloadDialog(pl.Tracks, pl.Name)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ func (m *Controller) ConnectAlbumGridActions(grid *widgets.GridView) {
|
||||
log.Printf("error loading album: %s", err.Error())
|
||||
return
|
||||
}
|
||||
m.ShowDownloadDialog(album.Tracks)
|
||||
m.ShowDownloadDialog(album.Tracks, album.Name)
|
||||
}()
|
||||
}
|
||||
}
|
||||
@@ -168,7 +168,12 @@ func (m *Controller) ConnectArtistGridActions(grid *widgets.GridView) {
|
||||
grid.OnDownload = func(artistID string) {
|
||||
go func() {
|
||||
tracks := m.GetArtistTracks(artistID)
|
||||
m.ShowDownloadDialog(tracks)
|
||||
artist, err := m.App.ServerManager.Server.GetArtist(artistID)
|
||||
if err != nil {
|
||||
log.Printf("error getting artist: %v", err.Error())
|
||||
return
|
||||
}
|
||||
m.ShowDownloadDialog(tracks, artist.Name)
|
||||
}()
|
||||
}
|
||||
}
|
||||
@@ -538,7 +543,7 @@ func (c *Controller) SetTrackRatings(trackIDs []string, rating int) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Controller) ShowDownloadDialog(tracks []*mediaprovider.Track) {
|
||||
func (c *Controller) ShowDownloadDialog(tracks []*mediaprovider.Track, downloadName string) {
|
||||
numTracks := len(tracks)
|
||||
var fileName string
|
||||
if numTracks == 1 {
|
||||
@@ -560,7 +565,7 @@ func (c *Controller) ShowDownloadDialog(tracks []*mediaprovider.Track) {
|
||||
if numTracks == 1 {
|
||||
go c.downloadTrack(tracks[0], file.URI().Path())
|
||||
} else {
|
||||
go c.downloadTracks(tracks, file.URI().Path())
|
||||
go c.downloadTracks(tracks, file.URI().Path(), downloadName)
|
||||
}
|
||||
|
||||
},
|
||||
@@ -590,9 +595,10 @@ func (c *Controller) downloadTrack(track *mediaprovider.Track, filePath string)
|
||||
}
|
||||
|
||||
log.Printf("Saved song %s to: %s\n", track.Name, filePath)
|
||||
c.sendNotification(fmt.Sprintf("Download completed: %s", track.Name), fmt.Sprintf("Saved at: %s", filePath))
|
||||
}
|
||||
|
||||
func (c *Controller) downloadTracks(tracks []*mediaprovider.Track, filePath string) {
|
||||
func (c *Controller) downloadTracks(tracks []*mediaprovider.Track, filePath, downloadName string) {
|
||||
zipFile, err := os.Create(filePath)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
@@ -627,5 +633,12 @@ func (c *Controller) downloadTracks(tracks []*mediaprovider.Track, filePath stri
|
||||
log.Printf("Saved song %s to: %s\n", track.Name, filePath)
|
||||
}
|
||||
|
||||
log.Printf("Finished download to: %s\n", filePath)
|
||||
c.sendNotification(fmt.Sprintf("Download completed: %s", downloadName), fmt.Sprintf("Saved at: %s", filePath))
|
||||
}
|
||||
|
||||
func (c *Controller) sendNotification(title, content string) {
|
||||
fyne.CurrentApp().SendNotification(&fyne.Notification{
|
||||
Title: title,
|
||||
Content: content,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ func (g *GridViewItem) showContextMenu(pos fyne.Position) {
|
||||
fyne.NewMenuItem("Shuffle", func() { g.onPlay(true) }),
|
||||
fyne.NewMenuItem("Add to queue", g.onAddToQueue),
|
||||
fyne.NewMenuItem("Add to playlist...", g.onAddToPlaylist),
|
||||
fyne.NewMenuItem("Download...", g.onDownload)),
|
||||
fyne.NewMenuItem("Download", g.onDownload)),
|
||||
fyne.CurrentApp().Driver().CanvasForObject(g))
|
||||
}
|
||||
g.menu.ShowAtPosition(pos)
|
||||
|
||||
@@ -76,7 +76,7 @@ type Tracklist struct {
|
||||
OnAddToPlaylist func(trackIDs []string)
|
||||
OnSetFavorite func(trackIDs []string, fav bool)
|
||||
OnSetRating func(trackIDs []string, rating int)
|
||||
OnDownload func(tracks []*mediaprovider.Track)
|
||||
OnDownload func(tracks []*mediaprovider.Track, downloadName string)
|
||||
|
||||
OnShowArtistPage func(artistID string)
|
||||
OnShowAlbumPage func(albumID string)
|
||||
@@ -511,7 +511,7 @@ func (t *Tracklist) onShowContextMenu(e *fyne.PointEvent, trackIdx int) {
|
||||
}))
|
||||
t.ctxMenu.Items = append(t.ctxMenu.Items,
|
||||
fyne.NewMenuItem("Download", func() {
|
||||
t.onDownload(t.selectedTracks())
|
||||
t.onDownload(t.selectedTracks(), "Selected tracks")
|
||||
}))
|
||||
t.ctxMenu.Items = append(t.ctxMenu.Items, fyne.NewMenuItemSeparator())
|
||||
t.ctxMenu.Items = append(t.ctxMenu.Items,
|
||||
@@ -587,9 +587,9 @@ func (t *Tracklist) onAlbumTapped(albumID string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Tracklist) onDownload(tracks []*mediaprovider.Track) {
|
||||
func (t *Tracklist) onDownload(tracks []*mediaprovider.Track, downloadName string) {
|
||||
if t.OnDownload != nil {
|
||||
t.OnDownload(tracks)
|
||||
t.OnDownload(tracks, downloadName)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user