Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
use OCA\Text\Middleware\SessionMiddleware;
use OCA\Text\Notification\Notifier;
use OCA\TpAssistant\Event\BeforeAssistantNotificationEvent;
use OCA\Viewer\Event\LoadViewer;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent as HttpBeforeTemplateRenderedEvent;
use OCP\DB\Events\AddMissingIndicesEvent;
use OCP\DirectEditing\RegisterDirectEditorEvent;
use OCP\Files\Events\Node\BeforeNodeDeletedEvent;
Expand All @@ -53,7 +53,7 @@ public function register(IRegistrationContext $context): void {
$context->registerConfigLexicon(\OCA\Text\ConfigLexicon::class);

$context->registerEventListener(RegisterDirectEditorEvent::class, RegisterDirectEditorEventListener::class);
$context->registerEventListener(LoadViewer::class, LoadViewerListener::class);
$context->registerEventListener(HttpBeforeTemplateRenderedEvent::class, LoadViewerListener::class);
$context->registerEventListener(LoadAdditionalScriptsEvent::class, FilesLoadAdditionalScriptsListener::class);
$context->registerEventListener(BeforeTemplateRenderedEvent::class, FilesSharingLoadAdditionalScriptsListener::class);
$context->registerEventListener(LoadEditor::class, LoadEditorListener::class);
Expand Down
26 changes: 10 additions & 16 deletions lib/Listeners/LoadViewerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,24 @@

namespace OCA\Text\Listeners;

use OCA\Text\Service\InitialStateProvider;
use OCA\Viewer\Event\LoadViewer;
use OCP\Collaboration\Reference\RenderReferenceEvent;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\EventDispatcher\IEventListener;
use OCP\Util;

/** @implements IEventListener<Event|LoadViewer> */
/** @implements IEventListener<BeforeTemplateRenderedEvent> */
class LoadViewerListener implements IEventListener {
public function __construct(
private readonly InitialStateProvider $initialStateProvider,
private readonly IEventDispatcher $eventDispatcher,
) {
}

public function handle(Event $event): void {
if (!$event instanceof LoadViewer) {
if (!($event instanceof BeforeTemplateRenderedEvent)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we will load this for basically all templates now, right - even if no viewer is loaded at all. So we need to make sure this is small.

return;
}
Util::addScript('text', 'text-viewer', 'viewer');
Util::addStyle('text', 'text-viewer');
$this->eventDispatcher->dispatchTyped(new RenderReferenceEvent());

$this->initialStateProvider->provideState();
if ($event->getResponse()->getRenderAs() === TemplateResponse::RENDER_AS_ERROR) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe exclude blank templates as well?

return;
}

Util::addInitScript('text', 'text-viewer');
Util::addStyle('text', 'text-viewer');
}
}
Loading
Loading