diff options
Diffstat (limited to 'apps/theming')
-rw-r--r-- | apps/theming/lib/ITheme.php | 8 | ||||
-rw-r--r-- | apps/theming/lib/Service/ThemeInjectionService.php | 51 | ||||
-rw-r--r-- | apps/theming/lib/Themes/DarkHighContrastTheme.php | 8 | ||||
-rw-r--r-- | apps/theming/lib/Themes/DarkTheme.php | 16 | ||||
-rw-r--r-- | apps/theming/lib/Themes/DefaultTheme.php | 4 | ||||
-rw-r--r-- | apps/theming/lib/Themes/HighContrastTheme.php | 8 | ||||
-rw-r--r-- | apps/theming/lib/Themes/LightTheme.php | 12 |
7 files changed, 23 insertions, 84 deletions
diff --git a/apps/theming/lib/ITheme.php b/apps/theming/lib/ITheme.php index 4ff455005a2..3c3b081aec5 100644 --- a/apps/theming/lib/ITheme.php +++ b/apps/theming/lib/ITheme.php @@ -72,14 +72,6 @@ interface ITheme { public function getDescription(): string; /** - * Get the meta attribute matching the theme - * e.g. https://html.spec.whatwg.org/multipage/semantics.html#meta-color-scheme - * @return array{name?: string, content?: string}[] - * @since 29.0.0 - */ - public function getMeta(): array; - - /** * Get the media query triggering this theme * Optional, ignored if falsy * diff --git a/apps/theming/lib/Service/ThemeInjectionService.php b/apps/theming/lib/Service/ThemeInjectionService.php index 169bc0c0223..c7560bdf8f8 100644 --- a/apps/theming/lib/Service/ThemeInjectionService.php +++ b/apps/theming/lib/Service/ThemeInjectionService.php @@ -22,7 +22,6 @@ */ namespace OCA\Theming\Service; -use OCA\Theming\ITheme; use OCA\Theming\Themes\DefaultTheme; use OCA\Theming\Util; use OCP\IConfig; @@ -49,7 +48,6 @@ class ThemeInjectionService { $this->defaultTheme = $defaultTheme; $this->util = $util; $this->config = $config; - if ($userSession->getUser() !== null) { $this->userId = $userSession->getUser()->getUID(); } else { @@ -57,7 +55,7 @@ class ThemeInjectionService { } } - public function injectHeaders(): void { + public function injectHeaders() { $themes = $this->themesService->getThemes(); $defaultTheme = $themes[$this->defaultTheme->getId()]; $mediaThemes = array_filter($themes, function ($theme) { @@ -66,11 +64,11 @@ class ThemeInjectionService { }); // Default theme fallback - $this->addThemeHeaders($defaultTheme); + $this->addThemeHeader($defaultTheme->getId()); // Themes applied by media queries foreach($mediaThemes as $theme) { - $this->addThemeHeaders($theme, true, $theme->getMediaQuery()); + $this->addThemeHeader($theme->getId(), true, $theme->getMediaQuery()); } // Themes @@ -79,23 +77,20 @@ class ThemeInjectionService { if ($theme->getId() === $this->defaultTheme->getId()) { continue; } - $this->addThemeHeaders($theme, false); + $this->addThemeHeader($theme->getId(), false); } - - // Meta headers - $this->addThemeMetaHeaders($themes); } /** * Inject theme header into rendered page * - * @param ITheme $theme the theme + * @param string $themeId the theme ID * @param bool $plain request the :root syntax * @param string $media media query to use in the <link> element */ - private function addThemeHeaders(ITheme $theme, bool $plain = true, string $media = null): void { + private function addThemeHeader(string $themeId, bool $plain = true, string $media = null) { $linkToCSS = $this->urlGenerator->linkToRoute('theming.Theming.getThemeStylesheet', [ - 'themeId' => $theme->getId(), + 'themeId' => $themeId, 'plain' => $plain, 'v' => $this->util->getCacheBuster(), ]); @@ -106,36 +101,4 @@ class ThemeInjectionService { 'class' => 'theme' ]); } - - /** - * Inject meta headers into rendered page - * - * @param ITheme[] $themes the theme - */ - private function addThemeMetaHeaders(array $themes): void { - $metaHeaders = []; - - // Meta headers - foreach($this->themesService->getThemes() as $theme) { - if (!empty($theme->getMeta())) { - foreach($theme->getMeta() as $meta) { - if (!isset($meta['name']) || !isset($meta['content'])) { - continue; - } - - if (!isset($metaHeaders[$meta['name']])) { - $metaHeaders[$meta['name']] = []; - } - $metaHeaders[$meta['name']][] = $meta['content']; - } - } - } - - foreach($metaHeaders as $name => $content) { - \OCP\Util::addHeader('meta', [ - 'name' => $name, - 'content' => join(' ', array_unique($content)), - ]); - } - } } diff --git a/apps/theming/lib/Themes/DarkHighContrastTheme.php b/apps/theming/lib/Themes/DarkHighContrastTheme.php index e6f1da94b4e..965dac2922c 100644 --- a/apps/theming/lib/Themes/DarkHighContrastTheme.php +++ b/apps/theming/lib/Themes/DarkHighContrastTheme.php @@ -33,6 +33,10 @@ class DarkHighContrastTheme extends DarkTheme implements ITheme { return 'dark-highcontrast'; } + public function getMediaQuery(): string { + return '(prefers-color-scheme: dark) and (prefers-contrast: more)'; + } + public function getTitle(): string { return $this->l->t('Dark theme with high contrast mode'); } @@ -45,10 +49,6 @@ class DarkHighContrastTheme extends DarkTheme implements ITheme { return $this->l->t('Similar to the high contrast mode, but with dark colours.'); } - public function getMediaQuery(): string { - return '(prefers-color-scheme: dark) and (prefers-contrast: more)'; - } - /** * Keep this consistent with other HighContrast Themes */ diff --git a/apps/theming/lib/Themes/DarkTheme.php b/apps/theming/lib/Themes/DarkTheme.php index a40f8009e17..f63854289ad 100644 --- a/apps/theming/lib/Themes/DarkTheme.php +++ b/apps/theming/lib/Themes/DarkTheme.php @@ -33,6 +33,10 @@ class DarkTheme extends DefaultTheme implements ITheme { return 'dark'; } + public function getMediaQuery(): string { + return '(prefers-color-scheme: dark)'; + } + public function getTitle(): string { return $this->l->t('Dark theme'); } @@ -45,18 +49,6 @@ class DarkTheme extends DefaultTheme implements ITheme { return $this->l->t('A dark theme to ease your eyes by reducing the overall luminosity and brightness.'); } - public function getMediaQuery(): string { - return '(prefers-color-scheme: dark)'; - } - - public function getMeta(): array { - // https://html.spec.whatwg.org/multipage/semantics.html#meta-color-scheme - return [[ - 'name' => 'color-scheme', - 'content' => 'dark', - ]]; - } - public function getCSSVariables(): array { $defaultVariables = parent::getCSSVariables(); diff --git a/apps/theming/lib/Themes/DefaultTheme.php b/apps/theming/lib/Themes/DefaultTheme.php index af1489c3577..3dfa89f8d3a 100644 --- a/apps/theming/lib/Themes/DefaultTheme.php +++ b/apps/theming/lib/Themes/DefaultTheme.php @@ -101,10 +101,6 @@ class DefaultTheme implements ITheme { return ''; } - public function getMeta(): array { - return []; - } - public function getCSSVariables(): array { $colorMainText = '#222222'; $colorMainTextRgb = join(',', $this->util->hexToRGB($colorMainText)); diff --git a/apps/theming/lib/Themes/HighContrastTheme.php b/apps/theming/lib/Themes/HighContrastTheme.php index b1c2bf1564f..92511b59c81 100644 --- a/apps/theming/lib/Themes/HighContrastTheme.php +++ b/apps/theming/lib/Themes/HighContrastTheme.php @@ -33,6 +33,10 @@ class HighContrastTheme extends DefaultTheme implements ITheme { return 'light-highcontrast'; } + public function getMediaQuery(): string { + return '(prefers-contrast: more)'; + } + public function getTitle(): string { return $this->l->t('High contrast mode'); } @@ -45,10 +49,6 @@ class HighContrastTheme extends DefaultTheme implements ITheme { return $this->l->t('A high contrast mode to ease your navigation. Visual quality will be reduced but clarity will be increased.'); } - public function getMediaQuery(): string { - return '(prefers-contrast: more)'; - } - /** * Keep this consistent with other HighContrast Themes */ diff --git a/apps/theming/lib/Themes/LightTheme.php b/apps/theming/lib/Themes/LightTheme.php index 7e6773992a1..320f8334147 100644 --- a/apps/theming/lib/Themes/LightTheme.php +++ b/apps/theming/lib/Themes/LightTheme.php @@ -33,6 +33,10 @@ class LightTheme extends DefaultTheme implements ITheme { return 'light'; } + public function getType(): int { + return ITheme::TYPE_THEME; + } + public function getTitle(): string { return $this->l->t('Light theme'); } @@ -48,12 +52,4 @@ class LightTheme extends DefaultTheme implements ITheme { public function getMediaQuery(): string { return '(prefers-color-scheme: light)'; } - - public function getMeta(): array { - // https://html.spec.whatwg.org/multipage/semantics.html#meta-color-scheme - return [[ - 'name' => 'color-scheme', - 'content' => 'light', - ]]; - } } |