@@ -32,25 +32,25 @@ |
||
| 32 | 32 | use OCP\EventDispatcher\IEventListener; |
| 33 | 33 | |
| 34 | 34 | class BeforePreferenceListener implements IEventListener { |
| 35 | - public function handle(Event $event): void { |
|
| 36 | - if (!$event instanceof BeforePreferenceSetEvent |
|
| 37 | - && !$event instanceof BeforePreferenceDeletedEvent) { |
|
| 38 | - return; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - if ($event->getAppId() !== Application::APP_ID) { |
|
| 42 | - return; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - if ($event->getConfigKey() !== 'shortcuts_disabled') { |
|
| 46 | - return; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - if ($event instanceof BeforePreferenceSetEvent) { |
|
| 50 | - $event->setValid($event->getConfigValue() === 'yes'); |
|
| 51 | - return; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - $event->setValid(true); |
|
| 55 | - } |
|
| 35 | + public function handle(Event $event): void { |
|
| 36 | + if (!$event instanceof BeforePreferenceSetEvent |
|
| 37 | + && !$event instanceof BeforePreferenceDeletedEvent) { |
|
| 38 | + return; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + if ($event->getAppId() !== Application::APP_ID) { |
|
| 42 | + return; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + if ($event->getConfigKey() !== 'shortcuts_disabled') { |
|
| 46 | + return; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + if ($event instanceof BeforePreferenceSetEvent) { |
|
| 50 | + $event->setValid($event->getConfigValue() === 'yes'); |
|
| 51 | + return; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + $event->setValid(true); |
|
| 55 | + } |
|
| 56 | 56 | } |
@@ -40,72 +40,72 @@ |
||
| 40 | 40 | |
| 41 | 41 | class BeforeTemplateRenderedListener implements IEventListener { |
| 42 | 42 | |
| 43 | - private IInitialState $initialState; |
|
| 44 | - private ContainerInterface $container; |
|
| 45 | - private ThemeInjectionService $themeInjectionService; |
|
| 46 | - private IUserSession $userSession; |
|
| 47 | - private IConfig $config; |
|
| 48 | - |
|
| 49 | - public function __construct( |
|
| 50 | - IInitialState $initialState, |
|
| 51 | - ContainerInterface $container, |
|
| 52 | - ThemeInjectionService $themeInjectionService, |
|
| 53 | - IUserSession $userSession, |
|
| 54 | - IConfig $config |
|
| 55 | - ) { |
|
| 56 | - $this->initialState = $initialState; |
|
| 57 | - $this->container = $container; |
|
| 58 | - $this->themeInjectionService = $themeInjectionService; |
|
| 59 | - $this->userSession = $userSession; |
|
| 60 | - $this->config = $config; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - public function handle(Event $event): void { |
|
| 64 | - $this->initialState->provideLazyInitialState( |
|
| 65 | - 'data', |
|
| 66 | - fn () => $this->container->get(JSDataService::class), |
|
| 67 | - ); |
|
| 68 | - |
|
| 69 | - /** @var BeforeTemplateRenderedEvent $event */ |
|
| 70 | - if ($event->getResponse()->getRenderAs() === TemplateResponse::RENDER_AS_USER) { |
|
| 71 | - $this->initialState->provideLazyInitialState('shortcutsDisabled', function () { |
|
| 72 | - if ($this->userSession->getUser()) { |
|
| 73 | - $uid = $this->userSession->getUser()->getUID(); |
|
| 74 | - return $this->config->getUserValue($uid, Application::APP_ID, 'shortcuts_disabled', 'no') === 'yes'; |
|
| 75 | - } |
|
| 76 | - return false; |
|
| 77 | - }); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - $this->themeInjectionService->injectHeaders(); |
|
| 81 | - |
|
| 82 | - $user = $this->userSession->getUser(); |
|
| 83 | - |
|
| 84 | - if (!empty($user)) { |
|
| 85 | - $userId = $user->getUID(); |
|
| 86 | - |
|
| 87 | - $this->initialState->provideInitialState( |
|
| 88 | - 'background', |
|
| 89 | - $this->config->getUserValue($userId, Application::APP_ID, 'background', 'default'), |
|
| 90 | - ); |
|
| 91 | - |
|
| 92 | - $this->initialState->provideInitialState( |
|
| 93 | - 'backgroundVersion', |
|
| 94 | - $this->config->getUserValue($userId, Application::APP_ID, 'backgroundVersion', 0), |
|
| 95 | - ); |
|
| 96 | - |
|
| 97 | - $this->initialState->provideInitialState( |
|
| 98 | - 'themingDefaultBackground', |
|
| 99 | - $this->config->getAppValue('theming', 'backgroundMime', ''), |
|
| 100 | - ); |
|
| 101 | - |
|
| 102 | - $this->initialState->provideInitialState( |
|
| 103 | - 'shippedBackgrounds', |
|
| 104 | - BackgroundService::SHIPPED_BACKGROUNDS, |
|
| 105 | - ); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - // Making sure to inject just after core |
|
| 109 | - \OCP\Util::addScript('theming', 'theming', 'core'); |
|
| 110 | - } |
|
| 43 | + private IInitialState $initialState; |
|
| 44 | + private ContainerInterface $container; |
|
| 45 | + private ThemeInjectionService $themeInjectionService; |
|
| 46 | + private IUserSession $userSession; |
|
| 47 | + private IConfig $config; |
|
| 48 | + |
|
| 49 | + public function __construct( |
|
| 50 | + IInitialState $initialState, |
|
| 51 | + ContainerInterface $container, |
|
| 52 | + ThemeInjectionService $themeInjectionService, |
|
| 53 | + IUserSession $userSession, |
|
| 54 | + IConfig $config |
|
| 55 | + ) { |
|
| 56 | + $this->initialState = $initialState; |
|
| 57 | + $this->container = $container; |
|
| 58 | + $this->themeInjectionService = $themeInjectionService; |
|
| 59 | + $this->userSession = $userSession; |
|
| 60 | + $this->config = $config; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + public function handle(Event $event): void { |
|
| 64 | + $this->initialState->provideLazyInitialState( |
|
| 65 | + 'data', |
|
| 66 | + fn () => $this->container->get(JSDataService::class), |
|
| 67 | + ); |
|
| 68 | + |
|
| 69 | + /** @var BeforeTemplateRenderedEvent $event */ |
|
| 70 | + if ($event->getResponse()->getRenderAs() === TemplateResponse::RENDER_AS_USER) { |
|
| 71 | + $this->initialState->provideLazyInitialState('shortcutsDisabled', function () { |
|
| 72 | + if ($this->userSession->getUser()) { |
|
| 73 | + $uid = $this->userSession->getUser()->getUID(); |
|
| 74 | + return $this->config->getUserValue($uid, Application::APP_ID, 'shortcuts_disabled', 'no') === 'yes'; |
|
| 75 | + } |
|
| 76 | + return false; |
|
| 77 | + }); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + $this->themeInjectionService->injectHeaders(); |
|
| 81 | + |
|
| 82 | + $user = $this->userSession->getUser(); |
|
| 83 | + |
|
| 84 | + if (!empty($user)) { |
|
| 85 | + $userId = $user->getUID(); |
|
| 86 | + |
|
| 87 | + $this->initialState->provideInitialState( |
|
| 88 | + 'background', |
|
| 89 | + $this->config->getUserValue($userId, Application::APP_ID, 'background', 'default'), |
|
| 90 | + ); |
|
| 91 | + |
|
| 92 | + $this->initialState->provideInitialState( |
|
| 93 | + 'backgroundVersion', |
|
| 94 | + $this->config->getUserValue($userId, Application::APP_ID, 'backgroundVersion', 0), |
|
| 95 | + ); |
|
| 96 | + |
|
| 97 | + $this->initialState->provideInitialState( |
|
| 98 | + 'themingDefaultBackground', |
|
| 99 | + $this->config->getAppValue('theming', 'backgroundMime', ''), |
|
| 100 | + ); |
|
| 101 | + |
|
| 102 | + $this->initialState->provideInitialState( |
|
| 103 | + 'shippedBackgrounds', |
|
| 104 | + BackgroundService::SHIPPED_BACKGROUNDS, |
|
| 105 | + ); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + // Making sure to inject just after core |
|
| 109 | + \OCP\Util::addScript('theming', 'theming', 'core'); |
|
| 110 | + } |
|
| 111 | 111 | } |
@@ -68,7 +68,7 @@ |
||
| 68 | 68 | |
| 69 | 69 | /** @var BeforeTemplateRenderedEvent $event */ |
| 70 | 70 | if ($event->getResponse()->getRenderAs() === TemplateResponse::RENDER_AS_USER) { |
| 71 | - $this->initialState->provideLazyInitialState('shortcutsDisabled', function () { |
|
| 71 | + $this->initialState->provideLazyInitialState('shortcutsDisabled', function() { |
|
| 72 | 72 | if ($this->userSession->getUser()) { |
| 73 | 73 | $uid = $this->userSession->getUser()->getUID(); |
| 74 | 74 | return $this->config->getUserValue($uid, Application::APP_ID, 'shortcuts_disabled', 'no') === 'yes'; |
@@ -36,19 +36,19 @@ |
||
| 36 | 36 | use OCP\Config\BeforePreferenceSetEvent; |
| 37 | 37 | |
| 38 | 38 | class Application extends App implements IBootstrap { |
| 39 | - public const APP_ID = 'theming'; |
|
| 39 | + public const APP_ID = 'theming'; |
|
| 40 | 40 | |
| 41 | - public function __construct() { |
|
| 42 | - parent::__construct(self::APP_ID); |
|
| 43 | - } |
|
| 41 | + public function __construct() { |
|
| 42 | + parent::__construct(self::APP_ID); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - public function register(IRegistrationContext $context): void { |
|
| 46 | - $context->registerCapability(Capabilities::class); |
|
| 47 | - $context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class); |
|
| 48 | - $context->registerEventListener(BeforePreferenceSetEvent::class, BeforePreferenceListener::class); |
|
| 49 | - $context->registerEventListener(BeforePreferenceDeletedEvent::class, BeforePreferenceListener::class); |
|
| 50 | - } |
|
| 45 | + public function register(IRegistrationContext $context): void { |
|
| 46 | + $context->registerCapability(Capabilities::class); |
|
| 47 | + $context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class); |
|
| 48 | + $context->registerEventListener(BeforePreferenceSetEvent::class, BeforePreferenceListener::class); |
|
| 49 | + $context->registerEventListener(BeforePreferenceDeletedEvent::class, BeforePreferenceListener::class); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - public function boot(IBootContext $context): void { |
|
| 53 | - } |
|
| 52 | + public function boot(IBootContext $context): void { |
|
| 53 | + } |
|
| 54 | 54 | } |
@@ -34,30 +34,30 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | interface IInitialState { |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Allows an app to provide its initial state to the template system. |
|
| 39 | - * Use this if you know your initial state sill be used for example if |
|
| 40 | - * you are in the render function of you controller. |
|
| 41 | - * |
|
| 42 | - * @since 20.0.0 |
|
| 43 | - * |
|
| 44 | - * @param string $key |
|
| 45 | - * @param bool|int|float|string|array|\JsonSerializable $data |
|
| 46 | - */ |
|
| 47 | - public function provideInitialState(string $key, $data): void; |
|
| 37 | + /** |
|
| 38 | + * Allows an app to provide its initial state to the template system. |
|
| 39 | + * Use this if you know your initial state sill be used for example if |
|
| 40 | + * you are in the render function of you controller. |
|
| 41 | + * |
|
| 42 | + * @since 20.0.0 |
|
| 43 | + * |
|
| 44 | + * @param string $key |
|
| 45 | + * @param bool|int|float|string|array|\JsonSerializable $data |
|
| 46 | + */ |
|
| 47 | + public function provideInitialState(string $key, $data): void; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Allows an app to provide its initial state via a lazy method. |
|
| 51 | - * This will call the closure when the template is being generated. |
|
| 52 | - * Use this if your app is injected into pages. Since then the render method |
|
| 53 | - * is not called explicitly. But we do not want to load the state on webdav |
|
| 54 | - * requests for example. |
|
| 55 | - * |
|
| 56 | - * @since 20.0.0 |
|
| 57 | - * |
|
| 58 | - * @param string $key |
|
| 59 | - * @param Closure $closure returns a primitive or an object that implements JsonSerializable |
|
| 60 | - * @psalm-param Closure():bool|Closure():int|Closure():float|Closure():string|Closure():\JsonSerializable $closure |
|
| 61 | - */ |
|
| 62 | - public function provideLazyInitialState(string $key, Closure $closure): void; |
|
| 49 | + /** |
|
| 50 | + * Allows an app to provide its initial state via a lazy method. |
|
| 51 | + * This will call the closure when the template is being generated. |
|
| 52 | + * Use this if your app is injected into pages. Since then the render method |
|
| 53 | + * is not called explicitly. But we do not want to load the state on webdav |
|
| 54 | + * requests for example. |
|
| 55 | + * |
|
| 56 | + * @since 20.0.0 |
|
| 57 | + * |
|
| 58 | + * @param string $key |
|
| 59 | + * @param Closure $closure returns a primitive or an object that implements JsonSerializable |
|
| 60 | + * @psalm-param Closure():bool|Closure():int|Closure():float|Closure():string|Closure():\JsonSerializable $closure |
|
| 61 | + */ |
|
| 62 | + public function provideLazyInitialState(string $key, Closure $closure): void; |
|
| 63 | 63 | } |