v1.0.21 - boot() reads config, adds inline CSS, logs to /tmp/mp_loaded.log

This commit is contained in:
2026-04-16 16:16:33 +02:00
parent ba35d41608
commit 7d2d102e29
2 changed files with 29 additions and 4 deletions

View File

@@ -9,6 +9,7 @@ use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\Util;
class Application extends App implements IBootstrap {
@@ -20,17 +21,41 @@ class Application extends App implements IBootstrap {
}
public function register(IRegistrationContext $context): void {
// Register event listener - this fires on EVERY page render after template is built
$context->registerService(IConfig::class, function($c) {
return $c->get(IConfig::class);
});
$context->registerEventListener(
TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS,
function() {
Util::addStyle('minimalprofile', 'minimalprofile');
}
);
file_put_contents('/tmp/minimalprofile.log', date('Y-m-d H:i:s') . ' register, event registered' . "\n", FILE_APPEND);
}
public function boot(IBootContext $context): void {
$config = $context->getAppContainer()->query(IConfig::class);
$value = $config->getAppValue('minimalprofile', 'hidden_fields', '');
$hidden = ($value !== '') ? json_decode($value, true) ?? [] : [];
$css = '';
if (!empty($hidden)) {
$selectors = [
'pronouns' => '#account-property-pronouns',
'role' => '#account-property-role',
'headline' => '#account-property-headline',
];
foreach ($hidden as $field) {
if (isset($selectors[$field])) {
$css .= $selectors[$field] . ' { display: none !important; }' . "\n";
}
}
}
if ($css) {
Util::addInlineStyle($css);
}
file_put_contents('/tmp/mp_loaded.log', date('Y-m-d H:i:s') . ' boot ran, hidden: ' . print_r($hidden, true) . ", css: $css\n", FILE_APPEND);
}
}