From 959aa90f1aa31dd1af024b3e4a07de80ace2aea7 Mon Sep 17 00:00:00 2001 From: Matias De lellis Date: Fri, 18 Sep 2020 09:27:23 -0300 Subject: [PATCH] Register nextcloud capabilities to check api versions.. ... ... 0.6.0 1.0 ... --- lib/AppInfo/Application.php | 13 +++++++-- lib/AppInfo/Capabilities.php | 47 +++++++++++++++++++++++++++++++++ lib/Service/SettingsService.php | 4 +-- 3 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 lib/AppInfo/Capabilities.php diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index f67f6d1..719d758 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -32,14 +32,18 @@ use OCP\IServerContainer; class Application extends App { /** @var string */ - public const APP_NAME = 'quicknotes'; + public const APP_ID = 'quicknotes'; + + /** @var string */ + public const API_VERSION = '1.0'; public function __construct(array $urlParams = []) { - parent::__construct(self::APP_NAME, $urlParams); + parent::__construct(self::APP_ID, $urlParams); } public function register(): void { $this->registerNavigationEntry(); + $this->registerCapabilities(); } private function registerNavigationEntry(): void { @@ -59,4 +63,9 @@ class Application extends App { }); } + private function registerCapabilities(): void { + $container = $this->getContainer(); + $container->registerCapability(Capabilities::class); + } + } \ No newline at end of file diff --git a/lib/AppInfo/Capabilities.php b/lib/AppInfo/Capabilities.php new file mode 100644 index 0000000..a24939a --- /dev/null +++ b/lib/AppInfo/Capabilities.php @@ -0,0 +1,47 @@ + + * + * @author 2016 Matias De lellis + * + * @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 . + */ + + +namespace OCA\QuickNotes\AppInfo; + +use OCP\Capabilities\ICapability; +use OCP\App\IAppManager; + +class Capabilities implements ICapability { + + /** @var IAppManager */ + private $appManager; + + public function __construct(IAppManager $appManager) { + $this->appManager = $appManager; + } + + public function getCapabilities() { + return [ + Application::APP_ID => [ + 'version' => $this->appManager->getAppVersion(Application::APP_ID), + 'api_version' => Application::API_VERSION, + ], + ]; + } + +} \ No newline at end of file diff --git a/lib/Service/SettingsService.php b/lib/Service/SettingsService.php index 97ff5bc..0df0daf 100644 --- a/lib/Service/SettingsService.php +++ b/lib/Service/SettingsService.php @@ -55,11 +55,11 @@ class SettingsService { public function getColorForNewNotes(): string { - return $this->config->getUserValue($this->userId, Application::APP_NAME, self::COLOR_FOR_NEW_NOTES_KEY, self::DEFAULT_COLOR_FOR_NEW_NOTES); + return $this->config->getUserValue($this->userId, Application::APP_ID, self::COLOR_FOR_NEW_NOTES_KEY, self::DEFAULT_COLOR_FOR_NEW_NOTES); } public function setColorForNewNotes(string $color) { - $this->config->setUserValue($this->userId, Application::APP_NAME, self::COLOR_FOR_NEW_NOTES_KEY, $color); + $this->config->setUserValue($this->userId, Application::APP_ID, self::COLOR_FOR_NEW_NOTES_KEY, $color); } }