From 4d865fd33fcd309a241f9fd21144fe157ad4a3d2 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sat, 20 Jan 2024 03:22:30 +0100 Subject: feat(theming): Allow users to configure their primary color Signed-off-by: Ferdinand Thiessen --- .../lib/Listener/BeforePreferenceListener.php | 16 ++- apps/theming/src/UserThemes.vue | 20 ++-- apps/theming/src/components/BackgroundSettings.vue | 1 - apps/theming/src/components/UserPrimaryColor.vue | 130 +++++++++++++++++++++ 4 files changed, 156 insertions(+), 11 deletions(-) create mode 100644 apps/theming/src/components/UserPrimaryColor.vue (limited to 'apps') diff --git a/apps/theming/lib/Listener/BeforePreferenceListener.php b/apps/theming/lib/Listener/BeforePreferenceListener.php index 47b7d3fb6ff..4981af6950e 100644 --- a/apps/theming/lib/Listener/BeforePreferenceListener.php +++ b/apps/theming/lib/Listener/BeforePreferenceListener.php @@ -55,14 +55,24 @@ class BeforePreferenceListener implements IEventListener { } private function handleThemingValues(BeforePreferenceSetEvent|BeforePreferenceDeletedEvent $event): void { - if ($event->getConfigKey() !== 'shortcuts_disabled') { + $allowedKeys = ['shortcuts_disabled', 'primary_color']; + + if (!in_array($event->getConfigKey(), $allowedKeys)) { // Not allowed config key return; } if ($event instanceof BeforePreferenceSetEvent) { - $event->setValid($event->getConfigValue() === 'yes'); - return; + switch ($event->getConfigKey()) { + case 'shortcuts_disabled': + $event->setValid($event->getConfigValue() === 'yes'); + break; + case 'primary_color': + $event->setValid(preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $event->getConfigValue()) === 1); + break; + default: + $event->setValid(false); + } } $event->setValid(true); diff --git a/apps/theming/src/UserThemes.vue b/apps/theming/src/UserThemes.vue index 676b8eca767..900577754b5 100644 --- a/apps/theming/src/UserThemes.vue +++ b/apps/theming/src/UserThemes.vue @@ -53,6 +53,13 @@ + + + + @@ -65,8 +72,8 @@ - -

{{ t('theming', 'In some cases keyboard shortcuts can interfere with accessibility tools. In order to allow focusing on your tool correctly you can disable all keyboard shortcuts here. This will also disable all available shortcuts in apps.') }}

+ theme.remove() document.head.append(newTheme) }) - }, - - updateBackground(data) { - this.background = (data.type === 'custom' || data.type === 'default') ? data.type : data.value - this.refreshGlobalStyles() + emit('theming:global-styles-refreshed') }, changeTheme({ enabled, id }) { diff --git a/apps/theming/src/components/BackgroundSettings.vue b/apps/theming/src/components/BackgroundSettings.vue index 166fdbc5f4b..1ccf05b3ce9 100644 --- a/apps/theming/src/components/BackgroundSettings.vue +++ b/apps/theming/src/components/BackgroundSettings.vue @@ -116,7 +116,6 @@ const defaultShippedBackground = loadState('theming', 'defaultShippedBackground' const prefixWithBaseUrl = (url) => generateFilePath('theming', '', 'img/background/') + url -console.warn(loadState('theming', 'data', {})) export default { name: 'BackgroundSettings', diff --git a/apps/theming/src/components/UserPrimaryColor.vue b/apps/theming/src/components/UserPrimaryColor.vue new file mode 100644 index 00000000000..5211b5aaba0 --- /dev/null +++ b/apps/theming/src/components/UserPrimaryColor.vue @@ -0,0 +1,130 @@ + + + + + -- cgit v1.2.3