diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-07-02 22:21:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-02 22:21:40 +0200 |
commit | e8c43740ccbf73e32b87586f943c7fc465217013 (patch) | |
tree | 3758ab476317514a055153be00be1fd215e5feb1 /apps | |
parent | d4cb51c7bc9315fd70ec737cef0e04cbb12a5705 (diff) | |
parent | 03064187f118e33c3fc1513504f68f2853e5843a (diff) | |
download | nextcloud-server-e8c43740ccbf73e32b87586f943c7fc465217013.tar.gz nextcloud-server-e8c43740ccbf73e32b87586f943c7fc465217013.zip |
Merge pull request #45395 from nextcloud/fix/blur-chromium
fix(theming): Conitionally disable blur filter for performance
Diffstat (limited to 'apps')
-rw-r--r-- | apps/theming/lib/Listener/BeforePreferenceListener.php | 14 | ||||
-rw-r--r-- | apps/theming/lib/Settings/Personal.php | 1 | ||||
-rw-r--r-- | apps/theming/lib/Themes/DefaultTheme.php | 58 | ||||
-rw-r--r-- | apps/theming/src/UserTheming.vue | 27 | ||||
-rw-r--r-- | apps/theming/tests/Service/ThemesServiceTest.php | 6 | ||||
-rw-r--r-- | apps/theming/tests/Settings/PersonalTest.php | 24 | ||||
-rw-r--r-- | apps/theming/tests/Themes/DarkHighContrastThemeTest.php | 1 | ||||
-rw-r--r-- | apps/theming/tests/Themes/DarkThemeTest.php | 1 | ||||
-rw-r--r-- | apps/theming/tests/Themes/DefaultThemeTest.php | 1 | ||||
-rw-r--r-- | apps/theming/tests/Themes/DyslexiaFontTest.php | 1 | ||||
-rw-r--r-- | apps/theming/tests/Themes/HighContrastThemeTest.php | 1 |
11 files changed, 97 insertions, 38 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<BeforePreferenceDeletedEvent|BeforePreferenceSetEvent> */ 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/lib/Themes/DefaultTheme.php b/apps/theming/lib/Themes/DefaultTheme.php index a169541d371..e81c01f1f83 100644 --- a/apps/theming/lib/Themes/DefaultTheme.php +++ b/apps/theming/lib/Themes/DefaultTheme.php @@ -7,6 +7,7 @@ declare(strict_types=1); */ namespace OCA\Theming\Themes; +use OC\AppFramework\Http\Request; use OCA\Theming\ImageManager; use OCA\Theming\ITheme; use OCA\Theming\ThemingDefaults; @@ -14,41 +15,27 @@ use OCA\Theming\Util; use OCP\App\IAppManager; use OCP\IConfig; use OCP\IL10N; +use OCP\IRequest; use OCP\IURLGenerator; use OCP\IUserSession; class DefaultTheme implements ITheme { use CommonThemeTrait; - public Util $util; - public ThemingDefaults $themingDefaults; - public IUserSession $userSession; - public IURLGenerator $urlGenerator; - public ImageManager $imageManager; - public IConfig $config; - public IL10N $l; - public IAppManager $appManager; - public string $defaultPrimaryColor; public string $primaryColor; - public function __construct(Util $util, - ThemingDefaults $themingDefaults, - IUserSession $userSession, - IURLGenerator $urlGenerator, - ImageManager $imageManager, - IConfig $config, - IL10N $l, - IAppManager $appManager) { - $this->util = $util; - $this->themingDefaults = $themingDefaults; - $this->userSession = $userSession; - $this->urlGenerator = $urlGenerator; - $this->imageManager = $imageManager; - $this->config = $config; - $this->l = $l; - $this->appManager = $appManager; - + public function __construct( + public Util $util, + public ThemingDefaults $themingDefaults, + public IUserSession $userSession, + public IURLGenerator $urlGenerator, + public ImageManager $imageManager, + public IConfig $config, + public IL10N $l, + public IAppManager $appManager, + private ?IRequest $request, + ) { $this->defaultPrimaryColor = $this->themingDefaults->getDefaultColorPrimary(); $this->primaryColor = $this->themingDefaults->getColorPrimary(); } @@ -96,12 +83,29 @@ class DefaultTheme implements ITheme { $colorSuccess = '#2d7b41'; $colorInfo = '#0071ad'; + $user = $this->userSession->getUser(); + // Chromium based browsers currently (2024) have huge performance issues with blur filters + $isChromium = $this->request !== null && $this->request->isUserAgent([Request::USER_AGENT_CHROME, Request::USER_AGENT_MS_EDGE]); + // Ignore MacOS because they always have hardware accelartion + $isChromium = $isChromium && !$this->request->isUserAgent(['/Macintosh/']); + // Allow to force the blur filter + $forceEnableBlur = $user === null ? false : $this->config->getUserValue( + $user->getUID(), + 'theming', + 'force_enable_blur_filter', + ); + $workingBlur = match($forceEnableBlur) { + 'yes' => true, + 'no' => false, + default => !$isChromium + }; + $variables = [ '--color-main-background' => $colorMainBackground, '--color-main-background-rgb' => $colorMainBackgroundRGB, '--color-main-background-translucent' => 'rgba(var(--color-main-background-rgb), .97)', '--color-main-background-blur' => 'rgba(var(--color-main-background-rgb), .8)', - '--filter-background-blur' => 'blur(25px)', + '--filter-background-blur' => $workingBlur ? 'blur(25px)' : 'none', // to use like this: background-image: linear-gradient(0, var('--gradient-main-background)); '--gradient-main-background' => 'var(--color-main-background) 0%, var(--color-main-background-translucent) 85%, transparent 100%', 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" /> </div> + + <h3>{{ t('theming', 'Misc accessibility options') }}</h3> + <NcCheckboxRadioSwitch type="checkbox" + :checked="enableBlurFilter === 'yes'" + :indeterminate="enableBlurFilter === ''" + @update:checked="changeEnableBlurFilter"> + {{ t('theming', 'Enable blur background filter (may increase GPU load)') }} + </NcCheckboxRadioSwitch> </NcSettingsSection> <NcSettingsSection :name="t('theming', 'Primary color')" @@ -86,6 +94,7 @@ import UserPrimaryColor from './components/UserPrimaryColor.vue' const availableThemes = loadState('theming', 'themes', []) const enforceTheme = loadState('theming', 'enforceTheme', '') const shortcutsDisabled = loadState('theming', 'shortcutsDisabled', false) +const enableBlurFilter = loadState('theming', 'enableBlurFilter', '') const isUserThemingDisabled = loadState('theming', 'isUserThemingDisabled') @@ -109,6 +118,8 @@ export default { enforceTheme, shortcutsDisabled, isUserThemingDisabled, + + enableBlurFilter, } }, @@ -223,6 +234,22 @@ export default { } }, + async changeEnableBlurFilter() { + this.enableBlurFilter = this.enableBlurFilter === 'no' ? 'yes' : 'no' + await axios({ + url: generateOcsUrl('apps/provisioning_api/api/v1/config/users/{appId}/{configKey}', { + appId: 'theming', + configKey: 'force_enable_blur_filter', + }), + data: { + configValue: this.enableBlurFilter, + }, + method: 'POST', + }) + // Refresh the styles + this.$emit('update:background') + }, + updateBodyAttributes() { const enabledThemesIDs = this.themes.filter(theme => 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/Service/ThemesServiceTest.php b/apps/theming/tests/Service/ThemesServiceTest.php index a670ab3a583..1644deea4c7 100644 --- a/apps/theming/tests/Service/ThemesServiceTest.php +++ b/apps/theming/tests/Service/ThemesServiceTest.php @@ -315,6 +315,7 @@ class ThemesServiceTest extends TestCase { $this->config, $l10n, $appManager, + null, ), 'light' => new LightTheme( $util, @@ -325,6 +326,7 @@ class ThemesServiceTest extends TestCase { $this->config, $l10n, $appManager, + null, ), 'dark' => new DarkTheme( $util, @@ -335,6 +337,7 @@ class ThemesServiceTest extends TestCase { $this->config, $l10n, $appManager, + null, ), 'light-highcontrast' => new HighContrastTheme( $util, @@ -345,6 +348,7 @@ class ThemesServiceTest extends TestCase { $this->config, $l10n, $appManager, + null, ), 'dark-highcontrast' => new DarkHighContrastTheme( $util, @@ -355,6 +359,7 @@ class ThemesServiceTest extends TestCase { $this->config, $l10n, $appManager, + null, ), 'opendyslexic' => new DyslexiaFont( $util, @@ -365,6 +370,7 @@ class ThemesServiceTest extends TestCase { $this->config, $l10n, $appManager, + null, ), ]; } 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, ), ]; } diff --git a/apps/theming/tests/Themes/DarkHighContrastThemeTest.php b/apps/theming/tests/Themes/DarkHighContrastThemeTest.php index 7a4187ae8ea..30bbc5f110d 100644 --- a/apps/theming/tests/Themes/DarkHighContrastThemeTest.php +++ b/apps/theming/tests/Themes/DarkHighContrastThemeTest.php @@ -101,6 +101,7 @@ class DarkHighContrastThemeTest extends AccessibleThemeTestCase { $this->config, $this->l10n, $this->appManager, + null, ); parent::setUp(); diff --git a/apps/theming/tests/Themes/DarkThemeTest.php b/apps/theming/tests/Themes/DarkThemeTest.php index 606d9694b4a..16a289053ae 100644 --- a/apps/theming/tests/Themes/DarkThemeTest.php +++ b/apps/theming/tests/Themes/DarkThemeTest.php @@ -98,6 +98,7 @@ class DarkThemeTest extends AccessibleThemeTestCase { $this->config, $this->l10n, $this->appManager, + null, ); parent::setUp(); diff --git a/apps/theming/tests/Themes/DefaultThemeTest.php b/apps/theming/tests/Themes/DefaultThemeTest.php index 662f1e970b6..91b7d8887d7 100644 --- a/apps/theming/tests/Themes/DefaultThemeTest.php +++ b/apps/theming/tests/Themes/DefaultThemeTest.php @@ -102,6 +102,7 @@ class DefaultThemeTest extends AccessibleThemeTestCase { $this->config, $this->l10n, $this->appManager, + null, ); parent::setUp(); diff --git a/apps/theming/tests/Themes/DyslexiaFontTest.php b/apps/theming/tests/Themes/DyslexiaFontTest.php index 138aeeace95..05f489449b8 100644 --- a/apps/theming/tests/Themes/DyslexiaFontTest.php +++ b/apps/theming/tests/Themes/DyslexiaFontTest.php @@ -103,6 +103,7 @@ class DyslexiaFontTest extends TestCase { $this->config, $this->l10n, $this->appManager, + null, ); parent::setUp(); diff --git a/apps/theming/tests/Themes/HighContrastThemeTest.php b/apps/theming/tests/Themes/HighContrastThemeTest.php index fc323811ffc..47c4b3bb374 100644 --- a/apps/theming/tests/Themes/HighContrastThemeTest.php +++ b/apps/theming/tests/Themes/HighContrastThemeTest.php @@ -101,6 +101,7 @@ class HighContrastThemeTest extends AccessibleThemeTestCase { $this->config, $this->l10n, $this->appManager, + null, ); parent::setUp(); |