]> source.dussan.org Git - nextcloud-server.git/commitdiff
Use color preset of shipped background as primary color
authorChristopher Ng <chrng8@gmail.com>
Wed, 28 Sep 2022 02:35:51 +0000 (02:35 +0000)
committerChristopher Ng <chrng8@gmail.com>
Wed, 5 Oct 2022 06:19:08 +0000 (06:19 +0000)
Signed-off-by: Christopher Ng <chrng8@gmail.com>
apps/theming/css/default.css
apps/theming/lib/Themes/DefaultTheme.php
apps/theming/lib/ThemingDefaults.php
apps/theming/tests/Service/ThemesServiceTest.php
apps/theming/tests/Settings/PersonalTest.php
apps/theming/tests/Themes/DefaultThemeTest.php
apps/theming/tests/Themes/DyslexiaFontTest.php
apps/theming/tests/ThemingDefaultsTest.php
lib/private/Server.php

index e7403ee69cca7c754bc0e34ea97ecef7445b7496..56c2e41781f26035f91d79ef49d60e707532a9ed 100644 (file)
   --background-invert-if-dark: no;
   --background-invert-if-bright: invert(100%);
   --image-main-background: url('/core/img/app-background.jpg');
-  --color-primary: #0082c9;
+  --color-primary: #00639a;
   --color-primary-text: #ffffff;
-  --color-primary-hover: #329bd3;
-  --color-primary-light: #e5f2f9;
-  --color-primary-light-text: #003450;
-  --color-primary-light-hover: #dbe7ee;
+  --color-primary-hover: #3282ae;
+  --color-primary-light: #e5eff4;
+  --color-primary-light-text: #00273d;
+  --color-primary-light-hover: #dbe4e9;
   --color-primary-text-dark: #ededed;
-  --color-primary-element: #0082c9;
+  --color-primary-element: #00639a;
   --color-primary-element-text: #ffffff;
-  --color-primary-element-hover: #329bd3;
-  --color-primary-element-light: #e5f2f9;
-  --color-primary-element-light-text: #003450;
-  --color-primary-element-light-hover: #dbe7ee;
+  --color-primary-element-hover: #3282ae;
+  --color-primary-element-light: #e5eff4;
+  --color-primary-element-light-text: #00273d;
+  --color-primary-element-light-hover: #dbe4e9;
   --color-primary-element-text-dark: #ededed;
   --gradient-primary-background: linear-gradient(40deg, var(--color-primary) 0%, var(--color-primary-hover) 100%);
 }
index 203e03757c854639c9dcaf4d9c20effbc2e0a1a7..d338c40ac5e4d70b7b0a2150f9ab091c24b8a9cd 100644 (file)
@@ -27,6 +27,7 @@ namespace OCA\Theming\Themes;
 use OCA\Theming\AppInfo\Application;
 use OCA\Theming\ImageManager;
 use OCA\Theming\ITheme;
+use OCA\Theming\Service\BackgroundService;
 use OCA\Theming\ThemingDefaults;
 use OCA\Theming\Util;
 use OCP\App\IAppManager;
