summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-01-21 21:41:10 +0200
committerPaul Buetow <paul@buetow.org>2026-01-21 21:41:10 +0200
commit2bd22f79f739136a7d30cf156979e2f2b23b7c65 (patch)
tree3e7dcbde757076564c3e74acc3c0394d5775afb2 /internal
parent6c69ffa83c1a7f534217e5af643c8bd1b4d2078b (diff)
fix: detect and load bg-bg audio files in GUI
- Fix scanExistingWords() to detect cards with audio_front/audio_back files Previously only checked for audio.mp3, missing Bulgarian-Bulgarian cards - Fix checkForMissingFiles() to also look for bg-bg audio files Now checks both audio.mp3 (en-bg) and audio_front.mp3 (bg-bg) - Add check for back audio file in checkForMissingFiles() Ensures SetBackAudioFile is called when audio_back is loaded later This fixes the issue where opening an existing Bulgarian-Bulgarian card would not load the audio files, leaving the play buttons non-functional.
Diffstat (limited to 'internal')
-rw-r--r--internal/gui/navigation.go85
1 files changed, 79 insertions, 6 deletions
diff --git a/internal/gui/navigation.go b/internal/gui/navigation.go
index d7410f1..4b1f8bf 100644
--- a/internal/gui/navigation.go
+++ b/internal/gui/navigation.go
@@ -11,6 +11,7 @@ import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/dialog"
+ "codeberg.org/snonux/totalrecall/internal"
"codeberg.org/snonux/totalrecall/internal/anki"
)
@@ -93,11 +94,22 @@ func (a *Application) scanExistingWords() {
// Look for at least one of: audio, image, or translation file
hasContent := false
- // Check for audio file
+ // Check for audio file (both en-bg and bg-bg formats)
audioFile := filepath.Join(wordDir, fmt.Sprintf("audio.%s", a.config.AudioFormat))
if _, err := os.Stat(audioFile); err == nil {
hasContent = true
}
+
+ // Check for bg-bg audio files (audio_front and audio_back)
+ if !hasContent {
+ frontAudio := filepath.Join(wordDir, fmt.Sprintf("audio_front.%s", a.config.AudioFormat))
+ backAudio := filepath.Join(wordDir, fmt.Sprintf("audio_back.%s", a.config.AudioFormat))
+ if _, errFront := os.Stat(frontAudio); errFront == nil {
+ hasContent = true
+ } else if _, errBack := os.Stat(backAudio); errBack == nil {
+ hasContent = true
+ }
+ }
// Check for image files
if !hasContent {
@@ -398,12 +410,50 @@ func (a *Application) loadExistingFiles(word string) {
fmt.Printf("No phonetic file found at: %s (error: %v)\n", phoneticFile, err)
}
- // Load audio file
- audioFile := filepath.Join(wordDir, fmt.Sprintf("audio.%s", a.config.AudioFormat))
- if _, err := os.Stat(audioFile); err == nil {
- a.currentAudioFile = audioFile
+ // Load card type and audio files
+ cardType := internal.LoadCardType(wordDir)
+ a.currentCardType = string(cardType)
+
+ // Update UI card type selector
+ fyne.Do(func() {
+ if cardType.IsBgBg() {
+ a.cardTypeSelect.SetSelected("Bulgarian → Bulgarian")
+ } else {
+ a.cardTypeSelect.SetSelected("English → Bulgarian")
+ }
+ })
+
+ // Load audio file(s)
+ if cardType.IsBgBg() {
+ // For bg-bg cards, load both front and back audio
+ frontAudio := filepath.Join(wordDir, fmt.Sprintf("audio_front.%s", a.config.AudioFormat))
+ backAudio := filepath.Join(wordDir, fmt.Sprintf("audio_back.%s", a.config.AudioFormat))
+
+ if _, err := os.Stat(frontAudio); err == nil {
+ a.currentAudioFile = frontAudio
+ fyne.Do(func() {
+ a.audioPlayer.SetAudioFile(frontAudio)
+ })
+ }
+ if _, err := os.Stat(backAudio); err == nil {
+ a.currentAudioFileBack = backAudio
+ fyne.Do(func() {
+ a.audioPlayer.SetBackAudioFile(backAudio)
+ })
+ }
+ } else {
+ // For en-bg cards, load standard audio file
+ audioFile := filepath.Join(wordDir, fmt.Sprintf("audio.%s", a.config.AudioFormat))
+ if _, err := os.Stat(audioFile); err == nil {
+ a.currentAudioFile = audioFile
+ fyne.Do(func() {
+ a.audioPlayer.SetAudioFile(audioFile)
+ })
+ }
+ // Hide back audio button for en-bg cards
+ a.currentAudioFileBack = ""
fyne.Do(func() {
- a.audioPlayer.SetAudioFile(audioFile)
+ a.audioPlayer.SetBackAudioFile("")
})
}
@@ -497,6 +547,7 @@ func (a *Application) checkForMissingFiles(word string) {
// Check for missing audio file
if a.currentAudioFile == "" {
+ // First check for en-bg audio file
audioFile := filepath.Join(wordDir, fmt.Sprintf("audio.%s", a.config.AudioFormat))
if _, err := os.Stat(audioFile); err == nil {
a.currentAudioFile = audioFile
@@ -504,6 +555,28 @@ func (a *Application) checkForMissingFiles(word string) {
a.audioPlayer.SetAudioFile(audioFile)
a.updateStatus(fmt.Sprintf("Found audio file for %s", word))
})
+ } else {
+ // Check for bg-bg audio_front file
+ frontAudio := filepath.Join(wordDir, fmt.Sprintf("audio_front.%s", a.config.AudioFormat))
+ if _, err := os.Stat(frontAudio); err == nil {
+ a.currentAudioFile = frontAudio
+ fyne.Do(func() {
+ a.audioPlayer.SetAudioFile(frontAudio)
+ a.updateStatus(fmt.Sprintf("Found audio file for %s", word))
+ })
+ }
+ }
+ }
+
+ // Check for missing back audio file (bg-bg cards)
+ if a.currentAudioFileBack == "" {
+ backAudio := filepath.Join(wordDir, fmt.Sprintf("audio_back.%s", a.config.AudioFormat))
+ if _, err := os.Stat(backAudio); err == nil {
+ a.currentAudioFileBack = backAudio
+ fyne.Do(func() {
+ a.audioPlayer.SetBackAudioFile(backAudio)
+ a.updateStatus(fmt.Sprintf("Found back audio file for %s", word))
+ })
}
}