Skip to content

Commit e8d3eac

Browse files
committed
feat: add preferred apps/providers and use them first
Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
1 parent 4901f72 commit e8d3eac

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

lib/private/Files/Conversion/ConversionManager.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,16 @@
2626
use Throwable;
2727

2828
class ConversionManager implements IConversionManager {
29-
/** @var ?IConversionProvider[] */
30-
private ?array $providers = null;
29+
/** @var string[] */
30+
private array $preferredApps = [
31+
'richdocuments',
32+
];
33+
34+
/** @var IConversionProvider[] */
35+
private array $preferredProviders = [];
36+
37+
/** @var IConversionProvider[] */
38+
private array $providers = [];
3139

3240
public function __construct(
3341
private Coordinator $coordinator,
@@ -51,7 +59,7 @@ public function getMimeTypes(): array {
5159
array_push($mimeTypes, $provider->getSupportedMimeType());
5260
}
5361

54-
return array_merge([], $mimeTypes);
62+
return $mimeTypes;
5563
}
5664

5765
public function convert(File $file, string $targetMimeType, ?string $destination = null): string {
@@ -96,17 +104,21 @@ public function convert(File $file, string $targetMimeType, ?string $destination
96104
}
97105

98106
public function getProviders(): array {
99-
if ($this->providers !== null) {
107+
if (count($this->providers) > 0) {
100108
return $this->providers;
101109
}
102110

103111
$context = $this->coordinator->getRegistrationContext();
104-
$this->providers = [];
105-
106112
foreach ($context->getFileConversionProviders() as $providerRegistration) {
107113
$class = $providerRegistration->getService();
114+
$appId = $providerRegistration->getAppId();
108115

109116
try {
117+
if (in_array($appId, $this->preferredApps)) {
118+
$this->preferredProviders[$class] = $this->serverContainer->get($class);
119+
continue;
120+
}
121+
110122
$this->providers[$class] = $this->serverContainer->get($class);
111123
} catch (NotFoundExceptionInterface|ContainerExceptionInterface|Throwable $e) {
112124
$this->logger->error('Failed to load file conversion provider ' . $class, [
@@ -115,7 +127,7 @@ public function getProviders(): array {
115127
}
116128
}
117129

118-
return $this->providers;
130+
return array_merge([], $this->preferredProviders, $this->providers);
119131
}
120132

121133
private function writeToDestination(string $destination, mixed $content): File {

0 commit comments

Comments
 (0)