misc: Notify user of failed sharing using a dialog
This commit is contained in:
@@ -253,7 +253,7 @@ func NewAlbumPageHeader(page *AlbumPage) *AlbumPageHeader {
|
|||||||
_, canShare := page.mp.(mediaprovider.SupportsSharing)
|
_, canShare := page.mp.(mediaprovider.SupportsSharing)
|
||||||
if canShare {
|
if canShare {
|
||||||
share := fyne.NewMenuItem("Share...", func() {
|
share := fyne.NewMenuItem("Share...", func() {
|
||||||
a.page.contr.CreateShareURL(a.albumID)
|
a.page.contr.ShowShareDialog(a.albumID)
|
||||||
})
|
})
|
||||||
share.Icon = myTheme.ShareIcon
|
share.Icon = myTheme.ShareIcon
|
||||||
menuItems = append(menuItems, share)
|
menuItems = append(menuItems, share)
|
||||||
|
|||||||
@@ -329,7 +329,7 @@ func NewArtistPageHeader(page *ArtistPage) *ArtistPageHeader {
|
|||||||
a.menuBtn.OnTapped = func() {
|
a.menuBtn.OnTapped = func() {
|
||||||
if pop == nil {
|
if pop == nil {
|
||||||
share := fyne.NewMenuItem("Share...", func() {
|
share := fyne.NewMenuItem("Share...", func() {
|
||||||
a.artistPage.contr.CreateShareURL(a.artistID)
|
a.artistPage.contr.ShowShareDialog(a.artistID)
|
||||||
})
|
})
|
||||||
share.Icon = myTheme.ShareIcon
|
share.Icon = myTheme.ShareIcon
|
||||||
menu := fyne.NewMenu("", share)
|
menu := fyne.NewMenu("", share)
|
||||||
|
|||||||
+30
-16
@@ -7,6 +7,7 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
@@ -144,7 +145,7 @@ func (m *Controller) connectTracklistActionsWithReplayGainMode(tracklist *widget
|
|||||||
_, canShare := m.App.ServerManager.Server.(mediaprovider.SupportsSharing)
|
_, canShare := m.App.ServerManager.Server.(mediaprovider.SupportsSharing)
|
||||||
if canShare {
|
if canShare {
|
||||||
tracklist.OnShare = func(trackID string) {
|
tracklist.OnShare = func(trackID string) {
|
||||||
go m.CreateShareURL(trackID)
|
go m.ShowShareDialog(trackID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -186,7 +187,7 @@ func (m *Controller) ConnectAlbumGridActions(grid *widgets.GridView) {
|
|||||||
_, canShare := m.App.ServerManager.Server.(mediaprovider.SupportsSharing)
|
_, canShare := m.App.ServerManager.Server.(mediaprovider.SupportsSharing)
|
||||||
if canShare {
|
if canShare {
|
||||||
grid.OnShare = func(albumID string) {
|
grid.OnShare = func(albumID string) {
|
||||||
go m.CreateShareURL(albumID)
|
go m.ShowShareDialog(albumID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -678,16 +679,10 @@ func (c *Controller) SetTrackRatings(trackIDs []string, rating int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) CreateShareURL(id string) {
|
func (c *Controller) ShowShareDialog(id string) {
|
||||||
go func() {
|
go func() {
|
||||||
r, ok := c.App.ServerManager.Server.(mediaprovider.SupportsSharing)
|
shareUrl, err := c.createShareURL(id)
|
||||||
if !ok {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
shareUrl, err := r.CreateShareURL(id)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error creating share URL: %v", err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -699,15 +694,11 @@ func (c *Controller) CreateShareURL(id string) {
|
|||||||
c.MainWindow.Clipboard().SetContent(hyperlink.Text)
|
c.MainWindow.Clipboard().SetContent(hyperlink.Text)
|
||||||
}),
|
}),
|
||||||
widget.NewButtonWithIcon("", theme.ViewRefreshIcon(), func() {
|
widget.NewButtonWithIcon("", theme.ViewRefreshIcon(), func() {
|
||||||
shareUrl, err := r.CreateShareURL(id)
|
if shareUrl, err := c.createShareURL(id); err == nil {
|
||||||
if err != nil {
|
|
||||||
log.Printf("error creating share URL: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
hyperlink.Text = shareUrl.String()
|
hyperlink.Text = shareUrl.String()
|
||||||
hyperlink.URL = shareUrl
|
hyperlink.URL = shareUrl
|
||||||
hyperlink.Refresh()
|
hyperlink.Refresh()
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
c.MainWindow,
|
c.MainWindow,
|
||||||
@@ -716,6 +707,24 @@ func (c *Controller) CreateShareURL(id string) {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Controller) createShareURL(id string) (*url.URL, error) {
|
||||||
|
r, ok := c.App.ServerManager.Server.(mediaprovider.SupportsSharing)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("server does not support sharing")
|
||||||
|
}
|
||||||
|
|
||||||
|
shareUrl, err := r.CreateShareURL(id)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("error creating share URL: %v", err)
|
||||||
|
c.showError(
|
||||||
|
"Failed to share content. This commonly occurs when the server does not support sharing," +
|
||||||
|
"or has the feature disabled.\nPlease check the server's settings and try again.",
|
||||||
|
)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return shareUrl, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Controller) ShowDownloadDialog(tracks []*mediaprovider.Track, downloadName string) {
|
func (c *Controller) ShowDownloadDialog(tracks []*mediaprovider.Track, downloadName string) {
|
||||||
numTracks := len(tracks)
|
numTracks := len(tracks)
|
||||||
var fileName string
|
var fileName string
|
||||||
@@ -816,6 +825,11 @@ func (c *Controller) sendNotification(title, content string) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Controller) showError(content string) {
|
||||||
|
// TODO: display an in-app toast message instead of a dialog.
|
||||||
|
dialog.ShowError(fmt.Errorf(content), c.MainWindow)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Controller) ShowAlbumInfoDialog(albumID, albumName string, albumCover image.Image) {
|
func (c *Controller) ShowAlbumInfoDialog(albumID, albumName string, albumCover image.Image) {
|
||||||
go func() {
|
go func() {
|
||||||
albumInfo, err := c.App.ServerManager.Server.GetAlbumInfo(albumID)
|
albumInfo, err := c.App.ServerManager.Server.GetAlbumInfo(albumID)
|
||||||
|
|||||||
Reference in New Issue
Block a user