Skip to content

Commit c84f451

Browse files
author
Julien Veyssier
committed
override default dashboard background with theming one
fix getAppValue default value in theming app fix cacheBuster value injection Signed-off-by: Julien Veyssier <[email protected]>
1 parent 35be4fd commit c84f451

File tree

9 files changed

+38
-18
lines changed

9 files changed

+38
-18
lines changed

apps/dashboard/lib/Controller/DashboardController.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use OCP\AppFramework\Http\JSONResponse;
3636
use OCP\AppFramework\Http\NotFoundResponse;
3737
use OCP\AppFramework\Http\TemplateResponse;
38+
use OCP\App\IAppManager;
3839
use OCP\Dashboard\IManager;
3940
use OCP\Dashboard\IWidget;
4041
use OCP\Dashboard\RegisterWidgetEvent;
@@ -49,6 +50,8 @@ class DashboardController extends Controller {
4950
private $inititalStateService;
5051
/** @var IEventDispatcher */
5152
private $eventDispatcher;
53+
/** @var IAppManager */
54+
private $appManager;
5255
/** @var IManager */
5356
private $dashboardManager;
5457
/** @var IConfig */
@@ -65,6 +68,7 @@ public function __construct(
6568
IRequest $request,
6669
IInitialStateService $initialStateService,
6770
IEventDispatcher $eventDispatcher,
71+
IAppManager $appManager,
6872
IManager $dashboardManager,
6973
IConfig $config,
7074
BackgroundService $backgroundService,
@@ -74,6 +78,7 @@ public function __construct(
7478

7579
$this->inititalStateService = $initialStateService;
7680
$this->eventDispatcher = $eventDispatcher;
81+
$this->appManager = $appManager;
7782
$this->dashboardManager = $dashboardManager;
7883
$this->config = $config;
7984
$this->backgroundService = $backgroundService;
@@ -109,6 +114,11 @@ public function index(): TemplateResponse {
109114
// It does not matter if some statuses are missing from the array, missing ones are considered enabled
110115
$statuses = ($statuses && count($statuses) > 0) ? $statuses : ['weather' => true];
111116

117+
// if theming app is enabled and wants to override default, we pass it
118+
$themingDefaultBackground = $this->appManager->isEnabledForUser('theming')
119+
? $this->config->getAppValue('theming', 'backgroundMime', '')
120+
: '';
121+
$this->inititalStateService->provideInitialState('dashboard', 'themingDefaultBackground', $themingDefaultBackground);
112122
$this->inititalStateService->provideInitialState('dashboard', 'panels', $widgets);
113123
$this->inititalStateService->provideInitialState('dashboard', 'statuses', $statuses);
114124
$this->inititalStateService->provideInitialState('dashboard', 'layout', $userLayout);

apps/dashboard/src/App.vue

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@
6868
<a v-if="isAdmin" :href="appStoreUrl" class="button">{{ t('dashboard', 'Get more widgets from the app store') }}</a>
6969

7070
<h3>{{ t('dashboard', 'Change background image') }}</h3>
71-
<BackgroundSettings :background="background" @update:background="updateBackground" />
71+
<BackgroundSettings :background="background"
72+
:theming-default-background="themingDefaultBackground"
73+
@update:background="updateBackground" />
7274

7375
<h3>{{ t('dashboard', 'Weather service') }}</h3>
7476
<p>
@@ -95,11 +97,11 @@ import { generateUrl } from '@nextcloud/router'
9597
import isMobile from './mixins/isMobile'
9698
import BackgroundSettings from './components/BackgroundSettings'
9799
import getBackgroundUrl from './helpers/getBackgroundUrl'
98-
import prefixWithBaseUrl from './helpers/prefixWithBaseUrl'
99100
100101
const panels = loadState('dashboard', 'panels')
101102
const firstRun = loadState('dashboard', 'firstRun')
102103
const background = loadState('dashboard', 'background')
104+
const themingDefaultBackground = loadState('dashboard', 'themingDefaultBackground')
103105
const version = loadState('dashboard', 'version')
104106
const shippedBackgroundList = loadState('dashboard', 'shippedBackgrounds')
105107
const statusInfo = {
@@ -142,16 +144,17 @@ export default {
142144
appStoreUrl: generateUrl('/settings/apps/dashboard'),
143145
statuses: {},
144146
background,
147+
themingDefaultBackground,
145148
version,
146-
defaultBackground: window.OCA.Accessibility?.theme === 'dark' ? prefixWithBaseUrl('[email protected]?v=1') : prefixWithBaseUrl('flickr-paszczak000-8715851521.jpg?v=1'),
147149
}
148150
},
149151
computed: {
150152
backgroundImage() {
151-
return getBackgroundUrl(this.background, this.version)
153+
return getBackgroundUrl(this.background, this.version, this.themingDefaultBackground)
152154
},
153155
backgroundStyle() {
154-
if (this.background.match(/#[0-9A-Fa-f]{6}/g)) {
156+
if ((this.background === 'default' && this.themingDefaultBackground === 'backgroundColor')
157+
|| this.background.match(/#[0-9A-Fa-f]{6}/g)) {
155158
return null
156159
}
157160
return {

apps/dashboard/src/components/BackgroundSettings.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ export default {
6666
type: String,
6767
default: 'default',
6868
},
69+
themingDefaultBackground: {
70+
type: String,
71+
default: '',
72+
},
6973
},
7074
data() {
7175
return {
@@ -88,8 +92,8 @@ export default {
8892
methods: {
8993
async update(data) {
9094
const background = data.type === 'custom' || data.type === 'default' ? data.type : data.value
91-
this.backgroundImage = getBackgroundUrl(background, data.version)
92-
if (data.type === 'color') {
95+
this.backgroundImage = getBackgroundUrl(background, data.version, this.themingDefaultBackground)
96+
if (data.type === 'color' || (data.type === 'default' && this.themingDefaultBackground === 'backgroundColor')) {
9397
this.$emit('update:background', data)
9498
this.loading = false
9599
return

apps/dashboard/src/helpers/getBackgroundUrl.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@
2323
import { generateUrl } from '@nextcloud/router'
2424
import prefixWithBaseUrl from './prefixWithBaseUrl'
2525

26-
export default (background, time = 0) => {
26+
export default (background, time = 0, themingDefaultBackground = '') => {
2727
if (background === 'default') {
28+
if (themingDefaultBackground && themingDefaultBackground !== 'backgroundColor') {
29+
return generateUrl('/apps/theming/image/background') + '?v=' + window.OCA.Theming.cacheBuster
30+
}
2831
if (window.OCA.Accessibility.theme === 'dark') {
2932
return prefixWithBaseUrl('eduardo-neves-pedra-azul.jpg')
3033
}

apps/theming/lib/Capabilities.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function __construct(ThemingDefaults $theming, Util $util, IURLGenerator
6969
* @return array
7070
*/
7171
public function getCapabilities() {
72-
$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', false);
72+
$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', '');
7373
$color = $this->theming->getColorPrimary();
7474
return [
7575
'theming' => [
@@ -82,10 +82,10 @@ public function getCapabilities() {
8282
'color-element-bright' => $this->util->elementColor($color),
8383
'color-element-dark' => $this->util->elementColor($color, false),
8484
'logo' => $this->url->getAbsoluteURL($this->theming->getLogo()),
85-
'background' => $backgroundLogo === 'backgroundColor' || ($backgroundLogo === false && $this->theming->getColorPrimary() !== '#0082c9') ?
85+
'background' => $backgroundLogo === 'backgroundColor' || ($backgroundLogo === '' && $this->theming->getColorPrimary() !== '#0082c9') ?
8686
$this->theming->getColorPrimary() :
8787
$this->url->getAbsoluteURL($this->theming->getBackground()),
88-
'background-plain' => $backgroundLogo === 'backgroundColor' || ($backgroundLogo === false && $this->theming->getColorPrimary() !== '#0082c9'),
88+
'background-plain' => $backgroundLogo === 'backgroundColor' || ($backgroundLogo === '' && $this->theming->getColorPrimary() !== '#0082c9'),
8989
'background-default' => !$this->util->isBackgroundThemed(),
9090
'logoheader' => $this->url->getAbsoluteURL($this->theming->getLogo()),
9191
'favicon' => $this->url->getAbsoluteURL($this->theming->getLogo()),

apps/theming/lib/ImageManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ public function getImageUrlAbsolute(string $key, bool $useSvg = true): string {
101101
* @throws NotPermittedException
102102
*/
103103
public function getImage(string $key, bool $useSvg = true): ISimpleFile {
104-
$logo = $this->config->getAppValue('theming', $key . 'Mime', false);
104+
$logo = $this->config->getAppValue('theming', $key . 'Mime', '');
105105
$folder = $this->appData->getFolder('images');
106-
if ($logo === false || !$folder->fileExists($key)) {
106+
if ($logo === '' || !$folder->fileExists($key)) {
107107
throw new NotFoundException();
108108
}
109109
if (!$useSvg && $this->shouldReplaceIcons()) {

apps/theming/lib/Service/JSDataService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function jsonSerialize() {
5959
'imprintUrl' => $this->themingDefaults->getImprintUrl(),
6060
'privacyUrl' => $this->themingDefaults->getPrivacyUrl(),
6161
'inverted' => $this->util->invertTextColor($this->themingDefaults->getColorPrimary()),
62-
'cacheBuster' => $this->appConfig->getAppValue(Application::class, 'cachebuster', '0'),
62+
'cacheBuster' => $this->appConfig->getAppValue(Application::APP_ID, 'cachebuster', '0'),
6363
];
6464
}
6565
}

apps/theming/lib/ThemingDefaults.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public function getColorPrimary() {
223223
* @return string
224224
*/
225225
public function getLogo($useSvg = true): string {
226-
$logo = $this->config->getAppValue('theming', 'logoMime', false);
226+
$logo = $this->config->getAppValue('theming', 'logoMime', '');
227227

228228
// short cut to avoid setting up the filesystem just to check if the logo is there
229229
//
@@ -309,13 +309,13 @@ public function getScssVariables() {
309309
$variables['image-login-background'] = "url('".$this->imageManager->getImageUrl('background')."')";
310310
$variables['image-login-plain'] = 'false';
311311

312-
if ($this->config->getAppValue('theming', 'color', null) !== null) {
312+
if ($this->config->getAppValue('theming', 'color', '') !== '') {
313313
$variables['color-primary'] = $this->getColorPrimary();
314314
$variables['color-primary-text'] = $this->getTextColorPrimary();
315315
$variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary());
316316
}
317317

318-
if ($this->config->getAppValue('theming', 'backgroundMime', null) === 'backgroundColor') {
318+
if ($this->config->getAppValue('theming', 'backgroundMime', '') === 'backgroundColor') {
319319
$variables['image-login-plain'] = 'true';
320320
}
321321

apps/theming/lib/Util.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public function isAlreadyThemed() {
249249
}
250250

251251
public function isBackgroundThemed() {
252-
$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime',false);
252+
$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', '');
253253

254254
$backgroundExists = true;
255255
try {

0 commit comments

Comments
 (0)