aboutsummaryrefslogtreecommitdiffstats
path: root/apps/theming/lib
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2022-10-05 11:34:05 +0200
committerJohn Molakvoæ <skjnldsv@protonmail.com>2022-10-13 12:13:39 +0200
commit4b46c5a5a02b6c1c77b99cf21b9ff933fabbcc35 (patch)
tree17de2e626c685d93f112a7a4c90efa150e6afe11 /apps/theming/lib
parentf6efd54242de80f4391a7bac57dab7ddc01cb981 (diff)
downloadnextcloud-server-4b46c5a5a02b6c1c77b99cf21b9ff933fabbcc35.tar.gz
nextcloud-server-4b46c5a5a02b6c1c77b99cf21b9ff933fabbcc35.zip
Use default system primary
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/theming/lib')
-rw-r--r--apps/theming/lib/Service/JSDataService.php1
-rw-r--r--apps/theming/lib/Settings/Admin.php2
-rw-r--r--apps/theming/lib/Themes/CommonThemeTrait.php1
-rw-r--r--apps/theming/lib/Themes/DefaultTheme.php10
-rw-r--r--apps/theming/lib/ThemingDefaults.php29
5 files changed, 36 insertions, 7 deletions
diff --git a/apps/theming/lib/Service/JSDataService.php b/apps/theming/lib/Service/JSDataService.php
index fdc85ea445a..26cda8c0012 100644
--- a/apps/theming/lib/Service/JSDataService.php
+++ b/apps/theming/lib/Service/JSDataService.php
@@ -55,6 +55,7 @@ class JSDataService implements \JsonSerializable {
'url' => $this->themingDefaults->getBaseUrl(),
'slogan' => $this->themingDefaults->getSlogan(),
'color' => $this->themingDefaults->getColorPrimary(),
+ 'defaultColor' => $this->themingDefaults->getDefaultColorPrimary(),
'imprintUrl' => $this->themingDefaults->getImprintUrl(),
'privacyUrl' => $this->themingDefaults->getPrivacyUrl(),
'inverted' => $this->util->invertTextColor($this->themingDefaults->getColorPrimary()),
diff --git a/apps/theming/lib/Settings/Admin.php b/apps/theming/lib/Settings/Admin.php
index 6caa174d99b..e89ea6b6fe9 100644
--- a/apps/theming/lib/Settings/Admin.php
+++ b/apps/theming/lib/Settings/Admin.php
@@ -75,7 +75,7 @@ class Admin implements IDelegatedSettings {
'name' => $this->themingDefaults->getEntity(),
'url' => $this->themingDefaults->getBaseUrl(),
'slogan' => $this->themingDefaults->getSlogan(),
- 'color' => $this->themingDefaults->getColorPrimary(),
+ 'color' => $this->themingDefaults->getDefaultColorPrimary(),
'uploadLogoRoute' => $this->urlGenerator->linkToRoute('theming.Theming.uploadImage'),
'canThemeIcons' => $this->imageManager->shouldReplaceIcons(),
'iconDocs' => $this->urlGenerator->linkToDocs('admin-theming-icons'),
diff --git a/apps/theming/lib/Themes/CommonThemeTrait.php b/apps/theming/lib/Themes/CommonThemeTrait.php
index 631879ea832..d88a6a319fb 100644
--- a/apps/theming/lib/Themes/CommonThemeTrait.php
+++ b/apps/theming/lib/Themes/CommonThemeTrait.php
@@ -42,6 +42,7 @@ trait CommonThemeTrait {
// primary related colours
return [
'--color-primary' => $this->primaryColor,
+ '--color-primary-default' => $this->defaultPrimaryColor,
'--color-primary-text' => $this->util->invertTextColor($this->primaryColor) ? '#000000' : '#ffffff',
'--color-primary-hover' => $this->util->mix($this->primaryColor, $colorMainBackground, 60),
'--color-primary-light' => $colorPrimaryLight,
diff --git a/apps/theming/lib/Themes/DefaultTheme.php b/apps/theming/lib/Themes/DefaultTheme.php
index e295d5d880a..b6c84e82d7b 100644
--- a/apps/theming/lib/Themes/DefaultTheme.php
+++ b/apps/theming/lib/Themes/DefaultTheme.php
@@ -48,6 +48,7 @@ class DefaultTheme implements ITheme {
public IConfig $config;
public IL10N $l;
+ public string $defaultPrimaryColor;
public string $primaryColor;
public function __construct(Util $util,
@@ -65,9 +66,12 @@ class DefaultTheme implements ITheme {
$this->config = $config;
$this->l = $l;
- $initialPrimaryColor = $this->themingDefaults->getColorPrimary();
- // Override default color if set to improve accessibility
- $this->primaryColor = $initialPrimaryColor === BackgroundService::DEFAULT_COLOR ? BackgroundService::DEFAULT_ACCESSIBLE_COLOR : $initialPrimaryColor;
+ $this->defaultPrimaryColor = $this->themingDefaults->getDefaultColorPrimary();
+
+ // Override default codefaultPrimaryColorlor if set to improve accessibility
+ $this->primaryColor = $this->defaultPrimaryColor === BackgroundService::DEFAULT_COLOR
+ ? BackgroundService::DEFAULT_ACCESSIBLE_COLOR
+ : $this->themingDefaults->getColorPrimary();
}
public function getId(): string {
diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php
index ae12530fb5c..cc23053a9c3 100644
--- a/apps/theming/lib/ThemingDefaults.php
+++ b/apps/theming/lib/ThemingDefaults.php
@@ -219,9 +219,12 @@ class ThemingDefaults extends \OC_Defaults {
*/
public function getColorPrimary() {
$user = $this->userSession->getUser();
- $color = $this->config->getAppValue(Application::APP_ID, 'color', '');
+ $defaultColor = $this->getDefaultColorPrimary();
+ $themingBackground = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background');
- if ($color === '' && !empty($user)) {
+ // if the user is defined and the selected background is not a colour
+ if ($user !== null
+ && !preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $themingBackground)) {
$themingBackground = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background', 'default');
if ($themingBackground === 'default') {
return BackgroundService::DEFAULT_COLOR;
@@ -230,10 +233,30 @@ class ThemingDefaults extends \OC_Defaults {
}
}
- if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $color)) {
+ // If the user selected a specific colour
+ if (preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $themingBackground)) {
+ return $themingBackground;
+ }
+
+ // If the default color is not valid, return the default background one
+ if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $defaultColor)) {
return BackgroundService::DEFAULT_COLOR;
}
+ // Finally, return the system global primary color
+ return $defaultColor;
+ }
+
+ /**
+ * Return the default color primary
+ *
+ * @return string
+ */
+ public function getDefaultColorPrimary() {
+ $color = $this->config->getAppValue(Application::APP_ID, 'color', $this->color);
+ if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $color)) {
+ $color = '#0082c9';
+ }
return $color;
}