Skip to content

Commit

Permalink
fix(theming): Conitionally disable blur filter for performance
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed May 17, 2024
1 parent 495d397 commit 1466ff4
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions apps/theming/lib/Themes/DefaultTheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/
namespace OCA\Theming\Themes;

use OC\AppFramework\Http\Request;
use OCA\Theming\ImageManager;
use OCA\Theming\ITheme;
use OCA\Theming\Service\BackgroundService;
Expand All @@ -39,35 +40,20 @@
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 ?Request $request,
) {
$this->defaultPrimaryColor = $this->themingDefaults->getDefaultColorPrimary();
$this->primaryColor = $this->themingDefaults->getColorPrimary();

Expand Down Expand Up @@ -120,12 +106,25 @@ public function getCSSVariables(): array {
$colorSuccess = '#2d7b41';
$colorInfo = '#0071ad';

// Chromium based browsers currently (2024) have huge performance issues with blur filters
$workingBlur = $this->request === null || !$this->request->isUserAgent([Request::USER_AGENT_CHROME, Request::USER_AGENT_MS_EDGE]);
// Allow to force some state
$forceEnableBlur = $this->config->getUserValue(
$this->userSession->getUser()->getUID(),

Check notice

Code scanning / Psalm

PossiblyNullReference Note

Cannot call method getUID on possibly null value
'theming',
'force_enable_blur_filter',
null,
);
if ($forceEnableBlur !== null) {

Check notice

Code scanning / Psalm

RedundantConditionGivenDocblockType Note

Docblock-defined type string can never contain null
$workingBlur = $forceEnableBlur;
}

$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',

Check notice

Code scanning / Psalm

RiskyTruthyFalsyComparison Note

Operand of type bool|string contains type string, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead.

// 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%',
Expand Down

0 comments on commit 1466ff4

Please sign in to comment.