diff --git a/main.go b/main.go index ed64f14..5adc71c 100644 --- a/main.go +++ b/main.go @@ -186,6 +186,7 @@ type appState struct { playerViewSource string renderingPlayerView bool playerViewRefreshNeeded bool + lastPlayerViewRender time.Time progressQuit chan struct{} convertCancel context.CancelFunc playerSurf *playerSurface @@ -586,13 +587,19 @@ func (s *appState) showPlayerView() { fmt.Printf("⏳ player view render already in progress, skipping\n") return } - s.renderingPlayerView = true - defer func() { s.renderingPlayerView = false }() - currentPath := "" if s.source != nil { currentPath = s.source.Path } + // Hard throttle: if we rendered recently for the same source, skip. + if !s.playerViewRefreshNeeded && s.active == "player" && s.playerViewSource == currentPath && time.Since(s.lastPlayerViewRender) < time.Second { + fmt.Printf("⏳ throttle: rendered recently for %s\n", currentPath) + return + } + + s.renderingPlayerView = true + defer func() { s.renderingPlayerView = false }() + if !s.playerViewRefreshNeeded && s.active == "player" && s.source != nil && s.playerViewSource == currentPath { fmt.Printf("📺 already in player view for this source; skipping rebuild\n") return @@ -605,6 +612,7 @@ func (s *appState) showPlayerView() { s.lastSourcePath = s.source.Path } fmt.Printf("📺 s.source is nil: %v\n", s.source == nil) + s.lastPlayerViewRender = time.Now() // Helper to refresh the view after selection/loads. refresh := func() { @@ -4510,7 +4518,11 @@ func (s *appState) loadVideo(path string) { fyne.CurrentApp().Driver().DoFromGoroutine(func() { s.playerViewRefreshNeeded = true s.switchToVideo(s.currentIndex) - s.showPlayerView() + // Avoid immediate re-render storm; defer minimal trigger. + time.AfterFunc(10*time.Millisecond, func() { + s.playerViewRefreshNeeded = true + s.showPlayerView() + }) }, false) } @@ -4637,7 +4649,10 @@ func (s *appState) loadVideos(paths []string) { fyne.Do(func() { s.playerViewRefreshNeeded = true s.switchToVideo(0) - s.showPlayerView() + time.AfterFunc(10*time.Millisecond, func() { + s.playerViewRefreshNeeded = true + s.showPlayerView() + }) }) }() }