Skip to content

Commit 5de1f0b

Browse files
feat: add repair step to install default fonts on installation
Signed-off-by: Luka Trovic <[email protected]>
1 parent 9eea957 commit 5de1f0b

File tree

7 files changed

+116
-0
lines changed

7 files changed

+116
-0
lines changed

appinfo/info.xml

+6
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,17 @@ You can also edit your documents off-line with the Collabora Office app from the
3535
<command>OCA\Richdocuments\Command\ActivateConfig</command>
3636
<command>OCA\Richdocuments\Command\ConvertToBigInt</command>
3737
<command>OCA\Richdocuments\Command\UpdateEmptyTemplates</command>
38+
<command>OCA\Richdocuments\Command\InstallDefaultFonts</command>
3839
</commands>
3940
<settings>
4041
<admin>OCA\Richdocuments\Settings\Admin</admin>
4142
<admin-section>OCA\Richdocuments\Settings\Section</admin-section>
4243
<personal>OCA\Richdocuments\Settings\Personal</personal>
4344
<personal-section>OCA\Richdocuments\Settings\Section</personal-section>
4445
</settings>
46+
<repair-steps>
47+
<install>
48+
<step>OCA\Richdocuments\Migration\InstallDefaultFonts</step>
49+
</install>
50+
</repair-steps>
4551
</info>

assets/fonts/AmaticSC-Regular.ttf

139 KB
Binary file not shown.

cypress/e2e/settings.spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { User } from '@nextcloud/cypress'
2121

2222
const usesHttps = Cypress.env('baseUrl').substr(0, 5) === 'https'
2323
const collaboraUrl = Cypress.env('collaboraUrl')
24+
const defaultFonts = ['AmaticSC-Regular.ttf']
2425

2526
describe('Office admin settings', function() {
2627

@@ -77,6 +78,13 @@ describe('Office admin settings', function() {
7778
.scrollIntoView()
7879
.should('be.visible')
7980

81+
cy.get('#font-settings')
82+
.scrollIntoView()
83+
.should('be.visible')
84+
defaultFonts.forEach(font => {
85+
cy.get('.settings-entry.font-list-settings').contains(font)
86+
})
87+
8088
// FIXME: Template settings only get visible after reload
8189
cy.reload()
8290
cy.get('#richdocuments-templates')

lib/Command/InstallDefaultFonts.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace OCA\Richdocuments\Command;
4+
5+
use OCA\Richdocuments\Service\FontService;
6+
use Symfony\Component\Console\Command\Command;
7+
use Symfony\Component\Console\Input\InputInterface;
8+
use Symfony\Component\Console\Output\OutputInterface;
9+
10+
class InstallDefaultFonts extends Command {
11+
public function __construct(private FontService $fontService) {
12+
parent::__construct();
13+
}
14+
15+
protected function configure() {
16+
$this
17+
->setName('richdocuments:install-fonts')
18+
->setDescription('Install default fonts');
19+
}
20+
21+
protected function execute(InputInterface $input, OutputInterface $output) {
22+
try {
23+
$this->fontService->installDefaultFonts();
24+
return 0;
25+
} catch (\Exception $e) {
26+
$output->writeln('<error>Failed to install default fonts</error>');
27+
$output->writeln($e->getMessage());
28+
$output->writeln($e->getTraceAsString());
29+
return 1;
30+
}
31+
}
32+
}

lib/Migration/InstallDefaultFonts.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace OCA\Richdocuments\Migration;
4+
5+
use OCA\Richdocuments\Service\FontService;
6+
use OCP\IConfig;
7+
use OCP\Migration\IOutput;
8+
use OCP\Migration\IRepairStep;
9+
10+
class InstallDefaultFonts implements IRepairStep {
11+
public function __construct(private IConfig $config, private FontService $fontService) {
12+
}
13+
14+
public function getName(): string {
15+
return 'Install default fonts';
16+
}
17+
18+
public function run(IOutput $output): void {
19+
$appVersion = $this->config->getAppValue('richdocuments', 'installed_version');
20+
21+
if (version_compare($appVersion, '8.2.2') < 1) {
22+
return;
23+
}
24+
25+
$this->fontService->installDefaultFonts();
26+
}
27+
}

lib/Service/FontService.php

+38
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
namespace OCA\Richdocuments\Service;
2525

26+
use Exception;
2627
use OCA\Richdocuments\AppInfo\Application;
2728
use OCP\Files\IAppData;
2829
use OCP\Files\NotFoundException;
@@ -242,4 +243,41 @@ private function generateFontOverview(ISimpleFile $fontFile): void {
242243
// in the UI and display a fallback message
243244
}
244245
}
246+
247+
/**
248+
* @throws Exception
249+
*/
250+
public function installDefaultFonts(): void {
251+
$dirPath = __DIR__ . '/../../assets/fonts';
252+
253+
if (!is_dir($dirPath)) {
254+
throw new Exception("Directory \"$dirPath\" does not exist!");
255+
}
256+
257+
$handle = opendir($dirPath);
258+
259+
if (!$handle) {
260+
throw new Exception("Failed opening directory \"$dirPath\"!");
261+
}
262+
263+
while (false !== ($fileName = readdir($handle))) {
264+
if ($fileName === '.' || $fileName === '..') {
265+
continue;
266+
}
267+
268+
$filePath = $dirPath . '/' . $fileName;
269+
270+
if (!is_file($filePath)) {
271+
continue;
272+
}
273+
274+
$fileHandle = fopen($filePath, 'r');
275+
276+
if (!$fileHandle) {
277+
continue;
278+
}
279+
280+
$this->uploadFontFile($fileName, $fileHandle);
281+
}
282+
}
245283
}

tests/psalm-baseline.xml

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
<code>Command</code>
3434
</UndefinedClass>
3535
</file>
36+
<file src="lib/Command/InstallDefaultFonts.php">
37+
<UndefinedClass>
38+
<code>Command</code>
39+
</UndefinedClass>
40+
</file>
3641
<file src="lib/Controller/DirectViewController.php">
3742
<InvalidScalarArgument>
3843
<code><![CDATA[$item->getId()]]></code>

0 commit comments

Comments
 (0)