Respect "prefers-color-scheme" media selector for guests

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2020-06-10 23:47:01 +02:00
parent 9806dec9b3
commit 291640273d
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
2 changed files with 15 additions and 3 deletions

View File

@ -63,6 +63,12 @@ class Application extends App {
$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]);
}
}

View File

@ -131,7 +131,7 @@ class AccessibilityController extends Controller {
}
/**
* @NoAdminRequired
* @PublicPage
* @NoCSRFRequired
* @NoSameSiteCookieRequired
*
@ -140,7 +140,11 @@ class AccessibilityController extends Controller {
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) {
@ -199,7 +203,9 @@ class AccessibilityController extends Controller {
$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;
}