From d12a5becb4a23e68ac140b2e2269be282ca8501f Mon Sep 17 00:00:00 2001 From: Luka Trovic Date: Fri, 5 Jan 2024 18:04:29 +0100 Subject: [PATCH] fix: translate popup does not open in mobile apps Signed-off-by: Luka Trovic --- lib/DirectEditing/TextDirectEditor.php | 15 ++++++++------- lib/Service/InitialStateProvider.php | 8 ++++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/DirectEditing/TextDirectEditor.php b/lib/DirectEditing/TextDirectEditor.php index dfec634ac2d..a61eb9a2d90 100644 --- a/lib/DirectEditing/TextDirectEditor.php +++ b/lib/DirectEditing/TextDirectEditor.php @@ -25,10 +25,10 @@ use OCA\Text\AppInfo\Application; use OCA\Text\Service\ApiService; +use OCA\Text\Service\InitialStateProvider; use OCP\AppFramework\Http\NotFoundResponse; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\TemplateResponse; -use OCP\AppFramework\Services\IInitialState; use OCP\DirectEditing\IEditor; use OCP\DirectEditing\IToken; use OCP\Files\InvalidPathException; @@ -42,15 +42,15 @@ class TextDirectEditor implements IEditor { /** @var IL10N */ private $l10n; - /** @var IInitialState */ - private $initialStateService; + /** @var InitialStateProvider */ + private $initialStateProvider; /** @var ApiService */ private $apiService; - public function __construct(IL10N $l10n, IInitialState $initialStateService, ApiService $apiService) { + public function __construct(IL10N $l10n, InitialStateProvider $initialStateProvider, ApiService $apiService) { $this->l10n = $l10n; - $this->initialStateService = $initialStateService; + $this->initialStateProvider = $initialStateProvider; $this->apiService = $apiService; } @@ -153,12 +153,13 @@ public function open(IToken $token): Response { $token->useTokenScope(); try { $session = $this->apiService->create($token->getFile()->getId()); - $this->initialStateService->provideInitialState('file', [ + $this->initialStateProvider->provideFile([ 'fileId' => $token->getFile()->getId(), 'mimetype' => $token->getFile()->getMimeType(), 'session' => \json_encode($session->getData()) ]); - $this->initialStateService->provideInitialState('directEditingToken', $token->getToken()); + $this->initialStateProvider->provideDirectEditToken($token->getToken()); + $this->initialStateProvider->provideState(); Util::addScript('text', 'text-text'); return new TemplateResponse('text', 'main', [], 'base'); } catch (InvalidPathException $e) { diff --git a/lib/Service/InitialStateProvider.php b/lib/Service/InitialStateProvider.php index aa250482e83..0471b05a662 100644 --- a/lib/Service/InitialStateProvider.php +++ b/lib/Service/InitialStateProvider.php @@ -64,4 +64,12 @@ public function provideState(): void { public function provideFileId(int $fileId): void { $this->initialState->provideInitialState('file_id', $fileId); } + + public function provideFile(array $fileData): void { + $this->initialState->provideInitialState('file', $fileData); + } + + public function provideDirectEditToken(string $token): void { + $this->initialState->provideInitialState('directEditingToken', $token); + } }