diff options
author | Julius Härtl <jus@bitgrid.net> | 2021-11-28 19:49:28 +0300 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2021-11-29 20:33:50 +0300 |
commit | 6551749b8627b2da1eca3bd07947175f4cffadfb (patch) | |
tree | 08e89417cb57cbe8c1989cf57861a66744845aca /lib/Service | |
parent | caf8284d4f2494f8a4d4461efa29212b2e2eba67 (diff) |
Introduce Nextcloud Office branding
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib/Service')
-rw-r--r-- | lib/Service/CapabilitiesService.php | 22 | ||||
-rw-r--r-- | lib/Service/InitialStateService.php | 85 |
2 files changed, 106 insertions, 1 deletions
diff --git a/lib/Service/CapabilitiesService.php b/lib/Service/CapabilitiesService.php index 3d18c957..51adc424 100644 --- a/lib/Service/CapabilitiesService.php +++ b/lib/Service/CapabilitiesService.php @@ -23,11 +23,13 @@ namespace OCA\Richdocuments\Service; +use OCA\Richdocuments\AppInfo\Application; use OCP\App\IAppManager; use OCP\Http\Client\IClientService; use OCP\ICache; use OCP\ICacheFactory; use OCP\IConfig; +use OCP\IL10N; class CapabilitiesService { @@ -39,16 +41,19 @@ class CapabilitiesService { private $cache; /** @var IAppManager */ private $appManager; + /** @var IL10N */ + private $l10n; /** @var array */ private $capabilities; - public function __construct(IConfig $config, IClientService $clientService, ICacheFactory $cacheFactory, IAppManager $appManager) { + public function __construct(IConfig $config, IClientService $clientService, ICacheFactory $cacheFactory, IAppManager $appManager, IL10N $l10n) { $this->config = $config; $this->clientService = $clientService; $this->cache = $cacheFactory->createDistributed('richdocuments'); $this->appManager = $appManager; + $this->l10n = $l10n; } public function getCapabilities() { @@ -72,6 +77,11 @@ class CapabilitiesService { return $this->capabilities; } + public function hasNextcloudBranding(): bool { + $productVersion = $this->getCapabilities()['productVersion'] ?? '0.0.0.0'; + return version_compare($productVersion, '21.11', '>='); + } + public function hasDrawSupport(): bool { $productVersion = $this->getCapabilities()['productVersion'] ?? '0.0.0.0'; return version_compare($productVersion, '6.4.7', '>='); @@ -85,6 +95,16 @@ class CapabilitiesService { return $this->getCapabilities()['hasTemplateSource'] ?? false; } + public function getProductName(): string { + $theme = $this->config->getAppValue(Application::APPNAME, 'theme', 'nextcloud'); + + if (isset($this->capabilitites['productName']) && $theme !== 'nextcloud') { + return $this->capabilitites['productName']; + } + + return $this->l10n->t('Nextcloud Office'); + } + public function clear(): void { $this->cache->remove('capabilities'); } diff --git a/lib/Service/InitialStateService.php b/lib/Service/InitialStateService.php new file mode 100644 index 00000000..ff85ec4e --- /dev/null +++ b/lib/Service/InitialStateService.php @@ -0,0 +1,85 @@ +<?php +/* + * @copyright Copyright (c) 2021 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\Richdocuments\Service; + +use OCA\Richdocuments\AppInfo\Application; +use OCA\Richdocuments\Db\Wopi; +use OCP\AppFramework\Services\IInitialState; +use OCP\IConfig; + +class InitialStateService { + + /** @var IInitialState */ + private $initialState; + + /** @var CapabilitiesService */ + private $capabilitiesService; + + /** @var IConfig */ + private $config; + + /** @var bool */ + private $hasProvidedCapabilities = false; + + public function __construct( + IInitialState $initialState, + CapabilitiesService $capabilitiesService, + IConfig $config + ) { + $this->initialState = $initialState; + $this->capabilitiesService = $capabilitiesService; + $this->config = $config; + } + + public function provideCapabilities(): void { + if ($this->hasProvidedCapabilities) { + return; + } + + $this->initialState->provideInitialState('productName', $this->capabilitiesService->getProductName()); + $this->initialState->provideInitialState('hasDrawSupport', $this->capabilitiesService->hasDrawSupport()); + $this->initialState->provideInitialState('hasNextcloudBranding', $this->capabilitiesService->hasNextcloudBranding()); + + $this->hasProvidedCapabilities = true; + } + + public function provideDocument(Wopi $wopi): void { + $this->provideCapabilities(); + + $this->initialState->provideInitialState('wopi', $wopi); + $this->initialState->provideInitialState('theme', $this->config->getAppValue(Application::APPNAME, 'theme', 'nextcloud')); + $this->initialState->provideInitialState('uiDefaults', [ + 'UIMode' => $this->config->getAppValue(Application::APPNAME, 'uiDefaults-UIMode', 'classic') + ]); + $logoSet = $this->config->getAppValue('theming', 'logoheaderMime', '') !== ''; + if (!$logoSet) { + $logoSet = $this->config->getAppValue('theming', 'logoMime', '') !== ''; + } + $this->initialState->provideInitialState('theming-customLogo', ($logoSet ? + \OC::$server->getURLGenerator()->getAbsoluteURL(\OC::$server->getThemingDefaults()->getLogo()) + : false)); + } +} |