diff options
author | Julius Härtl <jus@bitgrid.net> | 2020-09-03 16:18:47 +0300 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2020-09-03 16:18:47 +0300 |
commit | b70eaed7c5614da0a062c50c5c9d6a891a322122 (patch) | |
tree | 2382fd54d6c9fc8c02c8b3531bf6a1ca952c2620 | |
parent | eaaa6f812a9e9ad5c44eecb42780f3f946d248fb (diff) |
Move to IBootstrap and make app 20 compatible
Signed-off-by: Julius Härtl <jus@bitgrid.net>
-rw-r--r-- | appinfo/app.php | 38 | ||||
-rw-r--r-- | appinfo/info.xml | 4 | ||||
-rw-r--r-- | lib/AppInfo/Application.php | 50 | ||||
-rw-r--r-- | lib/Listeners/BeforeTemplateRenderedListener.php | 71 |
4 files changed, 123 insertions, 40 deletions
diff --git a/appinfo/app.php b/appinfo/app.php deleted file mode 100644 index 873bc31..0000000 --- a/appinfo/app.php +++ /dev/null @@ -1,38 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2017 Julius Härtl <jus@bitgrid.net> - * - * @author Julius Härtl <jus@bitgrid.net> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -$linkToCSS = \OC::$server->getURLGenerator()->linkToRoute( - 'theming_customcss.Theming.getStylesheet', - [ - 'v' => \OC::$server->getConfig()->getAppValue('theming_customcss', 'cachebuster', '0'), - ] -); -\OCP\Util::addHeader( - 'link', - [ - 'rel' => 'stylesheet', - 'href' => $linkToCSS, - ] -); - -$app = new \OCP\AppFramework\App('theming_customcss'); diff --git a/appinfo/info.xml b/appinfo/info.xml index 0253216..eb276bf 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -4,14 +4,14 @@ <name>Custom CSS</name> <summary>Adjust the Nextcloud theme with custom CSS</summary> <description>Adjust the Nextcloud theme with custom CSS</description> - <version>1.6.0</version> + <version>1.7.0</version> <licence>agpl</licence> <author>Julius Härtl</author> <namespace>ThemingCustomCss</namespace> <category>customization</category> <bugs>https://github.com/juliushaertl/theming_customcss/issues</bugs> <dependencies> - <nextcloud min-version="12" max-version="19" /> + <nextcloud min-version="20" max-version="20" /> </dependencies> <settings> <admin>OCA\ThemingCustomCss\Settings\Admin</admin> diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php new file mode 100644 index 0000000..3361a1e --- /dev/null +++ b/lib/AppInfo/Application.php @@ -0,0 +1,50 @@ +<?php +/** + * @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net> + * + * @author Julius Härtl <jus@bitgrid.net> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +declare(strict_types=1); + + +namespace OCA\ThemingCustomCss\AppInfo; + +use OCA\ThemingCustomCss\Listeners\BeforeTemplateRenderedListener; +use OCP\AppFramework\App; +use OCP\AppFramework\Bootstrap\IBootContext; +use OCP\AppFramework\Bootstrap\IBootstrap; +use OCP\AppFramework\Bootstrap\IRegistrationContext; +use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; + +class Application extends App implements IBootstrap { + + public const APP_ID = 'theming_customcss'; + + public function __construct() { + parent::__construct(self::APP_ID); + } + + public function register(IRegistrationContext $context): void { + $context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class); + } + + public function boot(IBootContext $context): void { + } +} diff --git a/lib/Listeners/BeforeTemplateRenderedListener.php b/lib/Listeners/BeforeTemplateRenderedListener.php new file mode 100644 index 0000000..8660e25 --- /dev/null +++ b/lib/Listeners/BeforeTemplateRenderedListener.php @@ -0,0 +1,71 @@ +<?php +/** + * @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net> + * + * @author Julius Härtl <jus@bitgrid.net> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +declare(strict_types=1); + + +namespace OCA\ThemingCustomCss\Listeners; + + +use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\IConfig; +use OCP\IURLGenerator; +use OCP\Util; + +class BeforeTemplateRenderedListener implements IEventListener { + + /** @var IConfig */ + private $config; + /** @var IURLGenerator */ + private $urlGenerator; + + public function __construct( + IConfig $config, + IURLGenerator $urlGenerator + ) { + $this->config = $config; + $this->urlGenerator = $urlGenerator; + } + + public function handle(Event $event): void { + if (!$event instanceof BeforeTemplateRenderedEvent) { + return; + } + + $linkToCSS = $this->urlGenerator->linkToRoute( + 'theming_customcss.Theming.getStylesheet', + [ + 'v' => $this->config->getAppValue('theming_customcss', 'cachebuster', '0'), + ] + ); + Util::addHeader( + 'link', + [ + 'rel' => 'stylesheet', + 'href' => $linkToCSS, + ] + ); + } +} |