Skip to content

Commit

Permalink
Respect "prefers-color-scheme" media selector for guests
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Jun 10, 2020
1 parent 9806dec commit 2916402
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions apps/accessibility/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ public function injectCss() {
$linkToCSS = $this->urlGenerator->linkToRoute(self::APP_NAME . '.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]);
}
}

Expand Down
12 changes: 9 additions & 3 deletions apps/accessibility/lib/Controller/AccessibilityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function __construct(string $appName,
}

/**
* @NoAdminRequired
* @PublicPage
* @NoCSRFRequired
* @NoSameSiteCookieRequired
*
Expand All @@ -140,7 +140,11 @@ public function __construct(string $appName,
public function getCss(): DataDisplayResponse {
$css = '';
$imports = '';
$userValues = $this->getUserValues();
if ($this->userSession->isLoggedIn()) {
$userValues = $this->getUserValues();
} else {
$userValues = ['dark'];
}

foreach ($userValues as $key => $scssFile) {
if ($scssFile !== false) {
Expand Down Expand Up @@ -199,7 +203,9 @@ public function getCss(): DataDisplayResponse {
$response->addHeader('Pragma', 'cache');

// store current cache hash
$this->config->setUserValue($this->userSession->getUser()->getUID(), $this->appName, 'icons-css', md5($css));
if ($this->userSession->isLoggedIn()) {
$this->config->setUserValue($this->userSession->getUser()->getUID(), $this->appName, 'icons-css', md5($css));
}

return $response;
}
Expand Down

0 comments on commit 2916402

Please sign in to comment.