*/
namespace OC\Core\Listener;
+use OCP\AppFramework\Http\Events\BeforeLoginTemplateRenderedEvent;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
+use OCP\IConfig;
+use OCP\Util;
class BeforeTemplateRenderedListener implements IEventListener {
+ public function __construct(private IConfig $config) {
+ }
+
public function handle(Event $event): void {
if (!($event instanceof BeforeTemplateRenderedEvent)) {
return;
if ($event->getResponse()->getRenderAs() === TemplateResponse::RENDER_AS_USER) {
// Making sure to inject just after core
- \OCP\Util::addScript('core', 'unsupported-browser-redirect');
+ Util::addScript('core', 'unsupported-browser-redirect');
+ }
+
+ \OC_Util::addStyle('server', null, true);
+
+ if ($event instanceof BeforeTemplateRenderedEvent) {
+
+ // include common nextcloud webpack bundle
+ Util::addScript('core', 'common');
+ Util::addScript('core', 'main');
+ Util::addTranslations('core');
+
+ if ($event->getResponse()->getRenderAs() !== TemplateResponse::RENDER_AS_ERROR) {
+ Util::addScript('core', 'files_fileinfo');
+ Util::addScript('core', 'files_client');
+ Util::addScript('core', 'merged-template-prepend');
+
+
+ // If installed and background job is set to ajax, add dedicated script
+ if ($this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax') == 'ajax') {
+ Util::addScript('core', 'backgroundjobs');
+ }
+ }
}
}
}
/** @var string */
protected $app; // app id
- protected static $initTemplateEngineFirstRun = true;
-
/**
* Constructor
*
* @param bool $registerCall = true
*/
public function __construct($app, $name, $renderAs = TemplateResponse::RENDER_AS_BLANK, $registerCall = true) {
- // Read the selected theme from the config file
- self::initTemplateEngine($renderAs);
-
$theme = OC_Util::getTheme();
$requestToken = (OC::$server->getSession() && $registerCall) ? \OCP\Util::callRegister() : '';
parent::__construct($template, $requestToken, $l10n, $themeDefaults);
}
- /**
- * @param string $renderAs
- */
- public static function initTemplateEngine($renderAs) {
- if (self::$initTemplateEngineFirstRun) {
- // apps that started before the template initialization can load their own scripts/styles
- // so to make sure this scripts/styles here are loaded first we put all core scripts first
- // check lib/public/Util.php
- OC_Util::addStyle('server', null, true);
-
- // include common nextcloud webpack bundle
- Util::addScript('core', 'common');
- Util::addScript('core', 'main');
- Util::addTranslations('core');
-
- if (\OC::$server->getSystemConfig()->getValue('installed', false) && !\OCP\Util::needUpgrade()) {
- Util::addScript('core', 'files_fileinfo');
- Util::addScript('core', 'files_client');
- Util::addScript('core', 'merged-template-prepend');
- }
-
- // If installed and background job is set to ajax, add dedicated script
- if (\OC::$server->getSystemConfig()->getValue('installed', false)
- && $renderAs !== TemplateResponse::RENDER_AS_ERROR
- && !\OCP\Util::needUpgrade()) {
- if (\OC::$server->getConfig()->getAppValue('core', 'backgroundjobs_mode', 'ajax') == 'ajax') {
- Util::addScript('core', 'backgroundjobs');
- }
- }
-
- self::$initTemplateEngineFirstRun = false;
- }
- }
-
/**
* find the template with the given name