Throttle player view calls aggressively
This commit is contained in:
parent
feeaf8e39a
commit
3d43123840
25
main.go
25
main.go
|
|
@ -186,6 +186,7 @@ type appState struct {
|
||||||
playerViewSource string
|
playerViewSource string
|
||||||
renderingPlayerView bool
|
renderingPlayerView bool
|
||||||
playerViewRefreshNeeded bool
|
playerViewRefreshNeeded bool
|
||||||
|
lastPlayerViewRender time.Time
|
||||||
progressQuit chan struct{}
|
progressQuit chan struct{}
|
||||||
convertCancel context.CancelFunc
|
convertCancel context.CancelFunc
|
||||||
playerSurf *playerSurface
|
playerSurf *playerSurface
|
||||||
|
|
@ -586,13 +587,19 @@ func (s *appState) showPlayerView() {
|
||||||
fmt.Printf("⏳ player view render already in progress, skipping\n")
|
fmt.Printf("⏳ player view render already in progress, skipping\n")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.renderingPlayerView = true
|
|
||||||
defer func() { s.renderingPlayerView = false }()
|
|
||||||
|
|
||||||
currentPath := ""
|
currentPath := ""
|
||||||
if s.source != nil {
|
if s.source != nil {
|
||||||
currentPath = s.source.Path
|
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 {
|
if !s.playerViewRefreshNeeded && s.active == "player" && s.source != nil && s.playerViewSource == currentPath {
|
||||||
fmt.Printf("📺 already in player view for this source; skipping rebuild\n")
|
fmt.Printf("📺 already in player view for this source; skipping rebuild\n")
|
||||||
return
|
return
|
||||||
|
|
@ -605,6 +612,7 @@ func (s *appState) showPlayerView() {
|
||||||
s.lastSourcePath = s.source.Path
|
s.lastSourcePath = s.source.Path
|
||||||
}
|
}
|
||||||
fmt.Printf("📺 s.source is nil: %v\n", s.source == nil)
|
fmt.Printf("📺 s.source is nil: %v\n", s.source == nil)
|
||||||
|
s.lastPlayerViewRender = time.Now()
|
||||||
|
|
||||||
// Helper to refresh the view after selection/loads.
|
// Helper to refresh the view after selection/loads.
|
||||||
refresh := func() {
|
refresh := func() {
|
||||||
|
|
@ -4510,7 +4518,11 @@ func (s *appState) loadVideo(path string) {
|
||||||
fyne.CurrentApp().Driver().DoFromGoroutine(func() {
|
fyne.CurrentApp().Driver().DoFromGoroutine(func() {
|
||||||
s.playerViewRefreshNeeded = true
|
s.playerViewRefreshNeeded = true
|
||||||
s.switchToVideo(s.currentIndex)
|
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)
|
}, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -4637,7 +4649,10 @@ func (s *appState) loadVideos(paths []string) {
|
||||||
fyne.Do(func() {
|
fyne.Do(func() {
|
||||||
s.playerViewRefreshNeeded = true
|
s.playerViewRefreshNeeded = true
|
||||||
s.switchToVideo(0)
|
s.switchToVideo(0)
|
||||||
s.showPlayerView()
|
time.AfterFunc(10*time.Millisecond, func() {
|
||||||
|
s.playerViewRefreshNeeded = true
|
||||||
|
s.showPlayerView()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user