Skip to content

Commit

Permalink
Merge pull request #524 from dweymouth/feature/toasts
Browse files Browse the repository at this point in the history
Show success/error "toast" message when adding tracks to playlists
  • Loading branch information
dweymouth authored Jan 6, 2025
2 parents 9390f7b + 7c657ac commit f1621fe
Show file tree
Hide file tree
Showing 14 changed files with 395 additions and 18 deletions.
7 changes: 6 additions & 1 deletion res/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,5 +239,10 @@
"Sept": "Sept",
"Oct": "Okt",
"Nov": "Nov",
"Dec": "Dec"
"Dec": "Dec",

"playlist.addedtracks": {
"one": "Added {{.trackCount}} track to playlist",
"other": "Added {{.trackCount}} tracks to playlist"
}
}
10 changes: 9 additions & 1 deletion res/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"All": "All",
"All Tracks": "All Tracks",
"Alt. URL": "Alt. URL",
"An error occurred adding tracks to the playlist": "An error occurred adding tracks to the playlist",
"Are you sure you want to delete the server": "Are you sure you want to delete the server",
"Artist": "Artist",
"Artist (A-Z)": "Artist (A-Z)",
Expand Down Expand Up @@ -69,6 +70,7 @@
"Enter": "Enter",
"EP": "EP",
"Equalizer": "Equalizer",
"Error": "Error",
"Exclusive mode": "Exclusive mode",
"Favorites": "Favorites",
"Field Recording": "Field Recording",
Expand Down Expand Up @@ -188,6 +190,7 @@
"Spoken Word": "Spoken Word",
"Startup page": "Startup page",
"Stopped": "Stopped",
"Success": "Success",
"Support the project": "Support the project",
"Switch Servers": "Switch Servers",
"Testing connection": "Testing connection",
Expand Down Expand Up @@ -242,5 +245,10 @@
"Sept": "Sept",
"Oct": "Oct",
"Nov": "Nov",
"Dec": "Dec"
"Dec": "Dec",

"playlist.addedtracks": {
"one": "Added one track to playlist",
"other": "Added {{.trackCount}} tracks to playlist"
}
}
10 changes: 9 additions & 1 deletion res/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"All": "Todos",
"All Tracks": "Todas las pistas",
"Alt. URL": "URL alternativa",
"An error occurred adding tracks to the playlist": "Ha ocurrido un error al añadir pistas a la lista de reproducción",
"Are you sure you want to delete the server": "¿Estás seguro de que quieres eliminar el servidor?",
"Artist": "Artista",
"Artist (A-Z)": "Artista (A-Z)",
Expand Down Expand Up @@ -69,6 +70,7 @@
"Enter": "Ingresar",
"EP": "EP",
"Equalizer": "Ecualizador",
"Error": "Error",
"Exclusive mode": "Modo exclusivo",
"Favorites": "Favoritos",
"Field Recording": "Grabación en campo",
Expand Down Expand Up @@ -187,6 +189,7 @@
"Spoken Word": "Palabra Hablada",
"Startup page": "Página de inicio",
"Stopped": "Detenida",
"Success": "Éxito",
"Support the project": "Apoya el proyecto",
"Switch Servers": "Cambiar servidores",
"Testing connection": "Probando conexión",
Expand Down Expand Up @@ -241,5 +244,10 @@
"Sept": "Set",
"Oct": "Oct",
"Nov": "Nov",
"Dec": "Dic"
"Dec": "Dic",

"playlist.addedtracks": {
"one": "Se ha añadido una pista a la lista de reproducción",
"other": "Se han añadido {{.trackCount}} pistas a la lista de reproducción"
}
}
7 changes: 6 additions & 1 deletion res/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,5 +240,10 @@
"Sept": "Sept",
"Oct": "Oct",
"Nov": "Nov",
"Dec": "Déc"
"Dec": "Déc",

"playlist.addedtracks": {
"one": "Une piste ajoutée à la liste de lecture",
"other": "{{.trackCount}} pistes ajoutées à la liste de lecture"
}
}
7 changes: 6 additions & 1 deletion res/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -238,5 +238,10 @@
"Sept": "Set",
"Oct": "Ott",
"Nov": "Nov",
"Dec": "Dic"
"Dec": "Dic",

