From 18a475657cbc7b2ff8ee537b082eeef25e9bf619 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 22 Jul 2025 16:03:13 +0300 Subject: Fix race conditions in background processing and prevent deletion of active cards MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix race condition where images, audio, and phonetic info could be saved to wrong flashcard when navigating quickly between cards - Add pre-determined card directory that's passed to all background operations - Track active operations per word to prevent deletion during generation - Block deletion of cards that are queued or being processed - Show appropriate error messages when deletion is blocked This ensures files are always saved to the correct card directory and prevents data loss from deleting cards with active operations. 🤖 Generated with [opencode](https://opencode.ai) Co-Authored-By: opencode --- internal/gui/navigation.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'internal/gui/navigation.go') diff --git a/internal/gui/navigation.go b/internal/gui/navigation.go index c91a57a..d7410f1 100644 --- a/internal/gui/navigation.go +++ b/internal/gui/navigation.go @@ -580,6 +580,18 @@ func (a *Application) onDelete() { return } + // Check if this word has active operations + if a.hasActiveOperations(a.currentWord) { + dialog.ShowError(fmt.Errorf("Cannot delete '%s' while content is being generated.\nPlease wait for generation to complete.", a.currentWord), a.window) + return + } + + // Also check if word is in the processing queue + if a.queue.IsWordProcessing(a.currentWord) { + dialog.ShowError(fmt.Errorf("Cannot delete '%s' while it is in the processing queue.\nPlease wait for processing to complete.", a.currentWord), a.window) + return + } + // Create custom confirmation dialog with keyboard support message := fmt.Sprintf("Move all files for '%s' to trash?\n\nPress y to confirm or n to cancel", a.currentWord) confirmDialog := dialog.NewConfirm("Move to Trash", message, func(confirm bool) { -- cgit v1.2.3