override default dashboard background with theming one

fix getAppValue default value in theming app
fix cacheBuster value injection

Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
Signed-off-by: npmbuildbot-nextcloud[bot] <npmbuildbot-nextcloud[bot]@users.noreply.github.com>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Julien Veyssier 2020-10-20 12:36:41 +02:00 committed by Roeland Jago Douma
parent bb32ba0c07
commit 451cb39122
11 changed files with 54 additions and 34 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -35,6 +35,7 @@ use OCP\AppFramework\Http\FileDisplayResponse;
use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\NotFoundResponse; use OCP\AppFramework\Http\NotFoundResponse;
use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Http\TemplateResponse;
use OCP\App\IAppManager;
use OCP\Dashboard\IManager; use OCP\Dashboard\IManager;
use OCP\Dashboard\IWidget; use OCP\Dashboard\IWidget;
use OCP\Dashboard\RegisterWidgetEvent; use OCP\Dashboard\RegisterWidgetEvent;
@ -49,6 +50,8 @@ class DashboardController extends Controller {
private $inititalStateService; private $inititalStateService;
/** @var IEventDispatcher */ /** @var IEventDispatcher */
private $eventDispatcher; private $eventDispatcher;
/** @var IAppManager */
private $appManager;
/** @var IManager */ /** @var IManager */
private $dashboardManager; private $dashboardManager;
/** @var IConfig */ /** @var IConfig */
@ -65,6 +68,7 @@ class DashboardController extends Controller {
IRequest $request, IRequest $request,
IInitialStateService $initialStateService, IInitialStateService $initialStateService,
IEventDispatcher $eventDispatcher, IEventDispatcher $eventDispatcher,
IAppManager $appManager,
IManager $dashboardManager, IManager $dashboardManager,
IConfig $config, IConfig $config,
BackgroundService $backgroundService, BackgroundService $backgroundService,
@ -74,6 +78,7 @@ class DashboardController extends Controller {
$this->inititalStateService = $initialStateService; $this->inititalStateService = $initialStateService;
$this->eventDispatcher = $eventDispatcher; $this->eventDispatcher = $eventDispatcher;
$this->appManager = $appManager;
$this->dashboardManager = $dashboardManager; $this->dashboardManager = $dashboardManager;
$this->config = $config; $this->config = $config;
$this->backgroundService = $backgroundService; $this->backgroundService = $backgroundService;
@ -109,6 +114,11 @@ class DashboardController extends Controller {
// It does not matter if some statuses are missing from the array, missing ones are considered enabled // 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]; $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', 'panels', $widgets);
$this->inititalStateService->provideInitialState('dashboard', 'statuses', $statuses); $this->inititalStateService->provideInitialState('dashboard', 'statuses', $statuses);
$this->inititalStateService->provideInitialState('dashboard', 'layout', $userLayout); $this->inititalStateService->provideInitialState('dashboard', 'layout', $userLayout);

View File

@ -68,7 +68,9 @@
<a v-if="isAdmin" :href="appStoreUrl" class="button">{{ t('dashboard', 'Get more widgets from the app store') }}</a> <a v-if="isAdmin" :href="appStoreUrl" class="button">{{ t('dashboard', 'Get more widgets from the app store') }}</a>
<h3>{{ t('dashboard', 'Change background image') }}</h3> <h3>{{ t('dashboard', 'Change background image') }}</h3>
<BackgroundSettings :background="background" @update:background="updateBackground" /> <BackgroundSettings :background="background"
:theming-default-background="themingDefaultBackground"
@update:background="updateBackground" />
<h3>{{ t('dashboard', 'Weather service') }}</h3> <h3>{{ t('dashboard', 'Weather service') }}</h3>
<p> <p>
@ -93,11 +95,11 @@ import { generateUrl } from '@nextcloud/router'
import isMobile from './mixins/isMobile' import isMobile from './mixins/isMobile'
import BackgroundSettings from './components/BackgroundSettings' import BackgroundSettings from './components/BackgroundSettings'
import getBackgroundUrl from './helpers/getBackgroundUrl' import getBackgroundUrl from './helpers/getBackgroundUrl'
import prefixWithBaseUrl from './helpers/prefixWithBaseUrl'
const panels = loadState('dashboard', 'panels') const panels = loadState('dashboard', 'panels')
const firstRun = loadState('dashboard', 'firstRun') const firstRun = loadState('dashboard', 'firstRun')
const background = loadState('dashboard', 'background') const background = loadState('dashboard', 'background')
const themingDefaultBackground = loadState('dashboard', 'themingDefaultBackground')
const version = loadState('dashboard', 'version') const version = loadState('dashboard', 'version')
const shippedBackgroundList = loadState('dashboard', 'shippedBackgrounds') const shippedBackgroundList = loadState('dashboard', 'shippedBackgrounds')
const statusInfo = { const statusInfo = {
@ -140,16 +142,17 @@ export default {
appStoreUrl: generateUrl('/settings/apps/dashboard'), appStoreUrl: generateUrl('/settings/apps/dashboard'),
statuses: {}, statuses: {},
background, background,
themingDefaultBackground,
version, version,
defaultBackground: window.OCA.Accessibility?.theme === 'dark' ? prefixWithBaseUrl('flickr-148302424@N05-36591009215.jpg?v=1') : prefixWithBaseUrl('flickr-paszczak000-8715851521.jpg?v=1'),
} }
}, },
computed: { computed: {
backgroundImage() { backgroundImage() {
return getBackgroundUrl(this.background, this.version) return getBackgroundUrl(this.background, this.version, this.themingDefaultBackground)
}, },
backgroundStyle() { 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 null
} }
return { return {

View File

@ -66,6 +66,10 @@ export default {
type: String, type: String,
default: 'default', default: 'default',
}, },
themingDefaultBackground: {
type: String,
default: '',
},
}, },
data() { data() {
return { return {
@ -88,8 +92,8 @@ export default {
methods: { methods: {
async update(data) { async update(data) {
const background = data.type === 'custom' || data.type === 'default' ? data.type : data.value const background = data.type === 'custom' || data.type === 'default' ? data.type : data.value
this.backgroundImage = getBackgroundUrl(background, data.version) this.backgroundImage = getBackgroundUrl(background, data.version, this.themingDefaultBackground)
if (data.type === 'color') { if (data.type === 'color' || (data.type === 'default' && this.themingDefaultBackground === 'backgroundColor')) {
this.$emit('update:background', data) this.$emit('update:background', data)
this.loading = false this.loading = false
return return

View File

@ -23,8 +23,11 @@
import { generateUrl } from '@nextcloud/router' import { generateUrl } from '@nextcloud/router'
import prefixWithBaseUrl from './prefixWithBaseUrl' import prefixWithBaseUrl from './prefixWithBaseUrl'
export default (background, time = 0) => { export default (background, time = 0, themingDefaultBackground = '') => {
if (background === 'default') { if (background === 'default') {
if (themingDefaultBackground && themingDefaultBackground !== 'backgroundColor') {
return generateUrl('/apps/theming/image/background') + '?v=' + window.OCA.Theming.cacheBuster
}
if (window.OCA.Accessibility?.theme === 'dark') { if (window.OCA.Accessibility?.theme === 'dark') {
return prefixWithBaseUrl('eduardo-neves-pedra-azul.jpg') return prefixWithBaseUrl('eduardo-neves-pedra-azul.jpg')
} }

View File

@ -69,7 +69,7 @@ class Capabilities implements IPublicCapability {
* @return array * @return array
*/ */
public function getCapabilities() { public function getCapabilities() {
$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', false); $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', '');
$color = $this->theming->getColorPrimary(); $color = $this->theming->getColorPrimary();
return [ return [
'theming' => [ 'theming' => [
@ -82,10 +82,10 @@ class Capabilities implements IPublicCapability {
'color-element-bright' => $this->util->elementColor($color), 'color-element-bright' => $this->util->elementColor($color),
'color-element-dark' => $this->util->elementColor($color, false), 'color-element-dark' => $this->util->elementColor($color, false),
'logo' => $this->url->getAbsoluteURL($this->theming->getLogo()), '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->theming->getColorPrimary() :
$this->url->getAbsoluteURL($this->theming->getBackground()), $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(), 'background-default' => !$this->util->isBackgroundThemed(),
'logoheader' => $this->url->getAbsoluteURL($this->theming->getLogo()), 'logoheader' => $this->url->getAbsoluteURL($this->theming->getLogo()),
'favicon' => $this->url->getAbsoluteURL($this->theming->getLogo()), 'favicon' => $this->url->getAbsoluteURL($this->theming->getLogo()),

View File

@ -41,7 +41,7 @@ use OCP\IURLGenerator;
class ImageManager { class ImageManager {
/** @var IConfig */ /** @var IConfig */
private $config; private $config;
/** @var IAppData */ /** @var IAppData */
private $appData; private $appData;
@ -57,12 +57,12 @@ class ImageManager {
private $tempManager; private $tempManager;
public function __construct(IConfig $config, public function __construct(IConfig $config,
IAppData $appData, IAppData $appData,
IURLGenerator $urlGenerator, IURLGenerator $urlGenerator,
ICacheFactory $cacheFactory, ICacheFactory $cacheFactory,
ILogger $logger, ILogger $logger,
ITempManager $tempManager ITempManager $tempManager
) { ) {
$this->config = $config; $this->config = $config;
$this->appData = $appData; $this->appData = $appData;
$this->urlGenerator = $urlGenerator; $this->urlGenerator = $urlGenerator;
@ -80,13 +80,13 @@ class ImageManager {
} }
switch ($key) { switch ($key) {
case 'logo': case 'logo':
case 'logoheader': case 'logoheader':
case 'favicon': case 'favicon':
return $this->urlGenerator->imagePath('core', 'logo/logo.png') . '?v=' . $cacheBusterCounter; return $this->urlGenerator->imagePath('core', 'logo/logo.png') . '?v=' . $cacheBusterCounter;
case 'background': case 'background':
return $this->urlGenerator->imagePath('core', 'background.png') . '?v=' . $cacheBusterCounter; return $this->urlGenerator->imagePath('core', 'background.png') . '?v=' . $cacheBusterCounter;
} }
} }
public function getImageUrlAbsolute(string $key, bool $useSvg = true): string { public function getImageUrlAbsolute(string $key, bool $useSvg = true): string {
@ -102,9 +102,9 @@ class ImageManager {
*/ */
public function getImage(string $key, bool $useSvg = true): ISimpleFile { public function getImage(string $key, bool $useSvg = true): ISimpleFile {
$pngFile = null; $pngFile = null;
$logo = $this->config->getAppValue('theming', $key . 'Mime', false); $logo = $this->config->getAppValue('theming', $key . 'Mime', '');
$folder = $this->appData->getFolder('images'); $folder = $this->appData->getFolder('images');
if ($logo === false || !$folder->fileExists($key)) { if ($logo === '' || !$folder->fileExists($key)) {
throw new NotFoundException(); throw new NotFoundException();
} }
if (!$useSvg && $this->shouldReplaceIcons()) { if (!$useSvg && $this->shouldReplaceIcons()) {

View File

@ -59,7 +59,7 @@ class JSDataService implements \JsonSerializable {
'imprintUrl' => $this->themingDefaults->getImprintUrl(), 'imprintUrl' => $this->themingDefaults->getImprintUrl(),
'privacyUrl' => $this->themingDefaults->getPrivacyUrl(), 'privacyUrl' => $this->themingDefaults->getPrivacyUrl(),
'inverted' => $this->util->invertTextColor($this->themingDefaults->getColorPrimary()), 'inverted' => $this->util->invertTextColor($this->themingDefaults->getColorPrimary()),
'cacheBuster' => $this->appConfig->getAppValue(Application::class, 'cachebuster', '0'), 'cacheBuster' => $this->appConfig->getAppValue(Application::APP_ID, 'cachebuster', '0'),
]; ];
} }
} }

View File

@ -223,7 +223,7 @@ class ThemingDefaults extends \OC_Defaults {
* @return string * @return string
*/ */
public function getLogo($useSvg = true): 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 // short cut to avoid setting up the filesystem just to check if the logo is there
// //
@ -310,13 +310,13 @@ class ThemingDefaults extends \OC_Defaults {
$variables['image-login-background'] = "url('".$this->imageManager->getImageUrl('background')."')"; $variables['image-login-background'] = "url('".$this->imageManager->getImageUrl('background')."')";
$variables['image-login-plain'] = 'false'; $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'] = $this->getColorPrimary();
$variables['color-primary-text'] = $this->getTextColorPrimary(); $variables['color-primary-text'] = $this->getTextColorPrimary();
$variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary()); $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'; $variables['image-login-plain'] = 'true';
} }

View File

@ -249,7 +249,7 @@ class Util {
} }
public function isBackgroundThemed() { public function isBackgroundThemed() {
$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime',false); $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', '');
$backgroundExists = true; $backgroundExists = true;
try { try {