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
+36 -5
View File
@@ -576,12 +576,17 @@ class YTSageApp(QMainWindow, FormatTableMixin, VideoInfoMixin, AnalysisMixin):
self.feed_page = FeedPage(self.router, self)
self.browse_page = BrowsePage(self.router, self)
# Feed first, Watch last. The feed is what you open the app to see;
# the player is where the other tabs send you, not somewhere you
# start. _tab_index_of resolves by widget identity, so the routing
# methods below are unaffected by this order.
self.main_tabs = SmoothTabWidget(self)
self.main_tabs.addTab(self.watch_page, _("main_tabs.watch"))
self.main_tabs.addTab(self.search_page, _("main_tabs.search"))
self.main_tabs.addTab(self.feed_page, _("main_tabs.feed"))
self.main_tabs.addTab(self.browse_page, _("main_tabs.browse"))
self.main_tabs.addTab(self.download_page, _("main_tabs.downloads"))
self.main_tabs.addTab(self.feed_page, _("main_tabs.feed"), icons.icon("rss", theme.ICON))
self.main_tabs.addTab(self.search_page, _("main_tabs.search"), icons.icon("search", theme.ICON))
self.main_tabs.addTab(self.browse_page, _("main_tabs.browse"), icons.icon("library", theme.ICON))
self.main_tabs.addTab(self.download_page, _("main_tabs.downloads"), icons.icon("download", theme.ICON))
self.main_tabs.addTab(self.watch_page, _("main_tabs.watch"), icons.icon("play", theme.ICON))
self.main_tabs.currentChanged.connect(self._on_main_tab_changed)
self.setCentralWidget(self.main_tabs)
# Fullscreen is driven from here because the chrome it hides -- the tab
@@ -599,6 +604,25 @@ class YTSageApp(QMainWindow, FormatTableMixin, VideoInfoMixin, AnalysisMixin):
self.router.openChannel.connect(self._route_open_channel)
self.router.openPlaylist.connect(self._route_open_playlist)
self.browse_page.subscribeRequested.connect(self.feed_page.subscribe_channel)
# A new subscription changes what the Feed's empty state should say.
self.feed_page.subscriptionsChanged.connect(self.browse_page.refresh_subscribe_state)
def _on_main_tab_changed(self, index: int) -> None:
"""
Tell a page it has become visible.
Duck-typed rather than isinstance-checked so a page opts in by simply
defining the method. Preferred over showEvent, which also fires on
window restore and on first show.
"""
page = self.main_tabs.stack.widget(index)
hook = getattr(page, "on_tab_activated", None)
if hook is None:
return
try:
hook()
except Exception as e:
logger.debug(f"Tab activation hook failed: {e}")
def _tab_index_of(self, page) -> int:
for i in range(self.main_tabs.stack.count()):
@@ -1211,6 +1235,13 @@ class YTSageApp(QMainWindow, FormatTableMixin, VideoInfoMixin, AnalysisMixin):
except Exception as e:
logger.debug(f"Watch page shutdown error: {e}")
# Stop a feed refresh before its QThread is destroyed with it.
if hasattr(self, "feed_page"):
try:
self.feed_page.shutdown()
except Exception as e:
logger.debug(f"Feed page shutdown error: {e}")
# Stop the analysis thread if it's running
if hasattr(self, "_analysis_thread") and self._analysis_thread is not None and self._analysis_thread.isRunning():
logger.info("Stopping analysis thread...")