From 2d827d0ed454dff8b0abf582e1a3181819775696 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Fri, 17 May 2024 16:48:08 +0200 Subject: [PATCH] feat(theming): Add checkbox for force enable / disable blurry background Signed-off-by: Ferdinand Thiessen --- .../lib/Listener/BeforePreferenceListener.php | 14 +++++++--- apps/theming/lib/Settings/Personal.php | 1 + apps/theming/src/UserTheming.vue | 27 +++++++++++++++++++ apps/theming/tests/Settings/PersonalTest.php | 24 +++++++++++------ 4 files changed, 55 insertions(+), 11 deletions(-) diff --git a/apps/theming/lib/Listener/BeforePreferenceListener.php b/apps/theming/lib/Listener/BeforePreferenceListener.php index f21ccc94a1a..048deae50ce 100644 --- a/apps/theming/lib/Listener/BeforePreferenceListener.php +++ b/apps/theming/lib/Listener/BeforePreferenceListener.php @@ -17,6 +17,12 @@ use OCP\EventDispatcher\IEventListener; /** @template-implements IEventListener */ class BeforePreferenceListener implements IEventListener { + + /** + * @var string[] + */ + private const ALLOWED_KEYS = ['force_enable_blur_filter', 'shortcuts_disabled', 'primary_color']; + public function __construct( private IAppManager $appManager, ) { @@ -38,15 +44,16 @@ class BeforePreferenceListener implements IEventListener { } private function handleThemingValues(BeforePreferenceSetEvent|BeforePreferenceDeletedEvent $event): void { - $allowedKeys = ['shortcuts_disabled', 'primary_color']; - - if (!in_array($event->getConfigKey(), $allowedKeys)) { + if (!in_array($event->getConfigKey(), self::ALLOWED_KEYS)) { // Not allowed config key return; } if ($event instanceof BeforePreferenceSetEvent) { switch ($event->getConfigKey()) { + case 'force_enable_blur_filter': + $event->setValid($event->getConfigValue() === 'yes' || $event->getConfigValue() === 'no'); + break; case 'shortcuts_disabled': $event->setValid($event->getConfigValue() === 'yes'); break; @@ -56,6 +63,7 @@ class BeforePreferenceListener implements IEventListener { default: $event->setValid(false); } + return; } $event->setValid(true); diff --git a/apps/theming/lib/Settings/Personal.php b/apps/theming/lib/Settings/Personal.php index cdf0399946f..43156515acd 100644 --- a/apps/theming/lib/Settings/Personal.php +++ b/apps/theming/lib/Settings/Personal.php @@ -75,6 +75,7 @@ class Personal implements ISettings { $this->initialStateService->provideInitialState('themes', array_values($themes)); $this->initialStateService->provideInitialState('enforceTheme', $enforcedTheme); $this->initialStateService->provideInitialState('isUserThemingDisabled', $this->themingDefaults->isUserThemingDisabled()); + $this->initialStateService->provideInitialState('enableBlurFilter', $this->config->getUserValue($this->userId, 'theming', 'force_enable_blur_filter', '')); $this->initialStateService->provideInitialState('navigationBar', [ 'userAppOrder' => json_decode($this->config->getUserValue($this->userId, 'core', 'apporder', '[]'), true, flags:JSON_THROW_ON_ERROR), 'enforcedDefaultApp' => $forcedDefaultApp diff --git a/apps/theming/src/UserTheming.vue b/apps/theming/src/UserTheming.vue index 5d75ca21fb0..a5c3d029158 100644 --- a/apps/theming/src/UserTheming.vue +++ b/apps/theming/src/UserTheming.vue @@ -33,6 +33,14 @@ type="font" @change="changeFont" /> + +

{{ t('theming', 'Misc accessibility options') }}

+ + {{ t('theming', 'Enable blur background filter (may increase GPU load)') }} + theme.enabled === true).map(theme => theme.id) const enabledFontsIDs = this.fonts.filter(font => font.enabled === true).map(font => font.id) diff --git a/apps/theming/tests/Settings/PersonalTest.php b/apps/theming/tests/Settings/PersonalTest.php index 57c4e12a268..2313b3062a0 100644 --- a/apps/theming/tests/Settings/PersonalTest.php +++ b/apps/theming/tests/Settings/PersonalTest.php @@ -26,14 +26,15 @@ use OCP\IConfig; use OCP\IL10N; use OCP\IURLGenerator; use OCP\IUserSession; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class PersonalTest extends TestCase { - private IConfig $config; - private ThemesService $themesService; - private IInitialState $initialStateService; - private ThemingDefaults $themingDefaults; - private IAppManager $appManager; + private IConfig&MockObject $config; + private ThemesService&MockObject $themesService; + private IInitialState&MockObject $initialStateService; + private ThemingDefaults&MockObject $themingDefaults; + private IAppManager&MockObject $appManager; private Personal $admin; /** @var ITheme[] */ @@ -106,17 +107,18 @@ class PersonalTest extends TestCase { ->method('getDefaultAppForUser') ->willReturn('forcedapp'); - $this->initialStateService->expects($this->exactly(7)) + $this->initialStateService->expects($this->exactly(8)) ->method('provideInitialState') - ->withConsecutive( + ->willReturnMap([ ['shippedBackgrounds', BackgroundService::SHIPPED_BACKGROUNDS], ['themingDefaults'], + ['enableBlurFilter', ''], ['userBackgroundImage'], ['themes', $themesState], ['enforceTheme', $enforcedTheme], ['isUserThemingDisabled', false], ['navigationBar', ['userAppOrder' => [], 'enforcedDefaultApp' => 'forcedapp']], - ); + ]); $expected = new TemplateResponse('theming', 'settings-personal'); $this->assertEquals($expected, $this->admin->getForm()); @@ -158,6 +160,7 @@ class PersonalTest extends TestCase { $config, $l10n, $appManager, + null, ), 'light' => new LightTheme( $util, @@ -168,6 +171,7 @@ class PersonalTest extends TestCase { $config, $l10n, $appManager, + null, ), 'dark' => new DarkTheme( $util, @@ -178,6 +182,7 @@ class PersonalTest extends TestCase { $config, $l10n, $appManager, + null, ), 'light-highcontrast' => new HighContrastTheme( $util, @@ -188,6 +193,7 @@ class PersonalTest extends TestCase { $config, $l10n, $appManager, + null, ), 'dark-highcontrast' => new DarkHighContrastTheme( $util, @@ -198,6 +204,7 @@ class PersonalTest extends TestCase { $config, $l10n, $appManager, + null, ), 'opendyslexic' => new DyslexiaFont( $util, @@ -208,6 +215,7 @@ class PersonalTest extends TestCase { $config, $l10n, $appManager, + null, ), ]; }