"playlist.addedtracks": {
"one": "Added {{.trackCount}} track to playlist",
"other": "Added {{.trackCount}} tracks to playlist"
}
}
7 changes: 6 additions & 1 deletion res/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,10 @@
"Remove from queue": "キューから削除",
"Play song radio": "曲をラジオで再生",
"to":"to",
"by":"by"
"by":"by",

"playlist.addedtracks": {
"one": "Added {{.trackCount}} track to playlist",
"other": "Added {{.trackCount}} tracks to playlist"
}
}
7 changes: 6 additions & 1 deletion res/translations/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,10 @@
"Remove from queue": "Usuń z kolejki odtwarzania",
"Play song radio": "Odtwórz mix utworów",
"to":"do",
"by":"przez"
"by":"przez",

"playlist.addedtracks": {
"one": "Added {{.trackCount}} track to playlist",
"other": "Added {{.trackCount}} tracks to playlist"
}
}
7 changes: 6 additions & 1 deletion res/translations/pt_BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,10 @@
"Remove from queue": "Remover da fila",
"Play song radio": "Reproduzir rádio da faixa",
"to":"a",
"by":"de"
"by":"de",

"playlist.addedtracks": {
"one": "Added {{.trackCount}} track to playlist",
"other": "Added {{.trackCount}} tracks to playlist"
}
}
7 changes: 6 additions & 1 deletion res/translations/ro.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,10 @@
"Sept": "Sept",
"Oct": "Oct",
"Nov": "Noiem",
"Dec": "Dec"
"Dec": "Dec",

"playlist.addedtracks": {
"one": "Added {{.trackCount}} track to playlist",
"other": "Added {{.trackCount}} tracks to playlist"
}
}
7 changes: 6 additions & 1 deletion res/translations/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,10 @@
"Unset favorite": "取消收藏",
"Remove from queue": "从队列中移除",
"Size": "大小",
"Play song radio": "播放歌曲电台"
"Play song radio": "播放歌曲电台",

"playlist.addedtracks": {
"one": "Added {{.trackCount}} track to playlist",
"other": "Added {{.trackCount}} tracks to playlist"
}
}
7 changes: 6 additions & 1 deletion res/translations/zhHans.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,10 @@
"Unset favorite": "取消收藏",
"Remove from queue": "从队列中移除",
"Size": "大小",
"Play song radio": "播放歌曲电台"
"Play song radio": "播放歌曲电台",

"playlist.addedtracks": {
"one": "Added {{.trackCount}} track to playlist",
"other": "Added {{.trackCount}} tracks to playlist"
}
}
54 changes: 48 additions & 6 deletions ui/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/url"
"os"
"path/filepath"
"strconv"
"sync"
"time"

Expand Down Expand Up @@ -39,17 +40,25 @@ type NavigationHandler func(Route)

type CurPageFunc func() Route

type ToastProvider interface {
ShowSuccessToast(string)
ShowErrorToast(string)
}

