Skip to content

Commit

Permalink
Merge pull request #5197 from nextcloud/bugfix/open-translate-on-mobile
Browse files Browse the repository at this point in the history
fix: translate popup does not open in mobile apps
  • Loading branch information
juliusknorr authored Jan 25, 2024
2 parents f57511c + d12a5be commit 22985c0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/DirectEditing/TextDirectEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions lib/Service/InitialStateProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 22985c0

Please sign in to comment.