feat: Add Share option for artists, albums, and tracks
This feature is only available on the Subsonic media provider. Using a Jellyfin server will make Supersonic hide the "Share" option. * Artists: Option available in grid view and in Artist view. * Albums: Option available in grid view and in Album view. * Tracks: Option available in tracklist, when a single track is selected.
This commit is contained in:
@@ -22,8 +22,10 @@ import (
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/dialog"
|
||||
"fyne.io/fyne/v2/layout"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
@@ -138,6 +140,13 @@ func (m *Controller) connectTracklistActionsWithReplayGainMode(tracklist *widget
|
||||
m.ClosePopUpOnEscape(pop)
|
||||
}
|
||||
tracklist.OnDownload = m.ShowDownloadDialog
|
||||
|
||||
_, canShare := m.App.ServerManager.Server.(mediaprovider.SupportsSharing)
|
||||
if canShare {
|
||||
tracklist.OnShare = func(trackID string) {
|
||||
go m.CreateShareURL(trackID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Controller) ConnectAlbumGridActions(grid *widgets.GridView) {
|
||||
@@ -173,6 +182,13 @@ func (m *Controller) ConnectAlbumGridActions(grid *widgets.GridView) {
|
||||
m.ShowDownloadDialog(album.Tracks, album.Name)
|
||||
}()
|
||||
}
|
||||
|
||||
_, canShare := m.App.ServerManager.Server.(mediaprovider.SupportsSharing)
|
||||
if canShare {
|
||||
grid.OnShare = func(albumID string) {
|
||||
go m.CreateShareURL(albumID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Controller) ConnectArtistGridActions(grid *widgets.GridView) {
|
||||
@@ -662,6 +678,44 @@ func (c *Controller) SetTrackRatings(trackIDs []string, rating int) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Controller) CreateShareURL(id string) {
|
||||
go func() {
|
||||
r, ok := c.App.ServerManager.Server.(mediaprovider.SupportsSharing)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
shareUrl, err := r.CreateShareURL(id)
|
||||
if err != nil {
|
||||
log.Printf("error creating share URL: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
hyperlink := widget.NewHyperlink(shareUrl.String(), shareUrl)
|
||||
dlg := dialog.NewCustom("Share content", "OK",
|
||||
container.NewHBox(
|
||||
hyperlink,
|
||||
widget.NewButtonWithIcon("", theme.ContentCopyIcon(), func() {
|
||||
c.MainWindow.Clipboard().SetContent(hyperlink.Text)
|
||||
}),
|
||||
widget.NewButtonWithIcon("", theme.ViewRefreshIcon(), func() {
|
||||
shareUrl, err := r.CreateShareURL(id)
|
||||
if err != nil {
|
||||
log.Printf("error creating share URL: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
hyperlink.Text = shareUrl.String()
|
||||
hyperlink.URL = shareUrl
|
||||
hyperlink.Refresh()
|
||||
}),
|
||||
),
|
||||
c.MainWindow,
|
||||
)
|
||||
dlg.Show()
|
||||
}()
|
||||
}
|
||||
|
||||
func (c *Controller) ShowDownloadDialog(tracks []*mediaprovider.Track, downloadName string) {
|
||||
numTracks := len(tracks)
|
||||
var fileName string
|
||||
|
||||
Reference in New Issue
Block a user