summaryrefslogtreecommitdiff
path: root/internal/gui/widgets.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-07-22 08:15:07 +0300
committerPaul Buetow <paul@buetow.org>2025-07-22 08:15:07 +0300
commit35ff0f508cf9cb52048f2ed67bd07f4aec17f2bf (patch)
tree3c3aef2d478e3edde300311137df43b2353af5f2 /internal/gui/widgets.go
parent1cc15cfbd68d45ae6d561e5659422e72bf9ecd1d (diff)
Fix GUI background image generation race conditions
- Add file.Sync() after image download to ensure data is flushed to disk - Add double-checking in UI updates to prevent wrong card updates - Fix background job completion to reload files when user navigates back - Add file size validation in image display widget - Improve error messages for image loading failures This fixes two issues: 1. 'png: invalid format: not enough pixel data' error when navigating during generation 2. Images not updating when navigating back to a card after background generation completes
Diffstat (limited to 'internal/gui/widgets.go')
-rw-r--r--internal/gui/widgets.go19
1 files changed, 16 insertions, 3 deletions
diff --git a/internal/gui/widgets.go b/internal/gui/widgets.go
index 6ad428c..df74027 100644
--- a/internal/gui/widgets.go
+++ b/internal/gui/widgets.go
@@ -73,7 +73,20 @@ func (d *ImageDisplay) SetImage(imagePath string) {
}
defer file.Close()
- img, _, err := image.Decode(file)
+ // Get file info to ensure it's fully written
+ stat, err := file.Stat()
+ if err != nil {
+ d.imageLabel.SetText(fmt.Sprintf("Error getting file info: %v", err))
+ return
+ }
+
+ // If file size is 0, it might still be writing
+ if stat.Size() == 0 {
+ d.imageLabel.SetText("Image file is empty")
+ return
+ }
+
+ img, format, err := image.Decode(file)
if err != nil {
d.imageLabel.SetText(fmt.Sprintf("Error decoding image: %v", err))
return
@@ -83,8 +96,8 @@ func (d *ImageDisplay) SetImage(imagePath string) {
d.imageCanvas.Image = img
d.imageCanvas.Refresh()
- // Update label
- d.imageLabel.SetText(filepath.Base(imagePath))
+ // Update label with format info
+ d.imageLabel.SetText(fmt.Sprintf("%s (%s)", filepath.Base(imagePath), format))
}
// SetImages sets multiple images but only displays the first one