Lazy-load thumbnail previews for batch drops
This commit is contained in:
parent
223ff7203b
commit
0bf4ee54d5
28
main.go
28
main.go
|
|
@ -11132,29 +11132,21 @@ func (s *appState) handleDrop(pos fyne.Position, items []fyne.URI) {
|
|||
return
|
||||
}
|
||||
|
||||
// Multi-drop: load list and add jobs for each file
|
||||
// Multi-drop: add lightweight list entries and queue jobs
|
||||
go func() {
|
||||
var sources []*videoSource
|
||||
for _, path := range videoPaths {
|
||||
src, err := probeVideo(path)
|
||||
if err != nil {
|
||||
logging.Debug(logging.CatModule, "failed to load video for thumb: %v", err)
|
||||
continue
|
||||
}
|
||||
sources = append(sources, src)
|
||||
}
|
||||
if len(sources) == 0 {
|
||||
fyne.CurrentApp().Driver().DoFromGoroutine(func() {
|
||||
dialog.ShowError(fmt.Errorf("failed to load video files for thumbnails"), s.window)
|
||||
}, false)
|
||||
return
|
||||
}
|
||||
|
||||
fyne.CurrentApp().Driver().DoFromGoroutine(func() {
|
||||
var sources []*videoSource
|
||||
for _, path := range videoPaths {
|
||||
sources = append(sources, &videoSource{
|
||||
Path: path,
|
||||
DisplayName: filepath.Base(path),
|
||||
})
|
||||
}
|
||||
s.thumbFiles = sources
|
||||
s.thumbFile = sources[0]
|
||||
s.showThumbView()
|
||||
logging.Debug(logging.CatModule, "loaded %d videos into thumb module", len(sources))
|
||||
s.loadThumbSourceAtIndex(0)
|
||||
logging.Debug(logging.CatModule, "loaded %d videos into thumb module (lazy probe)", len(sources))
|
||||
}, false)
|
||||
|
||||
if s.jobQueue != nil {
|
||||
|
|
|
|||
|
|
@ -42,6 +42,34 @@ func (s *appState) addThumbSource(src *videoSource) {
|
|||
s.thumbFiles = append(s.thumbFiles, src)
|
||||
}
|
||||
|
||||
func (s *appState) loadThumbSourceAtIndex(idx int) {
|
||||
if idx < 0 || idx >= len(s.thumbFiles) {
|
||||
return
|
||||
}
|
||||
current := s.thumbFiles[idx]
|
||||
if current == nil || current.Path == "" {
|
||||
return
|
||||
}
|
||||
if current.Width > 0 || current.Height > 0 || current.Duration > 0 {
|
||||
return
|
||||
}
|
||||
path := current.Path
|
||||
go func() {
|
||||
probed, err := probeVideo(path)
|
||||
if err != nil {
|
||||
logging.Debug(logging.CatModule, "failed to probe thumbnail source: %v", err)
|
||||
return
|
||||
}
|
||||
fyne.CurrentApp().Driver().DoFromGoroutine(func() {
|
||||
s.thumbFiles[idx] = probed
|
||||
if s.thumbFile != nil && s.thumbFile.Path == path {
|
||||
s.thumbFile = probed
|
||||
}
|
||||
s.showThumbView()
|
||||
}, false)
|
||||
}()
|
||||
}
|
||||
|
||||
func buildThumbView(state *appState) fyne.CanvasObject {
|
||||
thumbColor := moduleColor("thumb")
|
||||
|
||||
|
|
@ -92,7 +120,10 @@ func buildThumbView(state *appState) fyne.CanvasObject {
|
|||
fileLabel.TextStyle = fyne.TextStyle{Bold: true}
|
||||
|
||||
var videoContainer fyne.CanvasObject
|
||||
if state.thumbFile != nil {
|
||||
if state.thumbFile != nil && state.thumbFile.Width == 0 && state.thumbFile.Height == 0 {
|
||||
fileLabel.SetText(fmt.Sprintf("File: %s", filepath.Base(state.thumbFile.Path)))
|
||||
videoContainer = container.NewCenter(widget.NewLabel("Loading preview..."))
|
||||
} else if state.thumbFile != nil {
|
||||
fileLabel.SetText(fmt.Sprintf("File: %s", filepath.Base(state.thumbFile.Path)))
|
||||
videoContainer = buildVideoPane(state, fyne.NewSize(480, 270), state.thumbFile, nil)
|
||||
} else {
|
||||
|
|
@ -407,6 +438,7 @@ func buildThumbView(state *appState) fyne.CanvasObject {
|
|||
return
|
||||
}
|
||||
state.thumbFile = state.thumbFiles[id]
|
||||
state.loadThumbSourceAtIndex(id)
|
||||
state.showThumbView()
|
||||
}
|
||||
if state.thumbFile != nil {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user