From b5fd75f2be1429b5f6de8b1bc81a61d116e7f79a Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Sat, 3 Oct 2020 15:47:58 +0200 Subject: [PATCH] Move accessibility over to the new way Signed-off-by: Roeland Jago Douma --- apps/accessibility/lib/AppInfo/Application.php | 13 +------------ apps/accessibility/lib/Service/JSDataService.php | 9 +++++++-- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/apps/accessibility/lib/AppInfo/Application.php b/apps/accessibility/lib/AppInfo/Application.php index cd3ef069e4..5b59a24418 100644 --- a/apps/accessibility/lib/AppInfo/Application.php +++ b/apps/accessibility/lib/AppInfo/Application.php @@ -36,9 +36,7 @@ use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; -use OCP\AppFramework\IAppContainer; use OCP\IConfig; -use OCP\IInitialStateService; use OCP\IURLGenerator; use OCP\IUserSession; use function count; @@ -55,11 +53,11 @@ class Application extends App implements IBootstrap { } public function register(IRegistrationContext $context): void { + $context->registerInitialStateProvider(JSDataService::class); } public function boot(IBootContext $context): void { $context->injectFn([$this, 'injectCss']); - $context->injectFn([$this, 'registerInitialState']); } public function injectCss(IUserSession $userSession, @@ -84,13 +82,4 @@ class Application extends App implements IBootstrap { \OCP\Util::addHeader('link', ['rel' => 'stylesheet', 'media' => '(prefers-color-scheme: dark)', 'href' => $linkToCSS]); } } - - public function registerInitialState(IInitialStateService $initialState, - IAppContainer $container) { - $initialState->provideLazyInitialState(self::APP_ID, 'data', function () use ($container) { - /** @var JSDataService $data */ - $data = $container->query(JSDataService::class); - return $data; - }); - } } diff --git a/apps/accessibility/lib/Service/JSDataService.php b/apps/accessibility/lib/Service/JSDataService.php index 5ea7048b8b..3b23748757 100644 --- a/apps/accessibility/lib/Service/JSDataService.php +++ b/apps/accessibility/lib/Service/JSDataService.php @@ -27,10 +27,11 @@ declare(strict_types=1); namespace OCA\Accessibility\Service; use OCA\Accessibility\AppInfo\Application; +use OCP\AppFramework\Services\InitialStateProvider; use OCP\IConfig; use OCP\IUserSession; -class JSDataService implements \JsonSerializable { +class JSDataService extends InitialStateProvider { /** @var IUserSession */ private $userSession; /** @var IConfig */ @@ -44,7 +45,11 @@ class JSDataService implements \JsonSerializable { $this->config = $config; } - public function jsonSerialize() { + public function getKey(): string { + return 'data'; + } + + public function getData() { $user = $this->userSession->getUser(); if ($user === null) {