Open on the Feed, and refresh it without hammering yt-dlp

The tab order was Watch, Search, Feed, Browse, Downloads, and the app opened
on Watch -- which is where the other tabs send you, not somewhere you start.
It is now Feed, Search, Browse, Downloads, Watch, with icons. Routing is
unaffected: _tab_index_of resolves by widget identity, not position.

Refresh-on-open needed care rather than a call in showEvent. A local refresh
is one yt-dlp subprocess per subscribed channel, serially, so it is braked
four ways: only channels not seen for feed.auto_refresh_on_open_minutes (30,
0 to disable), at most eight per visit, once per interval per session, and
after a delay so it does not race the tab transition or first-run setup. The
cached feed is already on screen throughout. That is a new config key rather
than the dead auto_refresh_minutes, because existing configs store that as 0
and would have read as opting out of a feature that did not exist yet.

SmoothTabWidget gained the currentChanged signal, icons and a corner slot it
never had. Its set_current_index needed a re-entrancy flag, not just an index
check: setting the tab bar's index emits its currentChanged straight back into
the same method, and at that point the stack has not moved, so every switch
fired the activation hook twice.

The grid was cleared and rebuilt after every channel finished -- flicker, lost
scroll position and every thumbnail re-read from disk each time. merge_entries
keeps existing cards. While there, _relayout was re-adding cards the layout
already owned, so layout items accumulated on every Load more, and the resize
check compared against columnCount(), which never shrinks, so it relaid out on
every resize event.

Smaller things this exposed: feed errors were written into the label the next
success overwrote, so failures were invisible; switching to account mode left
the local videos on screen; cancel() had no callers, so a refresh outlived the
tab and the window; Browse's Subscribe never said Unsubscribe though it
toggles; "Play all" queued one page while claiming otherwise; and the feed
sorted publish times against wall-clock fetch times in one COALESCE, so the
last-refreshed channel floated to the top.

Feed is the first thing seen now, so an empty one says what to do about it
instead of showing a bare grid.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-09 01:11:40 +02:00
parent 27933dd495
commit 79a6f26c2f
9 changed files with 453 additions and 80 deletions
+58 -13
View File
@@ -1,9 +1,10 @@
from PySide6.QtCore import QEasingCurve, QPropertyAnimation, Qt
from PySide6.QtCore import QEasingCurve, QPropertyAnimation, Qt, Signal
from PySide6.QtGui import QPixmap
from PySide6.QtOpenGLWidgets import QOpenGLWidget
from PySide6.QtWidgets import (
QFrame,
QGraphicsOpacityEffect,
QHBoxLayout,
QLabel,
QStackedWidget,
QTabBar,
@@ -94,20 +95,38 @@ class SmoothTabWidget(QWidget):
A unified Widget that behaves like a QTabWidget but uses smooth fading transitions.
Includes a QTabBar and a FadingStackedWidget.
"""
#: Emitted after the visible page has actually changed. The QTabBar's own
#: currentChanged is not usable for this: it fires before the stack has
#: switched, and it re-enters through set_current_index.
currentChanged = Signal(int)
def __init__(self, parent=None):
super().__init__(parent)
# Main Layout
self.layout = QVBoxLayout(self)
self.layout.setContentsMargins(0, 0, 0, 0)
self.layout.setSpacing(0)
# Tab Bar
self.tab_bar = QTabBar(self)
self.tab_bar.setDrawBase(False) # We draw border on content instead
# Tab bar, plus a right-aligned slot for a corner widget. Wrapped in a
# row so something (the account button) can sit opposite the tabs the
# way QTabWidget::setCornerWidget would allow.
self.tab_row = QWidget(self)
tab_row_layout = QHBoxLayout(self.tab_row)
tab_row_layout.setContentsMargins(0, 0, 0, 0)
tab_row_layout.setSpacing(0)
self.tab_bar = QTabBar(self.tab_row)
self.tab_bar.setDrawBase(False) # We draw border on content instead
self.tab_bar.currentChanged.connect(self.set_current_index)
self.layout.addWidget(self.tab_bar)
tab_row_layout.addWidget(self.tab_bar)
tab_row_layout.addStretch(1)
self.corner_widget = None
self._switching = False
self._tab_row_layout = tab_row_layout
self.layout.addWidget(self.tab_row)
# Content Area (Frame) - Mimics QTabWidget::pane
self.content_frame = QFrame(self)
self.content_frame.setObjectName("tabContent")
@@ -123,15 +142,41 @@ class SmoothTabWidget(QWidget):
self.layout.addWidget(self.content_frame)
def addTab(self, widget, label):
"""Add a tab with the given widget and label."""
def addTab(self, widget, label, icon=None):
"""Add a tab with the given widget, label and optional icon."""
self.stack.addWidget(widget)
self.tab_bar.addTab(label)
if icon is not None:
self.tab_bar.addTab(icon, label)
else:
self.tab_bar.addTab(label)
def setCornerWidget(self, widget):
"""Place a widget at the right-hand end of the tab row."""
if self.corner_widget is not None:
self.corner_widget.setParent(None)
self.corner_widget = widget
if widget is not None:
widget.setParent(self.tab_row)
self._tab_row_layout.addWidget(widget)
def set_current_index(self, index):
"""Slot to handle tab bar clicks."""
self.tab_bar.setCurrentIndex(index)
self.stack.setCurrentIndex(index)
if index == self.stack.currentIndex() and self.tab_bar.currentIndex() == index:
return
# setCurrentIndex on the bar emits its own currentChanged, which is
# connected straight back here -- and at that moment the stack has not
# moved yet, so a plain index comparison does not catch the re-entry.
# Without this flag every switch emitted currentChanged twice and each
# page's activation hook ran twice.
if self._switching:
return
self._switching = True
try:
self.tab_bar.setCurrentIndex(index)
self.stack.setCurrentIndex(index)
finally:
self._switching = False
self.currentChanged.emit(index)
def currentWidget(self):
return self.stack.currentWidget()