diff options
author | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2022-04-28 12:04:25 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-28 12:04:25 +0300 |
commit | 9a832df62f14a3301ec76fe043ee2cd9c7d7f5b2 (patch) | |
tree | 694ab6660c05cadb21db1ae33a3933ef6d2d73f8 /apps/theming | |
parent | c2d9c2b93e5718c5fb8c56f7d5ab64bddd292e5a (diff) | |
parent | 4a646789c37eda99d431de84a2c4c5fed6c46152 (diff) |
Merge pull request #32195 from nextcloud/feat/system-theme
Diffstat (limited to 'apps/theming')
-rw-r--r-- | apps/theming/img/default-source.svg | 13 | ||||
-rw-r--r-- | apps/theming/img/default.jpg | bin | 391078 -> 57394 bytes | |||
-rw-r--r-- | apps/theming/img/light.jpg | bin | 0 -> 391078 bytes | |||
-rw-r--r-- | apps/theming/lib/Service/ThemesService.php | 3 | ||||
-rw-r--r-- | apps/theming/lib/Themes/DefaultTheme.php | 6 | ||||
-rw-r--r-- | apps/theming/lib/Themes/LightTheme.php | 61 | ||||
-rw-r--r-- | apps/theming/tests/Controller/UserThemeControllerTest.php | 3 | ||||
-rw-r--r-- | apps/theming/tests/Service/ThemesServiceTest.php | 11 | ||||
-rw-r--r-- | apps/theming/tests/Themes/DefaultThemeTest.php | 6 |
9 files changed, 97 insertions, 6 deletions
diff --git a/apps/theming/img/default-source.svg b/apps/theming/img/default-source.svg new file mode 100644 index 00000000000..89711e2a0c8 --- /dev/null +++ b/apps/theming/img/default-source.svg @@ -0,0 +1,13 @@ +<svg width="800" height="500" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"> + <!-- Use this file to generate the default.jpg theme preview --> + + <!-- Half rectangle light mask --> + <defs><mask id="a"><path d="M0 0h800L0 500Z" fill="#fff"/></mask></defs> + <!-- Dark and light images link --> + <image width="800" height="500" xlink:href="dark.jpg"/> + <image width="800" height="500" xlink:href="light.jpg" mask="url(#a)" fill="#fff"/> + <!-- White opacity layer --> + <path fill="#fff" opacity=".35" d="M0 0h800v500H0z"/> + <!-- Moon/sun icon --> + <path d="M358.82 162.36a58 58 0 0 0-26.63 48.81c0 20.6 10.74 38.6 26.9 48.81A48.85 48.85 0 0 1 310 211.17a48.82 48.81 0 0 1 48.82-48.81m102.69 13.3 12.7 12.7L336 326.55l-12.7-12.7 138.2-138.18m-54.85 21.57-13.14-8.26-12.78 8.88 3.73-15.1-12.34-9.4 15.53-1.06 5.15-14.65 5.95 14.47 15.35.27-11.98 10.02 4.53 14.83m-29.3 32.04-10.29-6.48-9.94 6.92 3.02-11.72-9.68-7.36 12.07-.8 4-11.45 4.53 11.27 12.07.27-9.32 7.72 3.55 11.63m83.52 35.14a48.82 48.81 0 0 1-48.82 48.82 48.7 48.7 0 0 1-28.93-9.5l68.25-68.25a48.7 48.7 0 0 1 9.5 28.93m-39.06 58.4 24.59-10.2-2.13 29.73-22.46-19.53m38.44-23.96 10.2-24.59L490 296.82l-29.73 2.04m10.2-44.02-10.11-24.68L490 232.3l-19.53 22.55m-92.75 57.78 24.59 10.2-22.46 19.44z" stroke="#000"/> +</svg> diff --git a/apps/theming/img/default.jpg b/apps/theming/img/default.jpg Binary files differindex ad3fafd96f2..bbea0e905b9 100644 --- a/apps/theming/img/default.jpg +++ b/apps/theming/img/default.jpg diff --git a/apps/theming/img/light.jpg b/apps/theming/img/light.jpg Binary files differnew file mode 100644 index 00000000000..ad3fafd96f2 --- /dev/null +++ b/apps/theming/img/light.jpg diff --git a/apps/theming/lib/Service/ThemesService.php b/apps/theming/lib/Service/ThemesService.php index 01ebc3fb504..43977721e76 100644 --- a/apps/theming/lib/Service/ThemesService.php +++ b/apps/theming/lib/Service/ThemesService.php @@ -29,6 +29,7 @@ use OCA\Theming\Themes\DarkTheme; use OCA\Theming\Themes\DefaultTheme; use OCA\Theming\Themes\DyslexiaFont; use OCA\Theming\Themes\HighContrastTheme; +use OCA\Theming\Themes\LightTheme; use OCP\IConfig; use OCP\IUser; use OCP\IUserSession; @@ -43,6 +44,7 @@ class ThemesService { public function __construct(IUserSession $userSession, IConfig $config, DefaultTheme $defaultTheme, + LightTheme $lightTheme, DarkTheme $darkTheme, HighContrastTheme $highContrastTheme, DarkHighContrastTheme $darkHighContrastTheme, @@ -53,6 +55,7 @@ class ThemesService { // Register themes $this->themesProviders = [ $defaultTheme->getId() => $defaultTheme, + $lightTheme->getId() => $lightTheme, $darkTheme->getId() => $darkTheme, $highContrastTheme->getId() => $highContrastTheme, $darkHighContrastTheme->getId() => $darkHighContrastTheme, diff --git a/apps/theming/lib/Themes/DefaultTheme.php b/apps/theming/lib/Themes/DefaultTheme.php index 191cb5814af..b13e481907a 100644 --- a/apps/theming/lib/Themes/DefaultTheme.php +++ b/apps/theming/lib/Themes/DefaultTheme.php @@ -67,15 +67,15 @@ class DefaultTheme implements ITheme { } public function getTitle(): string { - return $this->l->t('Light theme'); + return $this->l->t('System default theme'); } public function getEnableLabel(): string { - return $this->l->t('Enable the default light theme'); + return $this->l->t('Enable the system default'); } public function getDescription(): string { - return $this->l->t('The default light appearance.'); + return $this->l->t('Using the default system appearance.'); } public function getMediaQuery(): string { diff --git a/apps/theming/lib/Themes/LightTheme.php b/apps/theming/lib/Themes/LightTheme.php new file mode 100644 index 00000000000..e988f612226 --- /dev/null +++ b/apps/theming/lib/Themes/LightTheme.php @@ -0,0 +1,61 @@ +<?php +declare(strict_types=1); +/** + * @copyright Copyright (c) 2022 Joas Schilling <coding@schilljs.com> + * + * @author Joas Schilling <coding@schilljs.com> + * @author John Molakvoæ <skjnldsv@protonmail.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +namespace OCA\Theming\Themes; + +use OCA\Theming\ImageManager; +use OCA\Theming\ThemingDefaults; +use OCA\Theming\Util; +use OCA\Theming\ITheme; +use OCA\Theming\Themes\DefaultTheme; +use OCP\IConfig; +use OCP\IL10N; +use OCP\IURLGenerator; + +class LightTheme extends DefaultTheme implements ITheme { + + public function getId(): string { + return 'light'; + } + + public function getType(): int { + return ITheme::TYPE_THEME; + } + + public function getTitle(): string { + return $this->l->t('Light theme'); + } + + public function getEnableLabel(): string { + return $this->l->t('Enable the default light theme'); + } + + public function getDescription(): string { + return $this->l->t('The default light appearance.'); + } + + public function getMediaQuery(): string { + return '(prefers-color-scheme: light)'; + } +} diff --git a/apps/theming/tests/Controller/UserThemeControllerTest.php b/apps/theming/tests/Controller/UserThemeControllerTest.php index b925085bf41..952cd012210 100644 --- a/apps/theming/tests/Controller/UserThemeControllerTest.php +++ b/apps/theming/tests/Controller/UserThemeControllerTest.php @@ -30,6 +30,7 @@ use OCA\Theming\Themes\DefaultTheme; use OCA\Theming\Themes\DyslexiaFont; use OCA\Theming\Themes\HighContrastTheme; use OCA\Theming\Service\ThemesService; +use OCA\Theming\Themes\LightTheme; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCS\OCSBadRequestException; use OCP\IConfig; @@ -63,6 +64,7 @@ class UserThemeControllerTest extends TestCase { $this->themes = [ 'default' => $this->createMock(DefaultTheme::class), + 'light' => $this->createMock(LightTheme::class), 'dark' => $this->createMock(DarkTheme::class), 'highcontrast' => $this->createMock(HighContrastTheme::class), 'dark-highcontrast' => $this->createMock(DarkHighContrastTheme::class), @@ -91,6 +93,7 @@ class UserThemeControllerTest extends TestCase { public function dataTestThemes() { return [ ['default'], + ['light'], ['dark'], ['highcontrast'], ['dark-highcontrast'], diff --git a/apps/theming/tests/Service/ThemesServiceTest.php b/apps/theming/tests/Service/ThemesServiceTest.php index 56f96d29637..5865875cbb8 100644 --- a/apps/theming/tests/Service/ThemesServiceTest.php +++ b/apps/theming/tests/Service/ThemesServiceTest.php @@ -31,6 +31,7 @@ use OCA\Theming\Themes\DefaultTheme; use OCA\Theming\Themes\DyslexiaFont; use OCA\Theming\Themes\HighContrastTheme; use OCA\Theming\Service\ThemesService; +use OCA\Theming\Themes\LightTheme; use OCA\Theming\ThemingDefaults; use OCA\Theming\Util; use OCP\AppFramework\Http\DataResponse; @@ -81,6 +82,7 @@ class ThemesServiceTest extends TestCase { public function testGetThemes() { $expected = [ 'default', + 'light', 'dark', 'highcontrast', 'dark-highcontrast', @@ -92,6 +94,7 @@ class ThemesServiceTest extends TestCase { public function dataTestEnableTheme() { return [ + ['default', [], ['default']], ['dark', [], ['dark']], ['dark', ['dark'], ['dark']], ['opendyslexic', ['dark'], ['dark', 'opendyslexic']], @@ -207,6 +210,14 @@ class ThemesServiceTest extends TestCase { $this->config, $l10n, ), + 'light' => new LightTheme( + $util, + $this->themingDefaults, + $urlGenerator, + $imageManager, + $this->config, + $l10n, + ), 'dark' => new DarkTheme( $util, $this->themingDefaults, diff --git a/apps/theming/tests/Themes/DefaultThemeTest.php b/apps/theming/tests/Themes/DefaultThemeTest.php index b9302bb4c95..160efdba142 100644 --- a/apps/theming/tests/Themes/DefaultThemeTest.php +++ b/apps/theming/tests/Themes/DefaultThemeTest.php @@ -97,15 +97,15 @@ class DefaultThemeTest extends TestCase { } public function testGetTitle() { - $this->assertEquals('Light theme', $this->defaultTheme->getTitle()); + $this->assertEquals('System default theme', $this->defaultTheme->getTitle()); } public function testGetEnableLabel() { - $this->assertEquals('Enable the default light theme', $this->defaultTheme->getEnableLabel()); + $this->assertEquals('Enable the system default', $this->defaultTheme->getEnableLabel()); } public function testGetDescription() { - $this->assertEquals('The default light appearance.', $this->defaultTheme->getDescription()); + $this->assertEquals('Using the default system appearance.', $this->defaultTheme->getDescription()); } public function testGetMediaQuery() { |