# HG changeset patch # User Paper # Date 1762431058 18000 # Node ID 27c462bc7815c7ad51919b045975bd2e4e48e283 # Parent 0265e125f68010fffac39ad5884660dfadb1241f make the "Now Playing" page actually work diff -r 0265e125f680 -r 27c462bc7815 include/core/session.h --- a/include/core/session.h Thu Nov 06 03:16:55 2025 -0500 +++ b/include/core/session.h Thu Nov 06 07:10:58 2025 -0500 @@ -30,7 +30,7 @@ /* we literally *cannot* be lying to the user by doing this */ void IncrementRequests(); std::uint32_t GetRequests(); - int uptime(); + std::int64_t uptime(); Config config; diff -r 0265e125f680 -r 27c462bc7815 include/gui/pages/now_playing.h --- a/include/gui/pages/now_playing.h Thu Nov 06 03:16:55 2025 -0500 +++ b/include/gui/pages/now_playing.h Thu Nov 06 07:10:58 2025 -0500 @@ -12,6 +12,7 @@ #include #include +#include namespace Anime { @@ -82,7 +83,9 @@ }; QStackedWidget stack_; - QTimer timer_; + /* Time the episode started playing (roughly) + * This is -1 if there is no episode playing */ + std::int64_t timer_ = -1; NowPlayingPages::Default default_; NowPlayingPages::Playing playing_; diff -r 0265e125f680 -r 27c462bc7815 src/core/anime.cc --- a/src/core/anime.cc Thu Nov 06 03:16:55 2025 -0500 +++ b/src/core/anime.cc Thu Nov 06 07:10:58 2025 -0500 @@ -16,6 +16,21 @@ #include namespace Anime { +/* FIXME need to parse relations data as well. + * + * For example + * A Certain Magical Index - 2x13.mkv + * How do we know which anime is the second season of + * "A Certain Magical Index"? We can't possibly know + * without relations data! + * + * A way to solve this would be to store prequel/sequel. + * This is sorta-kinda anime speak for seasons. We can + * then find when the prequels stop. HOWEVER, this isn't + * exactly fool proof, because there are shows with a + * second "season" that is actually a prequel, and may + * show up as one in relations data. So it's not as + * straightforward as one may think. */ /* User list data */ bool Anime::IsInUserList() const diff -r 0265e125f680 -r 27c462bc7815 src/core/anime_db.cc --- a/src/core/anime_db.cc Thu Nov 06 03:16:55 2025 -0500 +++ b/src/core/anime_db.cc Thu Nov 06 07:10:58 2025 -0500 @@ -382,7 +382,8 @@ QImage Database::GetAnimePoster(int id) { - /* Creates an anime poster and then saves it to disk */ + /* Creates an anime poster and then saves it to disk + * Sorry this is kind of spaghetti... */ QImage res; QString posterfile; diff -r 0265e125f680 -r 27c462bc7815 src/core/session.cc --- a/src/core/session.cc Thu Nov 06 03:16:55 2025 -0500 +++ b/src/core/session.cc Thu Nov 06 07:10:58 2025 -0500 @@ -40,7 +40,7 @@ return requests_; }; -int Session::uptime() +std::int64_t Session::uptime() { return timer_.elapsed(); } diff -r 0265e125f680 -r 27c462bc7815 src/gui/pages/now_playing.cc --- a/src/gui/pages/now_playing.cc Thu Nov 06 03:16:55 2025 -0500 +++ b/src/gui/pages/now_playing.cc Thu Nov 06 07:10:58 2025 -0500 @@ -5,6 +5,7 @@ #include "gui/widgets/poster.h" #include "gui/widgets/text.h" #include "services/services.h" +#include "core/session.h" #include #include @@ -12,9 +13,14 @@ #include #include +#include + #include "anitomy/anitomy.h" namespace NowPlayingPages { +// TODO the "now playing" logic should NOT be located here; this should +// only be a frontent. THAT logic should at the very least be in the +// "core" subdirectory Default::Default(QWidget *parent) : QWidget(parent) { @@ -94,17 +100,27 @@ stack_.addWidget(&default_); stack_.addWidget(&playing_); layout->addWidget(&stack_); - timer_.setSingleShot(true); - - QObject::connect(&timer_, &QTimer::timeout, this, &NowPlayingPage::TimerDone); SetDefault(); } void NowPlayingPage::SetDefault() { - /* stop any timer */ - timer_.stop(); + /* 'timer_' is the time elapsed since we were set to the 'playing' + * mode. Otherwise it is -1. */ + if (timer_ != -1) { + std::int64_t elapsed = session.uptime() - timer_; + + /* FIXME hardcoding the interval length is a hack at best + * (18 * 60 * 1000), is 18 minutes. */ + if (elapsed > (18ll * 60ll * 1000ll)) { + /* Episode has finished playing */ + TimerDone(); + } + + /* Reset the timer */ + timer_ = -1; + } stack_.setCurrentIndex(static_cast(Subpages::Default)); } @@ -116,18 +132,11 @@ void NowPlayingPage::SetPlaying(const Anime::Anime &anime, const anitomy::Elements &info) { - /* ok */ - timer_.stop(); - playing_.SetPlayingAnime(anime, info); stack_.setCurrentIndex(static_cast(Subpages::Playing)); updateGeometry(); - /* now, start the timer - * FIXME hardcoding the interval length is a hack at best - * (12 * 60 * 1000) == 720000 msec, which is 12 minutes. */ - timer_.setInterval(12 * 60 * 1000); - timer_.start(); + timer_ = session.uptime(); } void NowPlayingPage::TimerDone(void) diff -r 0265e125f680 -r 27c462bc7815 src/gui/window.cc --- a/src/gui/window.cc Thu Nov 06 03:16:55 2025 -0500 +++ b/src/gui/window.cc Thu Nov 06 07:10:58 2025 -0500 @@ -107,9 +107,15 @@ sidebar_.SetCurrentItem(static_cast(Pages::ANIME_LIST)); setCentralWidget(&main_widget_); + /* This is disgusting */ NowPlayingPage *page = reinterpret_cast(stack_.widget(static_cast(Pages::NOW_PLAYING))); connect(&playing_thread_, &MainWindowPlayingThread::Done, this, [page](const std::vector &files) { + if (!files.size()) { + page->SetDefault(); + return; + } + for (const auto &file : files) { anitomy::Anitomy anitomy; anitomy.Parse(file); @@ -135,6 +141,7 @@ }); #ifdef MACOSX + /* Anitomy needs specific permissions for window title grabbing */ if (!osx::AskForPermissions()) return; #endif diff -r 0265e125f680 -r 27c462bc7815 src/library/library.cc --- a/src/library/library.cc Thu Nov 06 03:16:55 2025 -0500 +++ b/src/library/library.cc Thu Nov 06 07:10:58 2025 -0500 @@ -56,8 +56,6 @@ std::string bname = path.filename().u8string(); int aid, ep; - std::cout << path << '\n'; - if (!GetPathAnimeAndEpisode(bname, &aid, &ep)) return; @@ -124,7 +122,7 @@ Refresh(std::optional(id)); } -// TODO export to JSON +// TODO export to JSON on exit Database db;