From 9943855393e4891f32484a7a70b936ea7aad3abf Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Tue, 20 Oct 2020 12:36:41 +0200 Subject: [PATCH] override default dashboard background with theming one fix getAppValue default value in theming app fix cacheBuster value injection Signed-off-by: Julien Veyssier --- .../lib/Controller/DashboardController.php | 10 ++++++++++ apps/dashboard/src/App.vue | 13 ++++++++----- .../dashboard/src/components/BackgroundSettings.vue | 8 ++++++-- apps/dashboard/src/helpers/getBackgroundUrl.js | 5 ++++- apps/theming/lib/Capabilities.php | 6 +++--- apps/theming/lib/ImageManager.php | 4 ++-- apps/theming/lib/Service/JSDataService.php | 2 +- apps/theming/lib/ThemingDefaults.php | 6 +++--- apps/theming/lib/Util.php | 2 +- 9 files changed, 38 insertions(+), 18 deletions(-) diff --git a/apps/dashboard/lib/Controller/DashboardController.php b/apps/dashboard/lib/Controller/DashboardController.php index 57717b2669843..bc6cd02abbc5f 100644 --- a/apps/dashboard/lib/Controller/DashboardController.php +++ b/apps/dashboard/lib/Controller/DashboardController.php @@ -35,6 +35,7 @@ use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\NotFoundResponse; use OCP\AppFramework\Http\TemplateResponse; +use OCP\App\IAppManager; use OCP\Dashboard\IManager; use OCP\Dashboard\IWidget; use OCP\Dashboard\RegisterWidgetEvent; @@ -49,6 +50,8 @@ class DashboardController extends Controller { private $inititalStateService; /** @var IEventDispatcher */ private $eventDispatcher; + /** @var IAppManager */ + private $appManager; /** @var IManager */ private $dashboardManager; /** @var IConfig */ @@ -65,6 +68,7 @@ public function __construct( IRequest $request, IInitialStateService $initialStateService, IEventDispatcher $eventDispatcher, + IAppManager $appManager, IManager $dashboardManager, IConfig $config, BackgroundService $backgroundService, @@ -74,6 +78,7 @@ public function __construct( $this->inititalStateService = $initialStateService; $this->eventDispatcher = $eventDispatcher; + $this->appManager = $appManager; $this->dashboardManager = $dashboardManager; $this->config = $config; $this->backgroundService = $backgroundService; @@ -109,6 +114,11 @@ public function index(): TemplateResponse { // It does not matter if some statuses are missing from the array, missing ones are considered enabled $statuses = ($statuses && count($statuses) > 0) ? $statuses : ['weather' => true]; + // if theming app is enabled and wants to override default, we pass it + $themingDefaultBackground = $this->appManager->isEnabledForUser('theming') + ? $this->config->getAppValue('theming', 'backgroundMime', '') + : ''; + $this->inititalStateService->provideInitialState('dashboard', 'themingDefaultBackground', $themingDefaultBackground); $this->inititalStateService->provideInitialState('dashboard', 'panels', $widgets); $this->inititalStateService->provideInitialState('dashboard', 'statuses', $statuses); $this->inititalStateService->provideInitialState('dashboard', 'layout', $userLayout); diff --git a/apps/dashboard/src/App.vue b/apps/dashboard/src/App.vue index 0d09bcc45377c..c5eed836faa99 100644 --- a/apps/dashboard/src/App.vue +++ b/apps/dashboard/src/App.vue @@ -68,7 +68,9 @@ {{ t('dashboard', 'Get more widgets from the app store') }}

{{ t('dashboard', 'Change background image') }}

- +

{{ t('dashboard', 'Weather service') }}

@@ -95,11 +97,11 @@ import { generateUrl } from '@nextcloud/router' import isMobile from './mixins/isMobile' import BackgroundSettings from './components/BackgroundSettings' import getBackgroundUrl from './helpers/getBackgroundUrl' -import prefixWithBaseUrl from './helpers/prefixWithBaseUrl' const panels = loadState('dashboard', 'panels') const firstRun = loadState('dashboard', 'firstRun') const background = loadState('dashboard', 'background') +const themingDefaultBackground = loadState('dashboard', 'themingDefaultBackground') const version = loadState('dashboard', 'version') const shippedBackgroundList = loadState('dashboard', 'shippedBackgrounds') const statusInfo = { @@ -142,16 +144,17 @@ export default { appStoreUrl: generateUrl('/settings/apps/dashboard'), statuses: {}, background, + themingDefaultBackground, version, - defaultBackground: window.OCA.Accessibility?.theme === 'dark' ? prefixWithBaseUrl('flickr-148302424@N05-36591009215.jpg?v=1') : prefixWithBaseUrl('flickr-paszczak000-8715851521.jpg?v=1'), } }, computed: { backgroundImage() { - return getBackgroundUrl(this.background, this.version) + return getBackgroundUrl(this.background, this.version, this.themingDefaultBackground) }, backgroundStyle() { - if (this.background.match(/#[0-9A-Fa-f]{6}/g)) { + if ((this.background === 'default' && this.themingDefaultBackground === 'backgroundColor') + || this.background.match(/#[0-9A-Fa-f]{6}/g)) { return null } return { diff --git a/apps/dashboard/src/components/BackgroundSettings.vue b/apps/dashboard/src/components/BackgroundSettings.vue index be94737fdadec..936cfdef4864d 100644 --- a/apps/dashboard/src/components/BackgroundSettings.vue +++ b/apps/dashboard/src/components/BackgroundSettings.vue @@ -66,6 +66,10 @@ export default { type: String, default: 'default', }, + themingDefaultBackground: { + type: String, + default: '', + }, }, data() { return { @@ -88,8 +92,8 @@ export default { methods: { async update(data) { const background = data.type === 'custom' || data.type === 'default' ? data.type : data.value - this.backgroundImage = getBackgroundUrl(background, data.version) - if (data.type === 'color') { + this.backgroundImage = getBackgroundUrl(background, data.version, this.themingDefaultBackground) + if (data.type === 'color' || (data.type === 'default' && this.themingDefaultBackground === 'backgroundColor')) { this.$emit('update:background', data) this.loading = false return diff --git a/apps/dashboard/src/helpers/getBackgroundUrl.js b/apps/dashboard/src/helpers/getBackgroundUrl.js index 6090786884ced..3af48030534e4 100644 --- a/apps/dashboard/src/helpers/getBackgroundUrl.js +++ b/apps/dashboard/src/helpers/getBackgroundUrl.js @@ -23,8 +23,11 @@ import { generateUrl } from '@nextcloud/router' import prefixWithBaseUrl from './prefixWithBaseUrl' -export default (background, time = 0) => { +export default (background, time = 0, themingDefaultBackground = '') => { if (background === 'default') { + if (themingDefaultBackground && themingDefaultBackground !== 'backgroundColor') { + return generateUrl('/apps/theming/image/background') + '?v=' + window.OCA.Theming.cacheBuster + } if (window.OCA.Accessibility.theme === 'dark') { return prefixWithBaseUrl('eduardo-neves-pedra-azul.jpg') } diff --git a/apps/theming/lib/Capabilities.php b/apps/theming/lib/Capabilities.php index d10002c9deae8..f0c4d2663622c 100644 --- a/apps/theming/lib/Capabilities.php +++ b/apps/theming/lib/Capabilities.php @@ -69,7 +69,7 @@ public function __construct(ThemingDefaults $theming, Util $util, IURLGenerator * @return array */ public function getCapabilities() { - $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', false); + $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', ''); $color = $this->theming->getColorPrimary(); return [ 'theming' => [ @@ -82,10 +82,10 @@ public function getCapabilities() { 'color-element-bright' => $this->util->elementColor($color), 'color-element-dark' => $this->util->elementColor($color, false), 'logo' => $this->url->getAbsoluteURL($this->theming->getLogo()), - 'background' => $backgroundLogo === 'backgroundColor' || ($backgroundLogo === false && $this->theming->getColorPrimary() !== '#0082c9') ? + 'background' => $backgroundLogo === 'backgroundColor' || ($backgroundLogo === '' && $this->theming->getColorPrimary() !== '#0082c9') ? $this->theming->getColorPrimary() : $this->url->getAbsoluteURL($this->theming->getBackground()), - 'background-plain' => $backgroundLogo === 'backgroundColor' || ($backgroundLogo === false && $this->theming->getColorPrimary() !== '#0082c9'), + 'background-plain' => $backgroundLogo === 'backgroundColor' || ($backgroundLogo === '' && $this->theming->getColorPrimary() !== '#0082c9'), 'background-default' => !$this->util->isBackgroundThemed(), 'logoheader' => $this->url->getAbsoluteURL($this->theming->getLogo()), 'favicon' => $this->url->getAbsoluteURL($this->theming->getLogo()), diff --git a/apps/theming/lib/ImageManager.php b/apps/theming/lib/ImageManager.php index 469480d1e1022..d3b5f6130e740 100644 --- a/apps/theming/lib/ImageManager.php +++ b/apps/theming/lib/ImageManager.php @@ -101,9 +101,9 @@ public function getImageUrlAbsolute(string $key, bool $useSvg = true): string { * @throws NotPermittedException */ public function getImage(string $key, bool $useSvg = true): ISimpleFile { - $logo = $this->config->getAppValue('theming', $key . 'Mime', false); + $logo = $this->config->getAppValue('theming', $key . 'Mime', ''); $folder = $this->appData->getFolder('images'); - if ($logo === false || !$folder->fileExists($key)) { + if ($logo === '' || !$folder->fileExists($key)) { throw new NotFoundException(); } if (!$useSvg && $this->shouldReplaceIcons()) { diff --git a/apps/theming/lib/Service/JSDataService.php b/apps/theming/lib/Service/JSDataService.php index 89c4cd9c027d1..d87d11a0fe085 100644 --- a/apps/theming/lib/Service/JSDataService.php +++ b/apps/theming/lib/Service/JSDataService.php @@ -59,7 +59,7 @@ public function jsonSerialize() { 'imprintUrl' => $this->themingDefaults->getImprintUrl(), 'privacyUrl' => $this->themingDefaults->getPrivacyUrl(), 'inverted' => $this->util->invertTextColor($this->themingDefaults->getColorPrimary()), - 'cacheBuster' => $this->appConfig->getAppValue(Application::class, 'cachebuster', '0'), + 'cacheBuster' => $this->appConfig->getAppValue(Application::APP_ID, 'cachebuster', '0'), ]; } } diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php index 01af4d1b1771b..f47e4ae294d67 100644 --- a/apps/theming/lib/ThemingDefaults.php +++ b/apps/theming/lib/ThemingDefaults.php @@ -223,7 +223,7 @@ public function getColorPrimary() { * @return string */ public function getLogo($useSvg = true): string { - $logo = $this->config->getAppValue('theming', 'logoMime', false); + $logo = $this->config->getAppValue('theming', 'logoMime', ''); // short cut to avoid setting up the filesystem just to check if the logo is there // @@ -309,13 +309,13 @@ public function getScssVariables() { $variables['image-login-background'] = "url('".$this->imageManager->getImageUrl('background')."')"; $variables['image-login-plain'] = 'false'; - if ($this->config->getAppValue('theming', 'color', null) !== null) { + if ($this->config->getAppValue('theming', 'color', '') !== '') { $variables['color-primary'] = $this->getColorPrimary(); $variables['color-primary-text'] = $this->getTextColorPrimary(); $variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary()); } - if ($this->config->getAppValue('theming', 'backgroundMime', null) === 'backgroundColor') { + if ($this->config->getAppValue('theming', 'backgroundMime', '') === 'backgroundColor') { $variables['image-login-plain'] = 'true'; } diff --git a/apps/theming/lib/Util.php b/apps/theming/lib/Util.php index 3addda9142200..e757d100a1b15 100644 --- a/apps/theming/lib/Util.php +++ b/apps/theming/lib/Util.php @@ -249,7 +249,7 @@ public function isAlreadyThemed() { } public function isBackgroundThemed() { - $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime',false); + $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', ''); $backgroundExists = true; try {