summaryrefslogtreecommitdiffstats
path: root/apps/theming/lib
diff options
context:
space:
mode:
authorChristopher Ng <chrng8@gmail.com>2022-09-28 02:35:51 +0000
committerChristopher Ng <chrng8@gmail.com>2022-10-05 06:19:08 +0000
commite962d3fba4430f3a13cda70db9009784fc24112a (patch)
treeb5fb729a2b0863ecefee40357dd379634226fe10 /apps/theming/lib
parent89635e894986fd63d6acab37e78af80ced79505e (diff)
downloadnextcloud-server-e962d3fba4430f3a13cda70db9009784fc24112a.tar.gz
nextcloud-server-e962d3fba4430f3a13cda70db9009784fc24112a.zip
Use color preset of shipped background as primary color
Signed-off-by: Christopher Ng <chrng8@gmail.com>
Diffstat (limited to 'apps/theming/lib')
-rw-r--r--apps/theming/lib/Themes/DefaultTheme.php12
-rw-r--r--apps/theming/lib/ThemingDefaults.php83
2 files changed, 49 insertions, 46 deletions
diff --git a/apps/theming/lib/Themes/DefaultTheme.php b/apps/theming/lib/Themes/DefaultTheme.php
index 203e03757c8..d338c40ac5e 100644
--- a/apps/theming/lib/Themes/DefaultTheme.php
+++ b/apps/theming/lib/Themes/DefaultTheme.php
@@ -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;
}
diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php
index 3d7aaee2064..61001770302 100644
--- a/apps/theming/lib/ThemingDefaults.php
+++ b/apps/theming/lib/ThemingDefaults.php
@@ -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;
}