Improved PDF viewer integration

Also fixed a crash on shutdown caused by the PDF viewer
This commit is contained in:
Leon Styhre 2023-06-22 22:15:59 +02:00
parent 6bf8c5af46
commit f9780e58d8
3 changed files with 19 additions and 7 deletions

View file

@ -12,6 +12,7 @@
#include "Sound.h" #include "Sound.h"
#include "utils/FileSystemUtil.h" #include "utils/FileSystemUtil.h"
#include "utils/StringUtil.h" #include "utils/StringUtil.h"
#include "views/ViewController.h"
#include <array> #include <array>
@ -30,6 +31,8 @@ PDFViewer::PDFViewer()
bool PDFViewer::startPDFViewer(FileData* game) bool PDFViewer::startPDFViewer(FileData* game)
{ {
ViewController::getInstance()->pauseViewVideos();
#if defined(_WIN64) #if defined(_WIN64)
const std::string convertBinary {"/es-pdf-converter/es-pdf-convert.exe"}; const std::string convertBinary {"/es-pdf-converter/es-pdf-convert.exe"};
#else #else
@ -42,6 +45,8 @@ bool PDFViewer::startPDFViewer(FileData* game)
#else #else
LOG(LogError) << "Couldn't find PDF conversion binary es-pdf-convert"; LOG(LogError) << "Couldn't find PDF conversion binary es-pdf-convert";
#endif #endif
NavigationSounds::getInstance().playThemeNavigationSound(SCROLLSOUND);
ViewController::getInstance()->stopViewVideos();
return false; return false;
} }
@ -49,6 +54,8 @@ bool PDFViewer::startPDFViewer(FileData* game)
if (!Utils::FileSystem::exists(mManualPath)) { if (!Utils::FileSystem::exists(mManualPath)) {
LOG(LogError) << "No PDF manual found for game \"" << game->getName() << "\""; LOG(LogError) << "No PDF manual found for game \"" << game->getName() << "\"";
NavigationSounds::getInstance().playThemeNavigationSound(SCROLLSOUND);
ViewController::getInstance()->stopViewVideos();
return false; return false;
} }
@ -66,6 +73,8 @@ bool PDFViewer::startPDFViewer(FileData* game)
if (!getDocumentInfo()) { if (!getDocumentInfo()) {
LOG(LogError) << "PDFViewer: Couldn't load file \"" << mManualPath; LOG(LogError) << "PDFViewer: Couldn't load file \"" << mManualPath;
NavigationSounds::getInstance().playThemeNavigationSound(SCROLLSOUND);
ViewController::getInstance()->stopViewVideos();
return false; return false;
} }
@ -74,6 +83,8 @@ bool PDFViewer::startPDFViewer(FileData* game)
for (int i {1}; i <= mPageCount; ++i) { for (int i {1}; i <= mPageCount; ++i) {
if (mPages.find(i) == mPages.end()) { if (mPages.find(i) == mPages.end()) {
LOG(LogError) << "Couldn't read information for page " << i << ", invalid PDF file?"; LOG(LogError) << "Couldn't read information for page " << i << ", invalid PDF file?";
NavigationSounds::getInstance().playThemeNavigationSound(SCROLLSOUND);
ViewController::getInstance()->stopViewVideos();
return false; return false;
} }
@ -119,6 +130,8 @@ bool PDFViewer::startPDFViewer(FileData* game)
void PDFViewer::stopPDFViewer() void PDFViewer::stopPDFViewer()
{ {
NavigationSounds::getInstance().playThemeNavigationSound(SCROLLSOUND); NavigationSounds::getInstance().playThemeNavigationSound(SCROLLSOUND);
ViewController::getInstance()->stopViewVideos();
mPages.clear(); mPages.clear();
mPageImage.reset(); mPageImage.reset();
} }

View file

@ -17,7 +17,6 @@ class PDFViewer : public Window::PDFViewer
{ {
public: public:
PDFViewer(); PDFViewer();
~PDFViewer() { stopPDFViewer(); }
bool startPDFViewer(FileData* game) override; bool startPDFViewer(FileData* game) override;
void stopPDFViewer() override; void stopPDFViewer() override;

View file

@ -477,7 +477,7 @@ void Window::render()
auto& bottom = mGuiStack.front(); auto& bottom = mGuiStack.front();
auto& top = mGuiStack.back(); auto& top = mGuiStack.back();
if (mRenderMediaViewer || mRenderScreensaver) { if (mRenderMediaViewer || mRenderPDFViewer || mRenderScreensaver) {
bottom->cancelAllAnimations(); bottom->cancelAllAnimations();
bottom->stopAllAnimations(); bottom->stopAllAnimations();
} }
@ -485,8 +485,8 @@ void Window::render()
// Don't render the system view or gamelist view if the media viewer is active or if the // Don't render the system view or gamelist view if the media viewer is active or if the
// video or slideshow screensaver is running. The exception is if the fallback screensaver // video or slideshow screensaver is running. The exception is if the fallback screensaver
// is active due to a lack of videos or images. // is active due to a lack of videos or images.
bool renderBottom = true; bool renderBottom {true};
if (mRenderMediaViewer) if (mRenderMediaViewer || mRenderPDFViewer)
renderBottom = false; renderBottom = false;
else if (mRenderScreensaver && mScreensaver->isFallbackScreensaver()) else if (mRenderScreensaver && mScreensaver->isFallbackScreensaver())
renderBottom = true; renderBottom = true;
@ -653,9 +653,9 @@ void Window::render()
unsigned int screensaverTimer { unsigned int screensaverTimer {
static_cast<unsigned int>(Settings::getInstance()->getInt("ScreensaverTimer"))}; static_cast<unsigned int>(Settings::getInstance()->getInt("ScreensaverTimer"))};
if (mTimeSinceLastInput >= screensaverTimer && screensaverTimer != 0) { if (mTimeSinceLastInput >= screensaverTimer && screensaverTimer != 0) {
// If the media viewer is running or if a menu is open, reset the screensaver timer so // If the media viewer or PDF viewer is running, or if a menu is open, then reset the
// that the screensaver won't start. // screensaver timer so that the screensaver won't start.
if (mRenderMediaViewer || mGuiStack.front() != mGuiStack.back()) if (mRenderMediaViewer || mRenderPDFViewer || mGuiStack.front() != mGuiStack.back())
mTimeSinceLastInput = 0; mTimeSinceLastInput = 0;
// If a game has been launched, reset the screensaver timer as we don't want to start // If a game has been launched, reset the screensaver timer as we don't want to start
// the screensaver in the background when running a game. // the screensaver in the background when running a game.