feat(theming): Add checkbox for force enable / disable blurry background

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
Ferdinand Thiessen 2024-05-17 16:48:08 +02:00
parent 697a963243
commit 2d827d0ed4
No known key found for this signature in database
GPG key ID: 45FAE7268762B400
4 changed files with 55 additions and 11 deletions

View file

@ -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);

View file

@ -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

View file

@ -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)

View file

@ -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,
),
];
}