Skip to content

Commit

Permalink
Fix accessibility theme for guests
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen authored and backportbot[bot] committed Jul 9, 2021
1 parent 31f0593 commit fe9867b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/accessibility/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public function injectCss(IUserSession $userSession,
$hash = md5(implode('-', $userValues));
$linkToCSS = $urlGenerator->linkToRoute(self::APP_ID . '.accessibility.getCss', ['md5' => $hash]);
\OCP\Util::addHeader('link', ['rel' => 'stylesheet', 'media' => '(prefers-color-scheme: dark)', 'href' => $linkToCSS]);
\OCP\Util::addScript('accessibility', 'accessibilityoca');
}
}
}
1 change: 1 addition & 0 deletions apps/accessibility/lib/Service/JSDataService.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function getData() {
}

return [
'checkMedia' => $user === null,
'theme' => $theme,
'highcontrast' => $highcontrast,
];
Expand Down
5 changes: 5 additions & 0 deletions apps/accessibility/src/accessibilityoca.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
import { loadState } from '@nextcloud/initial-state'

OCA.Accessibility = loadState('accessibility', 'data')
if (OCA.Accessibility.checkMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
// Overwrite the theme for Guests based on the prefers-color-scheme
OCA.Accessibility.theme = 'dark'
}

if (OCA.Accessibility.theme !== false) {
document.body.classList.add(`theme--${OCA.Accessibility.theme}`)
} else {
Expand Down

0 comments on commit fe9867b

Please sign in to comment.