diff --git a/apps/theming/lib/Controller/ThemingController.php b/apps/theming/lib/Controller/ThemingController.php index ad556a1fdb54c..9c806ea5ba7eb 100644 --- a/apps/theming/lib/Controller/ThemingController.php +++ b/apps/theming/lib/Controller/ThemingController.php @@ -12,6 +12,7 @@ use OCA\Theming\ITheme; use OCA\Theming\Service\ThemesService; use OCA\Theming\Settings\Admin; +use OCA\Theming\ConfigLexicon; use OCA\Theming\ThemingDefaults; use OCP\App\IAppManager; use OCP\AppFramework\Controller; @@ -134,7 +135,7 @@ public function updateStylesheet(string $setting, string $value): DataResponse { if (!in_array($value, ['yes', 'true', 'no', 'false'], true)) { $error = $this->l10n->t('%1$s should be true or false', ['disable-user-theming']); } else { - $this->appConfig->setAppValueBool('disable-user-theming', $value === 'yes' || $value === 'true'); + $this->themingDefaults->set(ConfigLexicon::USER_THEMING_DISABLED, $value); $saved = true; } break; diff --git a/apps/theming/lib/Controller/UserThemeController.php b/apps/theming/lib/Controller/UserThemeController.php index fa3dc4219b1da..ee3aac1800428 100644 --- a/apps/theming/lib/Controller/UserThemeController.php +++ b/apps/theming/lib/Controller/UserThemeController.php @@ -154,6 +154,8 @@ public function getBackground(): Response { public function deleteBackground(): JSONResponse { $currentVersion = (int)$this->config->getUserValue($this->userId, Application::APP_ID, 'userCacheBuster', '0'); $this->backgroundService->deleteBackgroundImage(); + $currentVersion++; + $this->config->setUserValue($this->userId, Application::APP_ID, 'userCacheBuster', (string)$currentVersion); return new JSONResponse([ 'backgroundImage' => null, 'backgroundColor' => $this->themingDefaults->getColorBackground(), diff --git a/apps/theming/lib/Listener/BeforePreferenceListener.php b/apps/theming/lib/Listener/BeforePreferenceListener.php index 44ccb62fff6a7..f2ab801261732 100644 --- a/apps/theming/lib/Listener/BeforePreferenceListener.php +++ b/apps/theming/lib/Listener/BeforePreferenceListener.php @@ -13,6 +13,7 @@ use OCA\Theming\Capabilities; use OCA\Theming\ConfigLexicon; use OCP\App\IAppManager; +use OCP\IConfig; use OCP\Config\BeforePreferenceDeletedEvent; use OCP\Config\BeforePreferenceSetEvent; use OCP\EventDispatcher\Event; @@ -28,6 +29,7 @@ class BeforePreferenceListener implements IEventListener { public function __construct( private IAppManager $appManager, + private IConfig $config, ) { } @@ -71,10 +73,20 @@ private function handleThemingValues(BeforePreferenceSetEvent|BeforePreferenceDe default: $event->setValid(false); } + + if ($event->isValid() && $event->getConfigKey() === 'primary_color') { + $currentVersion = (int)$this->config->getUserValue($event->getUserId(), Application::APP_ID, 'userCacheBuster', '0'); + $this->config->setUserValue($event->getUserId(), Application::APP_ID, 'userCacheBuster', (string)($currentVersion + 1)); + } + return; } $event->setValid(true); + if ($event->getConfigKey() === 'primary_color') { + $currentVersion = (int)$this->config->getUserValue($event->getUserId(), Application::APP_ID, 'userCacheBuster', '0'); + $this->config->setUserValue($event->getUserId(), Application::APP_ID, 'userCacheBuster', (string)($currentVersion + 1)); + } } private function handleCoreValues(BeforePreferenceSetEvent|BeforePreferenceDeletedEvent $event): void { diff --git a/apps/theming/src/components/UserSectionPrimaryColor.vue b/apps/theming/src/components/UserSectionPrimaryColor.vue index 194033f72a37a..f7475575031d2 100644 --- a/apps/theming/src/components/UserSectionPrimaryColor.vue +++ b/apps/theming/src/components/UserSectionPrimaryColor.vue @@ -10,7 +10,7 @@ import { loadState } from '@nextcloud/initial-state' import { t } from '@nextcloud/l10n' import { generateOcsUrl } from '@nextcloud/router' import debounce from 'debounce' -import { computed, ref, useTemplateRef, watch } from 'vue' +import { computed, nextTick, ref, useTemplateRef, watch } from 'vue' import NcButton from '@nextcloud/vue/components/NcButton' import NcColorPicker from '@nextcloud/vue/components/NcColorPicker' import NcLoadingIcon from '@nextcloud/vue/components/NcLoadingIcon' @@ -32,9 +32,19 @@ const triggerElement = useTemplateRef('trigger') const loading = ref(false) const primaryColor = ref(initialPrimaryColor) -watch(primaryColor, debounce((newColor) => { + +let isResetting = false + +const debouncedUpdate = debounce((newColor: string) => { onUpdate(newColor) -}, 1000)) +}, 1000) + +watch(primaryColor, (newColor) => { + if (isResetting) { + return + } + debouncedUpdate(newColor) +}) const isDefaultPrimaryColor = computed(() => isSameColor(primaryColor.value, defaultPrimaryColor)) @@ -57,8 +67,13 @@ function reload() { * Reset primary color to default */ function onReset() { + isResetting = true + debouncedUpdate.clear?.() primaryColor.value = defaultPrimaryColor onUpdate(null) + nextTick(() => { + isResetting = false + }) } /** @@ -67,6 +82,7 @@ function onReset() { * @param value - The new value */ async function onUpdate(value: string | null) { + debouncedUpdate.clear?.() loading.value = true const url = generateOcsUrl('apps/provisioning_api/api/v1/config/users/{appId}/{configKey}', { appId: 'theming', @@ -104,7 +120,8 @@ function numberToHex(numeric: string): string {
+ data-user-theming-primary-color + @submit="onUpdate">