Use color preset of shipped background as primary color

Signed-off-by: Christopher Ng <chrng8@gmail.com>
pull/34298/head
Christopher Ng 3 years ago
parent 89635e8949
commit e962d3fba4
  1. 20
      apps/theming/css/default.css
  2. 12
      apps/theming/lib/Themes/DefaultTheme.php
  3. 83
      apps/theming/lib/ThemingDefaults.php
  4. 10
      apps/theming/tests/Service/ThemesServiceTest.php
  5. 8
      apps/theming/tests/Settings/PersonalTest.php
  6. 3
      apps/theming/tests/Themes/DefaultThemeTest.php
  7. 6
      apps/theming/tests/Themes/DyslexiaFontTest.php
  8. 11
      apps/theming/tests/ThemingDefaultsTest.php
  9. 1
      lib/private/Server.php

@ -53,19 +53,19 @@
--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%);
}

@ -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;
}

@ -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;
}

@ -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,

@ -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,

@ -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,

@ -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());
}

@ -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(),

@ -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')),

Loading…
Cancel
Save