Skip to content

Commit

Permalink
feat(theming): Add checkbox for force enable / disable blurry background
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 c7b5405 commit cadc8b2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
14 changes: 11 additions & 3 deletions apps/theming/lib/Listener/BeforePreferenceListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

/** @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,
) {
Expand All @@ -38,15 +44,16 @@ public function handle(Event $event): void {
}

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;
Expand All @@ -56,6 +63,7 @@ private function handleThemingValues(BeforePreferenceSetEvent|BeforePreferenceDe
default:
$event->setValid(false);
}
return;
}

$event->setValid(true);
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 @@ -75,6 +75,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/UserTheming.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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')"
Expand Down Expand Up @@ -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')

Expand All @@ -109,6 +118,8 @@ export default {
enforceTheme,
shortcutsDisabled,
isUserThemingDisabled,

enableBlurFilter,
}
},

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit cadc8b2

Please sign in to comment.