Skip to content

Commit

Permalink
fix: Make template file creator registration compatible with 28/29
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Knorr <jus@bitgrid.net>
  • Loading branch information
juliushaertl committed Sep 17, 2024
1 parent fd23e8e commit 47905e9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
12 changes: 11 additions & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Files\Template\ITemplateManager;
use OCP\Files\Template\RegisterTemplateCreatorEvent;
use OCP\IL10N;
use OCP\Security\CSP\AddContentSecurityPolicyEvent;
use OCP\Util;

/**
* @psalm-suppress UndefinedClass
Expand All @@ -44,6 +47,13 @@ public function register(IRegistrationContext $context): void {
}

public function boot(IBootContext $context): void {

[$major] = Util::getVersion();
if ($major < 30) {
$context->injectFn(function (ITemplateManager $templateManager, IL10N $l10n) use ($major) {
$templateManager->registerTemplateFileCreator(function () use ($l10n) {
return RegisterTemplateCreatorListener::getTemplateFileCreator($l10n);
});
});
}
}
}
14 changes: 9 additions & 5 deletions lib/Listener/RegisterTemplateCreatorListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ public function handle(Event $event): void {


$event->getTemplateManager()->registerTemplateFileCreator(function () {
$whiteboard = new TemplateFileCreator(Application::APP_ID, $this->l10n->t('New whiteboard'), '.whiteboard');
$whiteboard->addMimetype('application/vnd.excalidraw+json');
$whiteboard->setIconSvgInline(file_get_contents(__DIR__ . '/../../img/app-filetype.svg'));
$whiteboard->setActionLabel($this->l10n->t('Create new whiteboard'));
return $whiteboard;
return self::getTemplateFileCreator($this->l10n);
});
}

public static function getTemplateFileCreator(IL10N $l10n): TemplateFileCreator {
$whiteboard = new TemplateFileCreator(Application::APP_ID, $l10n->t('New whiteboard'), '.whiteboard');
$whiteboard->addMimetype('application/vnd.excalidraw+json');
$whiteboard->setIconSvgInline(file_get_contents(__DIR__ . '/../../img/app-filetype.svg'));
$whiteboard->setActionLabel($l10n->t('Create new whiteboard'));
return $whiteboard;
}
}

0 comments on commit 47905e9

Please sign in to comment.