namespace OCA\Accessibility\AppInfo;
+use OCA\Accessibility\Service\JSDataService;
use OCP\AppFramework\App;
+use OCP\AppFramework\Bootstrap\IBootContext;
+use OCP\AppFramework\Bootstrap\IBootstrap;
+use OCP\AppFramework\Bootstrap\IRegistrationContext;
+use OCP\AppFramework\IAppContainer;
use OCP\IConfig;
+use OCP\IInitialStateService;
use OCP\IURLGenerator;
use OCP\IUserSession;
+use function count;
+use function implode;
+use function md5;
-class Application extends App {
+class Application extends App implements IBootstrap {
/** @var string */
- public const APP_NAME = 'accessibility';
+ public const APP_ID = 'accessibility';
- /** @var IConfig */
- private $config;
+ public function __construct() {
+ parent::__construct(self::APP_ID);
+ }
- /** @var IUserSession */
- private $userSession;
+ public function register(IRegistrationContext $context): void {
+ }
- /** @var IURLGenerator */
- private $urlGenerator;
+ public function boot(IBootContext $context): void {
+ $this->injectCss(
+ $context->getAppContainer()->query(IUserSession::class),
+ $context->getAppContainer()->query(IConfig::class),
+ $context->getAppContainer()->query(IURLGenerator::class)
+ );
- public function __construct() {
- parent::__construct(self::APP_NAME);
- $this->config = \OC::$server->getConfig();
- $this->userSession = \OC::$server->getUserSession();
- $this->urlGenerator = \OC::$server->getURLGenerator();
+ $this->registerInitialState($context->getAppContainer());
}
- public function injectCss() {
+ private function injectCss(IUserSession $userSession,
+ IConfig $config,
+ IURLGenerator $urlGenerator) {
// Inject the fake css on all pages if enabled and user is logged
- $loggedUser = $this->userSession->getUser();
- if (!is_null($loggedUser)) {
- $userValues = $this->config->getUserKeys($loggedUser->getUID(), self::APP_NAME);
+ $loggedUser = $userSession->getUser();
+ if ($loggedUser !== null) {
+ $userValues = $config->getUserKeys($loggedUser->getUID(), self::APP_ID);
// we want to check if any theme or font is enabled.
if (count($userValues) > 0) {
- $hash = $this->config->getUserValue($loggedUser->getUID(), self::APP_NAME, 'icons-css', md5(implode('-', $userValues)));
- $linkToCSS = $this->urlGenerator->linkToRoute(self::APP_NAME . '.accessibility.getCss', ['md5' => $hash]);
+ $hash = $config->getUserValue($loggedUser->getUID(), self::APP_ID, 'icons-css', md5(implode('-', $userValues)));
+ $linkToCSS = $urlGenerator->linkToRoute(self::APP_ID . '.accessibility.getCss', ['md5' => $hash]);
\OCP\Util::addHeader('link', ['rel' => 'stylesheet', 'href' => $linkToCSS]);
}
+ } else {
+ $userValues = ['dark'];
+
+ $hash = md5(implode('-', $userValues));
+ $linkToCSS = $this->urlGenerator->linkToRoute(self::APP_NAME . '.accessibility.getCss', ['md5' => $hash]);
+ \OCP\Util::addHeader('link', ['rel' => 'stylesheet', 'media' => '(prefers-color-scheme: dark)', 'href' => $linkToCSS]);
}
}