Track current source to avoid rebuilds

This commit is contained in:
Stu 2025-12-10 05:09:01 -05:00
parent a393183d83
commit 9d255680bf

37
main.go
View File

@ -182,6 +182,7 @@ type appState struct {
playerLast time.Time
compareSess1 *playSession
compareSess2 *playSession
lastSourcePath string
progressQuit chan struct{}
convertCancel context.CancelFunc
playerSurf *playerSurface
@ -469,18 +470,18 @@ func (s *appState) buildComparePane(src *videoSource, onStop func(), setSess fun
videoImg := canvas.NewImageFromResource(nil)
videoImg.SetMinSize(fyne.NewSize(960, 540))
// Populate a preview frame if available
if len(src.PreviewFrames) == 0 {
if frames, err := capturePreviewFrames(src.Path, src.Duration); err == nil && len(frames) > 0 {
src.PreviewFrames = frames
}
if len(src.PreviewFrames) == 0 {
if frames, err := capturePreviewFrames(src.Path, src.Duration); err == nil && len(frames) > 0 {
src.PreviewFrames = frames
}
if len(src.PreviewFrames) > 0 {
s.currentFrame = src.PreviewFrames[0]
videoImg.File = s.currentFrame
videoImg.Refresh()
}
videoImg.FillMode = canvas.ImageFillContain
stage := container.NewMax(stageBG, videoImg)
}
if len(src.PreviewFrames) > 0 {
s.currentFrame = src.PreviewFrames[0]
videoImg.File = s.currentFrame
videoImg.Refresh()
}
videoImg.FillMode = canvas.ImageFillContain
stage := container.NewMax(stageBG, videoImg)
currentTime := widget.NewLabel("0:00")
totalTime := widget.NewLabel(src.DurationString())
@ -577,13 +578,16 @@ func (s *appState) buildComparePane(src *videoSource, onStop func(), setSess fun
// showPlayerView renders the player-focused UI with a lightweight playlist.
func (s *appState) showPlayerView() {
fmt.Printf("🎬 showPlayerView called\n")
if s.active == "player" && s.playSess != nil {
fmt.Printf("📺 already in player view; skipping rebuild\n")
if s.active == "player" && s.source != nil && s.lastSourcePath == s.source.Path {
fmt.Printf("📺 already in player view for this source; skipping rebuild\n")
return
}
// Do not stop the player; only clear compare previews.
s.stopCompareSessions()
s.active = "player"
if s.source != nil {
s.lastSourcePath = s.source.Path
}
fmt.Printf("📺 s.source is nil: %v\n", s.source == nil)
// Helper to refresh the view after selection/loads.
@ -1986,6 +1990,7 @@ func runGUI() {
a.Settings().SetTheme(&ui.MonoTheme{})
logging.Debug(logging.CatUI, "created fyne app: %#v", a)
w := a.NewWindow("VT Player")
state.window = w
if icon := utils.LoadAppIcon(); icon != nil {
a.SetIcon(icon)
w.SetIcon(icon)
@ -4502,6 +4507,7 @@ func (s *appState) clearVideo() {
s.convert.CoverArtPath = ""
s.convert.AspectHandling = "Auto"
s.convert.OutputAspect = "Source"
s.lastSourcePath = ""
fyne.CurrentApp().Driver().DoFromGoroutine(func() {
s.showPlayerView()
}, false)
@ -4650,9 +4656,8 @@ func (s *appState) switchToVideo(index int) {
s.playerPos = 0
s.playerPaused = true
fyne.CurrentApp().Driver().DoFromGoroutine(func() {
s.showPlayerView()
}, false)
// Do not rebuild the view; player session stays active.
s.lastSourcePath = src.Path
}
// nextVideo switches to the next loaded video