use error toast to inform user
This commit is contained in:
@@ -330,7 +330,8 @@ func (c *Controller) ShowSettingsDialog(themeUpdateCallbk func(), themeFiles map
|
|||||||
c.App.EQPresetManager,
|
c.App.EQPresetManager,
|
||||||
c.MainWindow,
|
c.MainWindow,
|
||||||
c.App.AutoEQManager,
|
c.App.AutoEQManager,
|
||||||
c.App.ImageManager)
|
c.App.ImageManager,
|
||||||
|
c.ToastProvider)
|
||||||
dlg.OnReplayGainSettingsChanged = func() {
|
dlg.OnReplayGainSettingsChanged = func() {
|
||||||
c.App.PlaybackManager.SetReplayGainOptions(c.App.Config.ReplayGain)
|
c.App.PlaybackManager.SetReplayGainOptions(c.App.Config.ReplayGain)
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-41
@@ -20,13 +20,15 @@ import (
|
|||||||
type AutoEQBrowser struct {
|
type AutoEQBrowser struct {
|
||||||
SearchDialog *SearchDialog
|
SearchDialog *SearchDialog
|
||||||
manager *backend.AutoEQManager
|
manager *backend.AutoEQManager
|
||||||
|
toastProvider ToastProvider
|
||||||
allProfileResults []*mediaprovider.SearchResult
|
allProfileResults []*mediaprovider.SearchResult
|
||||||
OnProfileSelected func(*backend.AutoEQProfile)
|
OnProfileSelected func(*backend.AutoEQProfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAutoEQBrowser(manager *backend.AutoEQManager, im util.ImageFetcher) *AutoEQBrowser {
|
func NewAutoEQBrowser(manager *backend.AutoEQManager, im util.ImageFetcher, toastProvider ToastProvider) *AutoEQBrowser {
|
||||||
ab := &AutoEQBrowser{
|
ab := &AutoEQBrowser{
|
||||||
manager: manager,
|
manager: manager,
|
||||||
|
toastProvider: toastProvider,
|
||||||
}
|
}
|
||||||
sd := NewSearchDialog(
|
sd := NewSearchDialog(
|
||||||
im,
|
im,
|
||||||
@@ -43,7 +45,6 @@ func (ab *AutoEQBrowser) fetchAllProfiles() error {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
profiles, err := ab.manager.FetchIndex(ctx)
|
profiles, err := ab.manager.FetchIndex(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error fetching AutoEQ index: %v", err)
|
|
||||||
// Show empty results on error
|
// Show empty results on error
|
||||||
ab.allProfileResults = []*mediaprovider.SearchResult{}
|
ab.allProfileResults = []*mediaprovider.SearchResult{}
|
||||||
return fmt.Errorf("failed to fetch AutoEQ index: %w", err)
|
return fmt.Errorf("failed to fetch AutoEQ index: %w", err)
|
||||||
@@ -83,14 +84,10 @@ func (ab *AutoEQBrowser) onSearched(query string) []*mediaprovider.SearchResult
|
|||||||
if ab.allProfileResults == nil {
|
if ab.allProfileResults == nil {
|
||||||
if err := ab.fetchAllProfiles(); err != nil {
|
if err := ab.fetchAllProfiles(); err != nil {
|
||||||
log.Printf("Failed to load AutoEQ profiles: %v", err)
|
log.Printf("Failed to load AutoEQ profiles: %v", err)
|
||||||
// Return a single error result
|
fyne.Do(func() {
|
||||||
return []*mediaprovider.SearchResult{
|
ab.toastProvider.ShowErrorToast(lang.L("Error loading AutoEQ profiles"))
|
||||||
{
|
})
|
||||||
Name: lang.L("Error loading AutoEQ profiles"),
|
return []*mediaprovider.SearchResult{}
|
||||||
ArtistName: lang.L("Check network connection and try again"),
|
|
||||||
Type: mediaprovider.ContentTypePlaylist,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,18 +111,20 @@ func (ab *AutoEQBrowser) SetOnDismiss(onDismiss func()) {
|
|||||||
func (ab *AutoEQBrowser) SetOnProfileSelected(callback func(*backend.AutoEQProfile)) {
|
func (ab *AutoEQBrowser) SetOnProfileSelected(callback func(*backend.AutoEQProfile)) {
|
||||||
ab.OnProfileSelected = callback
|
ab.OnProfileSelected = callback
|
||||||
ab.SearchDialog.OnNavigateTo = func(_ mediaprovider.ContentType, profilePath string) {
|
ab.SearchDialog.OnNavigateTo = func(_ mediaprovider.ContentType, profilePath string) {
|
||||||
// Fetch the full profile data
|
go func() {
|
||||||
ctx := context.Background()
|
// Fetch the full profile data
|
||||||
profile, err := ab.manager.FetchProfile(ctx, profilePath)
|
profile, err := ab.manager.FetchProfile(context.Background(), profilePath)
|
||||||
if err != nil {
|
fyne.Do(func() {
|
||||||
log.Printf("Error fetching AutoEQ profile: %v", err)
|
if err != nil {
|
||||||
// TODO: Show error dialog to user
|
log.Printf("Error loading AutoEQ profile: %v", err)
|
||||||
return
|
ab.toastProvider.ShowErrorToast(lang.L("Error loading AutoEQ profile"))
|
||||||
}
|
} else {
|
||||||
|
if ab.OnProfileSelected != nil {
|
||||||
if ab.OnProfileSelected != nil {
|
ab.OnProfileSelected(profile)
|
||||||
ab.OnProfileSelected(profile)
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,21 +147,3 @@ func (ab *AutoEQBrowser) Hide() {
|
|||||||
func (ab *AutoEQBrowser) Refresh() {
|
func (ab *AutoEQBrowser) Refresh() {
|
||||||
ab.SearchDialog.Refresh()
|
ab.SearchDialog.Refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShowErrorDialog displays an error message to the user
|
|
||||||
func ShowAutoEQError(window fyne.Window, err error) {
|
|
||||||
title := lang.L("Error")
|
|
||||||
message := lang.L("Failed to load profile")
|
|
||||||
|
|
||||||
if err == backend.ErrProfileNotFound {
|
|
||||||
message = lang.L("Profile not found")
|
|
||||||
} else if strings.Contains(err.Error(), "context deadline exceeded") ||
|
|
||||||
strings.Contains(err.Error(), "connection") {
|
|
||||||
message = lang.L("Network error. Check connection.")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use a simple dialog (would need to import "fyne.io/fyne/v2/dialog")
|
|
||||||
// For now just log it
|
|
||||||
log.Printf("AutoEQ Error: %s - %v", message, err)
|
|
||||||
fmt.Printf("%s: %s\n", title, message)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -50,12 +50,18 @@ type SettingsDialog struct {
|
|||||||
autoEQManager *backend.AutoEQManager
|
autoEQManager *backend.AutoEQManager
|
||||||
imageManager util.ImageFetcher
|
imageManager util.ImageFetcher
|
||||||
window fyne.Window
|
window fyne.Window
|
||||||
|
toastProvider ToastProvider
|
||||||
|
|
||||||
clientDecidesScrobble bool
|
clientDecidesScrobble bool
|
||||||
|
|
||||||
content fyne.CanvasObject
|
content fyne.CanvasObject
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ToastProvider interface {
|
||||||
|
ShowSuccessToast(message string)
|
||||||
|
ShowErrorToast(message string)
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: having this depend on the mpv package for the AudioDevice type is kinda gross. Refactor.
|
// TODO: having this depend on the mpv package for the AudioDevice type is kinda gross. Refactor.
|
||||||
func NewSettingsDialog(
|
func NewSettingsDialog(
|
||||||
config *backend.Config,
|
config *backend.Config,
|
||||||
@@ -71,6 +77,7 @@ func NewSettingsDialog(
|
|||||||
window fyne.Window,
|
window fyne.Window,
|
||||||
autoEQManager *backend.AutoEQManager,
|
autoEQManager *backend.AutoEQManager,
|
||||||
imageManager util.ImageFetcher,
|
imageManager util.ImageFetcher,
|
||||||
|
toastProvider ToastProvider,
|
||||||
) *SettingsDialog {
|
) *SettingsDialog {
|
||||||
s := &SettingsDialog{
|
s := &SettingsDialog{
|
||||||
config: config,
|
config: config,
|
||||||
@@ -81,6 +88,7 @@ func NewSettingsDialog(
|
|||||||
autoEQManager: autoEQManager,
|
autoEQManager: autoEQManager,
|
||||||
imageManager: imageManager,
|
imageManager: imageManager,
|
||||||
window: window,
|
window: window,
|
||||||
|
toastProvider: toastProvider,
|
||||||
}
|
}
|
||||||
s.ExtendBaseWidget(s)
|
s.ExtendBaseWidget(s)
|
||||||
|
|
||||||
@@ -587,7 +595,7 @@ func (s *SettingsDialog) openAutoEQBrowser(geq *GraphicEqualizer, debouncer func
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
browser := NewAutoEQBrowser(s.autoEQManager, s.imageManager)
|
browser := NewAutoEQBrowser(s.autoEQManager, s.imageManager, s.toastProvider)
|
||||||
|
|
||||||
// Show in a modal popup dialog
|
// Show in a modal popup dialog
|
||||||
var popup *widget.PopUp
|
var popup *widget.PopUp
|
||||||
|
|||||||
Reference in New Issue
Block a user