]> source.dussan.org Git - nextcloud-server.git/commitdiff
Merge pull request #21366 from nextcloud/feature/noid/respect-prefers-color-scheme
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>
Mon, 22 Jun 2020 13:56:11 +0000 (15:56 +0200)
committerGitHub <noreply@github.com>
Mon, 22 Jun 2020 13:56:11 +0000 (15:56 +0200)
Respect "prefers-color-scheme" media selector for guests

1  2 
apps/accessibility/lib/AppInfo/Application.php
apps/accessibility/lib/Controller/AccessibilityController.php

index c5c495c18294acc0092c2a836af88948c83953af,02dfeb8c16bec6f3a02e50ef6c01cc2117749d4e..9b79cadb4b6e8a1ddcad612cb74051626c53ac73
@@@ -29,55 -26,49 +29,61 @@@ declare(strict_types=1)
  
  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]);
                }
        }