type Controller struct {
visualizationData
AppVersion string
App *backend.App
MainWindow fyne.Window
AppVersion string
App *backend.App
MainWindow fyne.Window

// dependencies injected from MainWindow
NavHandler NavigationHandler
CurPageFunc CurPageFunc
ReloadFunc func()
RefreshPageFunc func()
SelectAllPageFunc func()
UnselectAllPageFunc func()
ToastProvider ToastProvider

popUpQueueMutex sync.Mutex
popUpQueue *widget.PopUp
Expand Down Expand Up @@ -297,17 +306,36 @@ func (m *Controller) DoAddTracksToPlaylistWorkflow(trackIDs []string) {
m.doModalClosed()
})
sp.SetOnNavigateTo(func(contentType mediaprovider.ContentType, id string) {
notifySuccess := func(n int) {
msg := lang.LocalizePluralKey("playlist.addedtracks",
"Added tracks to playlist", n, map[string]string{"trackCount": strconv.Itoa(n)})
m.ToastProvider.ShowSuccessToast(msg)
}
notifyError := func() {
m.ToastProvider.ShowErrorToast(
lang.L("An error occurred adding tracks to the playlist"),
)
}
pop.Hide()
m.App.Config.Application.AddToPlaylistSkipDuplicates = sp.SkipDuplicates
if id == "" /* creating new playlist */ {
go m.App.ServerManager.Server.CreatePlaylist(sp.SearchDialog.SearchQuery(), trackIDs)
go func() {
err := m.App.ServerManager.Server.CreatePlaylist(sp.SearchDialog.SearchQuery(), trackIDs)
if err == nil {
notifySuccess(len(trackIDs))
} else {
log.Println("error adding tracks to playlist: %s", err.Error())
notifyError()
}
}()
} else {
m.App.Config.Application.DefaultPlaylistID = id
if sp.SkipDuplicates {
go func() {
currentTrackIDs := make(map[string]struct{})
if selectedPlaylist, err := m.App.ServerManager.Server.GetPlaylist(id); err != nil {
log.Printf("error getting playlist: %s", err.Error())
notifyError()
} else {
for _, track := range selectedPlaylist.Tracks {
currentTrackIDs[track.ID] = struct{}{}
Expand All @@ -316,11 +344,25 @@ func (m *Controller) DoAddTracksToPlaylistWorkflow(trackIDs []string) {
_, ok := currentTrackIDs[trackID]
return !ok
})
m.App.ServerManager.Server.AddPlaylistTracks(id, filterTrackIDs)
err := m.App.ServerManager.Server.AddPlaylistTracks(id, filterTrackIDs)
if err == nil {
notifySuccess(len(filterTrackIDs))
} else {
log.Println("error adding tracks to playlist: %s", err.Error())
notifyError()
}
}
}()
} else {
go m.App.ServerManager.Server.AddPlaylistTracks(id, trackIDs)
go func() {
err := m.App.ServerManager.Server.AddPlaylistTracks(id, trackIDs)
if err == nil {
notifySuccess(len(trackIDs))
} else {
log.Println("error adding tracks to playlist: %s", err.Error())
notifyError()
}
}()
}
}

Expand Down
7 changes: 6 additions & 1 deletion ui/mainwindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type MainWindow struct {
Controller *controller.Controller
BrowsingPane *browsing.BrowsingPane
BottomPanel *BottomPanel
ToastOverlay *ToastOverlay

theme *theme.MyTheme
haveSystemTray bool
Expand Down Expand Up @@ -61,6 +62,7 @@ func NewMainWindow(fyneApp fyne.App, appName, displayAppName, appVersion string,
}
m.Controller = controller.New(app, appVersion, m.Window)
m.BrowsingPane = browsing.NewBrowsingPane(app, m.Controller, func() { m.Router.NavigateTo(m.StartupPage()) })
m.ToastOverlay = NewToastOverlay()
m.Router = browsing.NewRouter(app, m.Controller, m.BrowsingPane)
// inject controller dependencies
m.Controller.NavHandler = m.Router.NavigateTo
Expand All @@ -69,6 +71,7 @@ func NewMainWindow(fyneApp fyne.App, appName, displayAppName, appVersion string,
m.Controller.RefreshPageFunc = m.BrowsingPane.RefreshPage
m.Controller.SelectAllPageFunc = m.BrowsingPane.SelectAll
m.Controller.UnselectAllPageFunc = m.BrowsingPane.UnselectAll
m.Controller.ToastProvider = m.ToastOverlay

if runtime.GOOS == "darwin" {
// Fyne will extract out an "About" menu item and
Expand Down Expand Up @@ -137,10 +140,12 @@ func NewMainWindow(fyneApp fyne.App, appName, displayAppName, appVersion string,
m.BrowsingPane.DisableNavigationButtons()
m.addShortcuts()

m.content = newMainWindowContent(container.NewBorder(nil, m.BottomPanel, nil, nil, m.BrowsingPane),
center := container.NewStack(m.BrowsingPane, m.ToastOverlay)
m.content = newMainWindowContent(container.NewBorder(nil, m.BottomPanel, nil, nil, center),
m.Controller.UnselectAll)
m.Window.SetContent(fynetooltip.AddWindowToolTipLayer(m.content, m.Window.Canvas()))
m.setInitialSize()

m.Window.SetCloseIntercept(func() {
m.SaveWindowSize()
// save settings in case we crash during shutdown
Expand Down
Loading

0 comments on commit f1621fe

Please sign in to comment.