Skip to content

Commit

Permalink
On NC, don't load the embedded player on auth page nor on shared file
Browse files Browse the repository at this point in the history
The typed dispatcher event BeforeTemplateRenderEvent on Nextcloud from the
Files_Sharing app tells us if the loaded view is the authentication page of
a password-protected share and if the shared node type is file or folder. On
NC, we anyway are using the embedded player only on folder shares and now we
can avoid the unnecessary loading of our module on the authentication page or
on the share page of an individual file.
  • Loading branch information
paulijar committed Jun 19, 2024
1 parent 85e1223 commit b67934a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion js/embedded/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
OCA.Music.fileShareView = new OCA.Music.FileShareView(mPlayer, mAudioMimes);
} else {
// Files app or a link shared folder
if (OCA.Files.fileActions) {
if (OCA.Files?.fileActions) {
OCA.Music.folderView.registerToFileActions(OCA.Files.fileActions);
}
OCA.Music.initPlaylistTabView(mPlaylistMimes);
Expand Down
18 changes: 13 additions & 5 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -794,13 +794,21 @@ private function registerHooks() {
}

private function registerEmbeddedPlayer() {
$loadEmbeddedMusicPlayer = function() {
$dispatcher = $this->getContainer()->query(\OCP\EventDispatcher\IEventDispatcher::class);

// Files app
$dispatcher->addListener(\OCA\Files\Event\LoadAdditionalScriptsEvent::class, function() {
$this->loadEmbeddedMusicPlayer();
};
});

$dispatcher = $this->getContainer()->query(\OCP\EventDispatcher\IEventDispatcher::class);
$dispatcher->addListener(\OCA\Files\Event\LoadAdditionalScriptsEvent::class, $loadEmbeddedMusicPlayer);
$dispatcher->addListener(\OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent::class, $loadEmbeddedMusicPlayer);
// Files_Sharing app
$dispatcher->addListener(\OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent::class, function(\OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent $event) {
// don't load the embedded player on the authentication page of password-protected share, and only load it for shared folders (not individual files)
if ($event->getScope() != \OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent::SCOPE_PUBLIC_SHARE_AUTH
&& $event->getShare()->getNodeType() == 'folder') {
$this->loadEmbeddedMusicPlayer();
}
});
}

/**
Expand Down

0 comments on commit b67934a

Please sign in to comment.