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 <[email protected]>
  • Loading branch information
susnux committed Jul 1, 2024
1 parent beececf commit c7b5405
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 27 deletions.
57 changes: 30 additions & 27 deletions apps/theming/lib/Themes/DefaultTheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,35 @@
*/
namespace OCA\Theming\Themes;

use OC\AppFramework\Http\Request;
use OCA\Theming\ImageManager;
use OCA\Theming\ITheme;
use OCA\Theming\ThemingDefaults;
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();
}
Expand Down Expand Up @@ -96,12 +83,28 @@ public function getCSSVariables(): array {
$colorSuccess = '#2d7b41';
$colorInfo = '#0071ad';

// 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 = $this->config->getUserValue(
$this->userSession->getUser()->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%',
Expand Down
6 changes: 6 additions & 0 deletions apps/theming/tests/Service/ThemesServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ private function initThemes() {
$this->config,
$l10n,
$appManager,
null,
),
'light' => new LightTheme(
$util,
Expand All @@ -325,6 +326,7 @@ private function initThemes() {
$this->config,
$l10n,
$appManager,
null,
),
'dark' => new DarkTheme(
$util,
Expand All @@ -335,6 +337,7 @@ private function initThemes() {
$this->config,
$l10n,
$appManager,
null,
),
'light-highcontrast' => new HighContrastTheme(
$util,
Expand All @@ -345,6 +348,7 @@ private function initThemes() {
$this->config,
$l10n,
$appManager,
null,
),
'dark-highcontrast' => new DarkHighContrastTheme(
$util,
Expand All @@ -355,6 +359,7 @@ private function initThemes() {
$this->config,
$l10n,
$appManager,
null,
),
'opendyslexic' => new DyslexiaFont(
$util,
Expand All @@ -365,6 +370,7 @@ private function initThemes() {
$this->config,
$l10n,
$appManager,
null,
),
];
}
Expand Down
1 change: 1 addition & 0 deletions apps/theming/tests/Themes/DarkHighContrastThemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ protected function setUp(): void {
$this->config,
$this->l10n,
$this->appManager,
null,
);

parent::setUp();
Expand Down
1 change: 1 addition & 0 deletions apps/theming/tests/Themes/DarkThemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ protected function setUp(): void {
$this->config,
$this->l10n,
$this->appManager,
null,
);

parent::setUp();
Expand Down
1 change: 1 addition & 0 deletions apps/theming/tests/Themes/DefaultThemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ protected function setUp(): void {
$this->config,
$this->l10n,
$this->appManager,
null,
);

parent::setUp();
Expand Down
1 change: 1 addition & 0 deletions apps/theming/tests/Themes/DyslexiaFontTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ protected function setUp(): void {
$this->config,
$this->l10n,
$this->appManager,
null,
);

parent::setUp();
Expand Down
1 change: 1 addition & 0 deletions apps/theming/tests/Themes/HighContrastThemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ protected function setUp(): void {
$this->config,
$this->l10n,
$this->appManager,
null,
);

parent::setUp();
Expand Down

0 comments on commit c7b5405

Please sign in to comment.