Skip to content

Commit 7ac1d65

Browse files
committed
Load PDF viewer only in public share pages
The PDF viewer is initialized only in public share pages for PDF files, but it was loaded in all public pages (for example, in the public profile page). To reduce the number of unneeded loads now it is loaded only in public share pages instead. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
1 parent f0d0d2d commit 7ac1d65

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

lib/AppInfo/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131
use OCA\Files_PDFViewer\Listeners\LoadPublicViewerListener;
3232
use OCA\Files_PDFViewer\Listeners\LoadViewerListener;
3333

34+
use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent;
3435
use OCA\Viewer\Event\LoadViewer;
3536

3637
use OCP\AppFramework\App;
3738
use OCP\AppFramework\Bootstrap\IBootContext;
3839
use OCP\AppFramework\Bootstrap\IBootstrap;
3940
use OCP\AppFramework\Bootstrap\IRegistrationContext;
40-
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
4141
use OCP\Security\CSP\AddContentSecurityPolicyEvent;
4242

4343
class Application extends App implements IBootstrap {

lib/Listeners/LoadPublicViewerListener.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
namespace OCA\Files_PDFViewer\Listeners;
2828

2929
use OCA\Files_PDFViewer\AppInfo\Application;
30-
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
31-
use OCP\AppFramework\Http\TemplateResponse;
30+
use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent;
3231
use OCP\EventDispatcher\Event;
3332
use OCP\EventDispatcher\IEventListener;
3433
use OCP\Util;
@@ -39,10 +38,12 @@ public function handle(Event $event): void {
3938
return;
4039
}
4140

42-
// Make sure we are on a public page rendering
43-
if ($event->getResponse()->getRenderAs() !== TemplateResponse::RENDER_AS_PUBLIC) {
41+
// If the event has a scope it is not the default share page but, for
42+
// example, the authentication page
43+
if ($event->getScope() !== null) {
4444
return;
4545
}
46+
4647
Util::addScript(Application::APP_ID, 'files_pdfviewer-public');
4748
}
4849
}

0 commit comments

Comments
 (0)