From 10661bd1005edf1ebaebf5658e33cb3671cc7445 Mon Sep 17 00:00:00 2001 From: Guy Van Sanden Date: Thu, 16 Apr 2026 14:50:02 +0200 Subject: [PATCH] Use template event listener approach --- lib/AppInfo/Application.php | 39 +++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index ea7affe..358e6d5 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -4,10 +4,14 @@ declare(strict_types=1); namespace OCA\MinimalProfile\AppInfo; +use OCA\MinimalProfile\Service\Config; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; use OCP\IConfig; use OCP\Util; @@ -20,17 +24,36 @@ class Application extends App implements IBootstrap { } public function register(IRegistrationContext $context): void { + $context->registerService(Config::class, function($c) { + return new Config($c->get(IConfig::class)); + }); + + $context->registerEventListener( + TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS, + TemplateListener::class + ); } public function boot(IBootContext $context): void { - $container = $context->getAppContainer(); - $config = $container->query(IConfig::class); + } +} + +class TemplateListener implements IEventListener { + + private Config $config; + + public function __construct(Config $config) { + $this->config = $config; + } + + public function handle(Event $event): void { + if (!($event instanceof TemplateResponse)) { + return; + } + + $hidden = $this->config->getHiddenFields(); - $value = $config->getAppValue('minimalprofile', 'hidden_fields', ''); - $hidden = ($value !== '') ? json_decode($value, true) ?? [] : []; - - // Debug first - always add this to prove CSS is being added - $debugCss = '#content { border: 50px solid purple !important; }'; + $debugCss = '#content { border: 30px solid cyan !important; }'; Util::addInlineStyle($debugCss); $css = ''; @@ -51,6 +74,6 @@ class Application extends App implements IBootstrap { Util::addInlineStyle($css); } - file_put_contents('/tmp/minimalprofile_debug.log', date('Y-m-d H:i:s') . ' Hidden: ' . print_r($hidden, true) . ' CSS: ' . $css . "\n", FILE_APPEND); + file_put_contents('/tmp/minimalprofile_debug.log', date('Y-m-d H:i:s') . ' TemplateListener ran, hidden: ' . print_r($hidden, true) . "\n", FILE_APPEND); } } \ No newline at end of file