-
Notifications
You must be signed in to change notification settings - Fork 83
/
InitialStateProvider.php
67 lines (56 loc) 路 1.71 KB
/
InitialStateProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace OCA\Text\Service;
use OCP\AppFramework\Services\IInitialState;
use OCP\TextProcessing\IManager;
use OCP\TextProcessing\ITaskType;
use OCP\Translation\ITranslationManager;
class InitialStateProvider {
public function __construct(
private IInitialState $initialState,
private ConfigService $configService,
private ITranslationManager $translationManager,
private IManager $textProcessingManager,
private ?string $userId
) {
}
public function provideState(): void {
$this->initialState->provideInitialState(
'workspace_available',
$this->configService->isRichWorkspaceAvailable()
);
$this->initialState->provideInitialState(
'workspace_enabled',
$this->configService->isRichWorkspaceEnabledForUser($this->userId)
);
$this->initialState->provideInitialState(
'default_file_extension',
$this->configService->getDefaultFileExtension()
);
$this->initialState->provideInitialState(
'rich_editing_enabled',
$this->configService->isRichEditingEnabled()
);
$this->initialState->provideInitialState(
'translation_can_detect',
$this->translationManager->canDetectLanguage()
);
$this->initialState->provideInitialState(
'translation_languages',
$this->translationManager->getLanguages()
);
$this->initialState->provideInitialState(
'textprocessing',
array_map(function (string $className) {
/** @var class-string<ITaskType> $className */
$type = \OCP\Server::get($className);
return [
'task' => $className,
'name' => $type->getName(),
];
}, $this->textProcessingManager->getAvailableTaskTypes()),
);
}
public function provideFileId(int $fileId): void {
$this->initialState->provideInitialState('file_id', $fileId);
}
}