@@ -41,6 +42,7 @@ class DefaultTheme implements ITheme {
 
        public Util $util;
        public ThemingDefaults $themingDefaults;
+       public IUserSession $userSession;
        public IURLGenerator $urlGenerator;
        public ImageManager $imageManager;
        public IConfig $config;
@@ -50,12 +52,14 @@ class DefaultTheme implements ITheme {
 
        public function __construct(Util $util,
                                                                ThemingDefaults $themingDefaults,
+                                                               IUserSession $userSession,
                                                                IURLGenerator $urlGenerator,
                                                                ImageManager $imageManager,
                                                                IConfig $config,
                                                                IL10N $l) {
                $this->util = $util;
                $this->themingDefaults = $themingDefaults;
+               $this->userSession = $userSession;
                $this->urlGenerator = $urlGenerator;
                $this->imageManager = $imageManager;
                $this->config = $config;
@@ -221,19 +225,15 @@ class DefaultTheme implements ITheme {
                }
 
                $appManager = Server::get(IAppManager::class);
-               $userSession = Server::get(IUserSession::class);
-               $user = $userSession->getUser();
+               $user = $this->userSession->getUser();
                if ($appManager->isEnabledForUser(Application::APP_ID) && $user !== null) {
                        $themingBackground = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background', 'default');
 
                        if ($themingBackground === 'custom') {
-                               // Custom
                                $variables['--image-main-background'] = "url('" . $this->urlGenerator->linkToRouteAbsolute('theming.userTheme.getBackground') . "')";
-                       } elseif ($themingBackground !== 'default' && substr($themingBackground, 0, 1) !== '#') {
-                               // Shipped background
+                       } elseif (isset(BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground])) {
                                $variables['--image-main-background'] = "url('" . $this->urlGenerator->linkTo(Application::APP_ID, "/img/background/$themingBackground") . "')";
                        } elseif (substr($themingBackground, 0, 1) === '#') {
-                               // Color
                                unset($variables['--image-main-background']);
                                $variables['--color-main-background-plain'] = $this->primaryColor;
                        }
index 3d7aaee2064a3bd0ba9beb84faae0e0054246473..61001770302fb153d7717c54b5bc41560c16be4b 100644 (file)
@@ -40,6 +40,8 @@
  */
 namespace OCA\Theming;
 
+use OCA\Theming\AppInfo\Application;
+use OCA\Theming\Service\BackgroundService;
 use OCP\App\AppPathNotFoundException;
 use OCP\App\IAppManager;
 use OCP\Files\NotFoundException;
@@ -49,47 +51,31 @@ use OCP\IConfig;
 use OCP\IL10N;
 use OCP\INavigationManager;
 use OCP\IURLGenerator;
+use OCP\IUserSession;
 
 class ThemingDefaults extends \OC_Defaults {
 
-       /** @var IConfig */
-       private $config;
-       /** @var IL10N */
-       private $l;
-       /** @var ImageManager */
-       private $imageManager;
-       /** @var IURLGenerator */
-       private $urlGenerator;
-       /** @var ICacheFactory */
-       private $cacheFactory;
-       /** @var Util */
-       private $util;
-       /** @var IAppManager */
-       private $appManager;
-       /** @var INavigationManager */
-       private $navigationManager;
-
-       /** @var string */
-       private $name;
-       /** @var string */
-       private $title;
-       /** @var string */
-       private $entity;
-       /** @var string */
-       private $productName;
-       /** @var string */
-       private $url;
-       /** @var string */
-       private $color;
-
-       /** @var string */
-       private $iTunesAppId;
-       /** @var string */
-       private $iOSClientUrl;
-       /** @var string */
-       private $AndroidClientUrl;
-       /** @var string */
-       private $FDroidClientUrl;
+       private IConfig $config;
+       private IL10N $l;
+       private ImageManager $imageManager;
+       private IUserSession $userSession;
+       private IURLGenerator $urlGenerator;
+       private ICacheFactory $cacheFactory;
+       private Util $util;
+       private IAppManager $appManager;
+       private INavigationManager $navigationManager;
+
+       private string $name;
+       private string $title;
+       private string $entity;
+       private string $productName;
+       private string $url;
+       private string $color;
+
+       private string $iTunesAppId;
+       private string $iOSClientUrl;
+       private string $AndroidClientUrl;
+       private string $FDroidClientUrl;
 
        /**
         * ThemingDefaults constructor.
@@ -97,6 +83,7 @@ class ThemingDefaults extends \OC_Defaults {
         * @param IConfig $config
         * @param IL10N $l
         * @param ImageManager $imageManager
+        * @param IUserSession $userSession
         * @param IURLGenerator $urlGenerator
         * @param ICacheFactory $cacheFactory
         * @param Util $util
@@ -104,6 +91,7 @@ class ThemingDefaults extends \OC_Defaults {
         */
        public function __construct(IConfig $config,
                                                                IL10N $l,
+                                                               IUserSession $userSession,
                                                                IURLGenerator $urlGenerator,
                                                                ICacheFactory $cacheFactory,
                                                                Util $util,
@@ -115,6 +103,7 @@ class ThemingDefaults extends \OC_Defaults {
                $this->config = $config;
                $this->l = $l;
                $this->imageManager = $imageManager;
+               $this->userSession = $userSession;
                $this->urlGenerator = $urlGenerator;
                $this->cacheFactory = $cacheFactory;
                $this->util = $util;
@@ -229,10 +218,24 @@ class ThemingDefaults extends \OC_Defaults {
         * @return string
         */
        public function getColorPrimary() {
-               $color = $this->config->getAppValue('theming', 'color', $this->color);
+               $user = $this->userSession->getUser();
+               $color = $this->config->getAppValue(Application::APP_ID, 'color', '');
+
+               if ($color === '' && !empty($user)) {
+                       $themingBackground = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background', 'default');
+                       if (isset(BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground]['primary_color'])) {
+                               $this->increaseCacheBuster();
+                               return BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground]['primary_color'];
+                       } else if ($themingBackground === 'default') {
+                               $this->increaseCacheBuster();
+                               return BackgroundService::SHIPPED_BACKGROUNDS['kamil-porembinski-clouds.jpg']['primary_color'];
+                       }
+               }
+
                if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $color)) {
-                       $color = '#0082c9';
+                       return BackgroundService::SHIPPED_BACKGROUNDS['kamil-porembinski-clouds.jpg']['primary_color'];
                }
+
                return $color;
        }
 
index 3be8881669a828c3fc448054571767fea0f1a232..5a2907ec0733c18a3f84911050c84926d345c26e 100644 (file)
@@ -156,7 +156,7 @@ class ThemesServiceTest extends TestCase {
                        ->method('getUserValue')
                        ->with('user', Application::APP_ID, 'enabled-themes', '[]')
                        ->willReturn(json_encode($enabledThemes));
-       
+
 
                $this->assertEquals($expectedEnabled, $this->themesService->disableTheme($this->themes[$toDisable]));
        }
@@ -190,7 +190,7 @@ class ThemesServiceTest extends TestCase {
                        ->method('getUserValue')
                        ->with('user', Application::APP_ID, 'enabled-themes', '[]')
                        ->willReturn(json_encode($enabledThemes));
-       
+
 
                $this->assertEquals($expected, $this->themesService->isEnabled($this->themes[$themeId]));
        }
@@ -281,6 +281,7 @@ class ThemesServiceTest extends TestCase {
                        'default' => new DefaultTheme(
                                $util,
                                $this->themingDefaults,
+                               $this->userSession,
                                $urlGenerator,
                                $imageManager,
                                $this->config,
@@ -289,6 +290,7 @@ class ThemesServiceTest extends TestCase {
                        'light' => new LightTheme(
                                $util,
                                $this->themingDefaults,
+                               $this->userSession,
                                $urlGenerator,
                                $imageManager,
                                $this->config,
@@ -297,6 +299,7 @@ class ThemesServiceTest extends TestCase {
                        'dark' => new DarkTheme(
                                $util,
                                $this->themingDefaults,
+                               $this->userSession,
                                $urlGenerator,
                                $imageManager,
                                $this->config,
@@ -305,6 +308,7 @@ class ThemesServiceTest extends TestCase {
                        'light-highcontrast' => new HighContrastTheme(
                                $util,
                                $this->themingDefaults,
+                               $this->userSession,
                                $urlGenerator,
                                $imageManager,
                                $this->config,
@@ -313,6 +317,7 @@ class ThemesServiceTest extends TestCase {
                        'dark-highcontrast' => new DarkHighContrastTheme(
                                $util,
                                $this->themingDefaults,
+                               $this->userSession,
                                $urlGenerator,
                                $imageManager,
                                $this->config,
@@ -321,6 +326,7 @@ class ThemesServiceTest extends TestCase {
                        'opendyslexic' => new DyslexiaFont(
                                $util,
                                $this->themingDefaults,
+                               $this->userSession,
                                $urlGenerator,
                                $imageManager,
                                $this->config,
index 8e121c0a057419e8c3314da25bbe8eff3999ce97..0cb289cb86ade4c83bd2bb91e749c18281989596 100644 (file)
@@ -45,6 +45,7 @@ use OCP\AppFramework\Services\IInitialState;
 use OCP\IConfig;
 use OCP\IL10N;
 use OCP\IURLGenerator;
+use OCP\IUserSession;
 use Test\TestCase;
 
 class PersonalTest extends TestCase {
@@ -128,6 +129,7 @@ class PersonalTest extends TestCase {
        private function initThemes() {
                $util = $this->createMock(Util::class);
                $themingDefaults = $this->createMock(ThemingDefaults::class);
+               $userSession = $this->createMock(IUserSession::class);
                $urlGenerator = $this->createMock(IURLGenerator::class);
                $imageManager = $this->createMock(ImageManager::class);
                $config = $this->createMock(IConfig::class);
@@ -141,6 +143,7 @@ class PersonalTest extends TestCase {
                        'default' => new DefaultTheme(
                                $util,
                                $themingDefaults,
+                               $userSession,
                                $urlGenerator,
                                $imageManager,
                                $config,
@@ -149,6 +152,7 @@ class PersonalTest extends TestCase {
                        'light' => new LightTheme(
                                $util,
                                $themingDefaults,
+                               $userSession,
                                $urlGenerator,
                                $imageManager,
                                $config,
@@ -157,6 +161,7 @@ class PersonalTest extends TestCase {
                        'dark' => new DarkTheme(
                                $util,
                                $themingDefaults,
+                               $userSession,
                                $urlGenerator,
                                $imageManager,
                                $config,
@@ -165,6 +170,7 @@ class PersonalTest extends TestCase {
                        'light-highcontrast' => new HighContrastTheme(
                                $util,
                                $themingDefaults,
+                               $userSession,
                                $urlGenerator,
                                $imageManager,
                                $config,
@@ -173,6 +179,7 @@ class PersonalTest extends TestCase {
                        'dark-highcontrast' => new DarkHighContrastTheme(
                                $util,
                                $themingDefaults,
+                               $userSession,
                                $urlGenerator,
                                $imageManager,
                                $config,
@@ -181,6 +188,7 @@ class PersonalTest extends TestCase {
                        'opendyslexic' => new DyslexiaFont(
                                $util,
                                $themingDefaults,
+                               $userSession,
                                $urlGenerator,
                                $imageManager,
                                $config,
index 84430360897ab38bf4917ce56e25ed22c58eb212..c1de2810396e7c191e89bd69acb537b6f4ec83dc 100644 (file)
@@ -32,6 +32,7 @@ use OCP\Files\IAppData;
 use OCP\IConfig;
 use OCP\IL10N;
 use OCP\IURLGenerator;
+use OCP\IUserSession;
 use PHPUnit\Framework\MockObject\MockObject;
 use Test\TestCase;
 
@@ -52,6 +53,7 @@ class DefaultThemeTest extends TestCase {
 
        protected function setUp(): void {
                $this->themingDefaults = $this->createMock(ThemingDefaults::class);
+               $this->userSession = $this->createMock(IUserSession::class);
                $this->urlGenerator = $this->createMock(IURLGenerator::class);
                $this->imageManager = $this->createMock(ImageManager::class);
                $this->config = $this->createMock(IConfig::class);
@@ -85,6 +87,7 @@ class DefaultThemeTest extends TestCase {
                $this->defaultTheme = new DefaultTheme(
                        $util,
                        $this->themingDefaults,
+                       $this->userSession,
                        $this->urlGenerator,
                        $this->imageManager,
                        $this->config,
index 30472aeb6f267369c37a838c98b5a16639a95306..77eb77a281894621a02f78ba7ee6d2d46f763ec8 100644 (file)
@@ -56,6 +56,7 @@ class DyslexiaFontTest extends TestCase {
 
        protected function setUp(): void {
                $this->themingDefaults = $this->createMock(ThemingDefaults::class);
+               $this->userSession = $this->createMock(IUserSession::class);
                $this->imageManager = $this->createMock(ImageManager::class);
                $this->config = $this->createMock(IConfig::class);
                $this->l10n = $this->createMock(IL10N::class);
@@ -93,6 +94,7 @@ class DyslexiaFontTest extends TestCase {
                $this->dyslexiaFont = new DyslexiaFont(
                        $util,
                        $this->themingDefaults,
+                       $this->userSession,
                        $this->urlGenerator,
                        $this->imageManager,
                        $this->config,
@@ -142,7 +144,7 @@ class DyslexiaFontTest extends TestCase {
 
        /**
         * @dataProvider dataTestGetCustomCss
-        * 
+        *
         * Ensure the fonts are always loaded from the web root
         * despite having url rewriting enabled or not
         *
@@ -155,7 +157,7 @@ class DyslexiaFontTest extends TestCase {
                        ->method('getSystemValue')
                        ->with('htaccess.IgnoreFrontController', false)
                        ->willReturn($prettyUrlsEnabled);
-               
+
                $this->assertStringContainsString("'$webRoot/apps/theming/fonts/OpenDyslexic-Regular.woff'", $this->dyslexiaFont->getCustomCss());
                $this->assertStringNotContainsString('index.php', $this->dyslexiaFont->getCustomCss());
        }
index 20c153f1e96b5545c9a83c49c8895ec8961256a7..5aa3621105332db6a0c0eddc366cbc8d73c6a892 100644 (file)
@@ -46,6 +46,7 @@ use OCP\IConfig;
 use OCP\IL10N;
 use OCP\INavigationManager;
 use OCP\IURLGenerator;
+use OCP\IUserSession;
 use Test\TestCase;
 
 class ThemingDefaultsTest extends TestCase {
@@ -53,6 +54,8 @@ class ThemingDefaultsTest extends TestCase {
        private $config;
        /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
        private $l10n;
+       /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
+       private $userSession;
        /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
        private $urlGenerator;
        /** @var \OC_Defaults|\PHPUnit\Framework\MockObject\MockObject */
@@ -78,6 +81,7 @@ class ThemingDefaultsTest extends TestCase {
                parent::setUp();
                $this->config = $this->createMock(IConfig::class);
                $this->l10n = $this->createMock(IL10N::class);
+               $this->userSession = $this->createMock(IUserSession::class);
                $this->urlGenerator = $this->createMock(IURLGenerator::class);
                $this->cacheFactory = $this->createMock(ICacheFactory::class);
                $this->cache = $this->createMock(ICache::class);
@@ -93,6 +97,7 @@ class ThemingDefaultsTest extends TestCase {
                $this->template = new ThemingDefaults(
                        $this->config,
                        $this->l10n,
+                       $this->userSession,
                        $this->urlGenerator,
                        $this->cacheFactory,
                        $this->util,
@@ -419,7 +424,7 @@ class ThemingDefaultsTest extends TestCase {
                $this->config
                        ->expects($this->once())
                        ->method('getAppValue')
-                       ->with('theming', 'color', $this->defaults->getColorPrimary())
+                       ->with('theming', 'color', null)
                        ->willReturn($this->defaults->getColorPrimary());
 
                $this->assertEquals($this->defaults->getColorPrimary(), $this->template->getColorPrimary());
@@ -429,7 +434,7 @@ class ThemingDefaultsTest extends TestCase {
                $this->config
                        ->expects($this->once())
                        ->method('getAppValue')
-                       ->with('theming', 'color', $this->defaults->getColorPrimary())
+                       ->with('theming', 'color', null)
                        ->willReturn('#fff');
 
                $this->assertEquals('#fff', $this->template->getColorPrimary());
@@ -542,7 +547,7 @@ class ThemingDefaultsTest extends TestCase {
                        ->method('getAppValue')
                        ->withConsecutive(
                                ['theming', 'cachebuster', '0'],
-                               ['theming', 'color', $this->defaults->getColorPrimary()],
+                               ['theming', 'color', null],
                        )->willReturnOnConsecutiveCalls(
                                '15',
                                $this->defaults->getColorPrimary(),
index e7f4019e00b86b14173a66d3328326d22623863f..a94e0d568b08e6466a02d56a7d218f3c5ff8b0fa 100644 (file)
@@ -1222,6 +1222,7 @@ class Server extends ServerContainer implements IServerContainer {
                                return new ThemingDefaults(
                                        $c->get(\OCP\IConfig::class),
                                        $c->getL10N('theming'),
+                                       $c->get(IUserSession::class),
                                        $c->get(IURLGenerator::class),
                                        $c->get(ICacheFactory::class),
                                        new Util($c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming')),