Move accessibility over to the new way

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2020-10-03 15:47:58 +02:00
parent f865a3a1c2
commit b5fd75f2be
No known key found for this signature in database
GPG Key ID: F941078878347C0C
2 changed files with 8 additions and 14 deletions

View File

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

View File

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