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