Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(theming): Add checkbox for force enable / disable blurry background
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux authored and AndyScherzinger committed Jul 11, 2024
commit 78114c6630e0fa1119a3d1b46f25bad02dd41e9d
19 changes: 17 additions & 2 deletions apps/theming/lib/Listener/BeforePreferenceListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@

/** @template-implements IEventListener<BeforePreferenceDeletedEvent|BeforePreferenceSetEvent> */
class BeforePreferenceListener implements IEventListener {

/**
* @var string[]
*/
private const ALLOWED_KEYS = ['force_enable_blur_filter', 'shortcuts_disabled'];

public function __construct(
private IAppManager $appManager,
) {
Expand All @@ -55,13 +61,22 @@ public function handle(Event $event): void {
}

private function handleThemingValues(BeforePreferenceSetEvent|BeforePreferenceDeletedEvent $event): void {
if ($event->getConfigKey() !== 'shortcuts_disabled') {
if (!in_array($event->getConfigKey(), self::ALLOWED_KEYS)) {
// Not allowed config key
return;
}

if ($event instanceof BeforePreferenceSetEvent) {
$event->setValid($event->getConfigValue() === 'yes');
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;
default:
$event->setValid(false);
}
return;
}

Expand Down
1 change: 1 addition & 0 deletions apps/theming/lib/Settings/Personal.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function getForm(): TemplateResponse {
$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
Expand Down
27 changes: 27 additions & 0 deletions apps/theming/src/UserThemes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,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', 'Background')"
Expand Down Expand Up @@ -93,6 +101,7 @@ import UserAppMenuSection from './components/UserAppMenuSection.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')

Expand All @@ -115,6 +124,8 @@ export default {
enforceTheme,
shortcutsDisabled,
isUserThemingDisabled,

enableBlurFilter,
}
},

Expand Down Expand Up @@ -240,6 +251,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)
Expand Down
30 changes: 20 additions & 10 deletions apps/theming/tests/Settings/PersonalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@
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[] */
Expand Down Expand Up @@ -116,23 +117,26 @@ public function testGetForm(string $enforcedTheme, $themesState) {
->with('enforce_theme', '')
->willReturn($enforcedTheme);

$this->config->expects($this->once())
$this->config->expects($this->exactly(2))
->method('getUserValue')
->with('admin', 'core', 'apporder')
->willReturn('[]');
->willReturnMap([
['admin', 'core', 'apporder', '[]'],
['admin', 'theming', 'force_enable_blur_filter', ''],
]);

$this->appManager->expects($this->once())
->method('getDefaultAppForUser')
->willReturn('forcedapp');

$this->initialStateService->expects($this->exactly(4))
->method('provideInitialState')
->withConsecutive(
->willReturnMap([
['themes', $themesState],
['enableBlurFilter', ''],
['enforceTheme', $enforcedTheme],
['isUserThemingDisabled', false],
['navigationBar', ['userAppOrder' => [], 'enforcedDefaultApp' => 'forcedapp']],
);
]);

$expected = new TemplateResponse('theming', 'settings-personal');
$this->assertEquals($expected, $this->admin->getForm());
Expand Down Expand Up @@ -174,6 +178,7 @@ private function initThemes() {
$config,
$l10n,
$appManager,
null,
),
'light' => new LightTheme(
$util,
Expand All @@ -184,6 +189,7 @@ private function initThemes() {
$config,
$l10n,
$appManager,
null,
),
'dark' => new DarkTheme(
$util,
Expand All @@ -194,6 +200,7 @@ private function initThemes() {
$config,
$l10n,
$appManager,
null,
),
'light-highcontrast' => new HighContrastTheme(
$util,
Expand All @@ -204,6 +211,7 @@ private function initThemes() {
$config,
$l10n,
$appManager,
null,
),
'dark-highcontrast' => new DarkHighContrastTheme(
$util,
Expand All @@ -214,6 +222,7 @@ private function initThemes() {
$config,
$l10n,
$appManager,
null,
),
'opendyslexic' => new DyslexiaFont(
$util,
Expand All @@ -224,6 +233,7 @@ private function initThemes() {
$config,
$l10n,
$appManager,
null,
),
];
}
Expand Down