Skip to content

Commit 87fcbc9

Browse files
GretaDPytal
authored andcommitted
Move background settings from dashboard app to Appearance and accessibility settings
Signed-off-by: greta <[email protected]> Signed-off-by: Christopher Ng <[email protected]>
1 parent 204a700 commit 87fcbc9

File tree

54 files changed

+475
-228
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+475
-228
lines changed

apps/dashboard/appinfo/routes.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
['name' => 'dashboard#index', 'url' => '/', 'verb' => 'GET'],
3030
['name' => 'dashboard#updateLayout', 'url' => '/layout', 'verb' => 'POST'],
3131
['name' => 'dashboard#updateStatuses', 'url' => '/statuses', 'verb' => 'POST'],
32-
['name' => 'dashboard#getBackground', 'url' => '/background', 'verb' => 'GET'],
33-
['name' => 'dashboard#setBackground', 'url' => '/background/{type}', 'verb' => 'POST'],
3432
],
3533
'ocs' => [
3634
['name' => 'dashboardApi#getWidgetItems', 'url' => '/api/v1/widget-items', 'verb' => 'GET'],

apps/dashboard/lib/Controller/DashboardController.php

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,12 @@
2828
*/
2929
namespace OCA\Dashboard\Controller;
3030

31-
use OCA\Dashboard\Service\BackgroundService;
3231
use OCA\Files\Event\LoadSidebar;
3332
use OCA\Viewer\Event\LoadViewer;
3433
use OCP\AppFramework\Controller;
3534
use OCP\AppFramework\Http;
36-
use OCP\AppFramework\Http\FileDisplayResponse;
3735
use OCP\AppFramework\Http\JSONResponse;
38-
use OCP\AppFramework\Http\NotFoundResponse;
3936
use OCP\AppFramework\Http\TemplateResponse;
40-
use OCP\App\IAppManager;
4137
use OCP\AppFramework\Services\IInitialState;
4238
use OCP\Dashboard\IManager;
4339
use OCP\Dashboard\IWidget;
@@ -52,38 +48,28 @@ class DashboardController extends Controller {
5248
private $inititalState;
5349
/** @var IEventDispatcher */
5450
private $eventDispatcher;
55-
/** @var IAppManager */
56-
private $appManager;
5751
/** @var IManager */
5852
private $dashboardManager;
5953
/** @var IConfig */
6054
private $config;
6155
/** @var string */
6256
private $userId;
63-
/**
64-
* @var BackgroundService
65-
*/
66-
private $backgroundService;
6757

6858
public function __construct(
6959
string $appName,
7060
IRequest $request,
7161
IInitialState $initialState,
7262
IEventDispatcher $eventDispatcher,
73-
IAppManager $appManager,
7463
IManager $dashboardManager,
7564
IConfig $config,
76-
BackgroundService $backgroundService,
7765
$userId
7866
) {
7967
parent::__construct($appName, $request);
8068

8169
$this->inititalState = $initialState;
8270
$this->eventDispatcher = $eventDispatcher;
83-
$this->appManager = $appManager;
8471
$this->dashboardManager = $dashboardManager;
8572
$this->config = $config;
86-
$this->backgroundService = $backgroundService;
8773
$this->userId = $userId;
8874
}
8975

@@ -119,18 +105,10 @@ public function index(): TemplateResponse {
119105
// It does not matter if some statuses are missing from the array, missing ones are considered enabled
120106
$statuses = ($statuses && count($statuses) > 0) ? $statuses : ['weather' => true];
121107

122-
// if theming app is enabled and wants to override default, we pass it
123-
$themingDefaultBackground = $this->appManager->isEnabledForUser('theming')
124-
? $this->config->getAppValue('theming', 'backgroundMime', '')
125-
: '';
126-
$this->inititalState->provideInitialState('themingDefaultBackground', $themingDefaultBackground);
127108
$this->inititalState->provideInitialState('panels', $widgets);
128109
$this->inititalState->provideInitialState('statuses', $statuses);
129110
$this->inititalState->provideInitialState('layout', $userLayout);
130111
$this->inititalState->provideInitialState('firstRun', $this->config->getUserValue($this->userId, 'dashboard', 'firstRun', '1') === '1');
131-
$this->inititalState->provideInitialState('shippedBackgrounds', BackgroundService::SHIPPED_BACKGROUNDS);
132-
$this->inititalState->provideInitialState('background', $this->config->getUserValue($this->userId, 'dashboard', 'background', 'default'));
133-
$this->inititalState->provideInitialState('version', $this->config->getUserValue($this->userId, 'dashboard', 'backgroundVersion', 0));
134112
$this->config->setUserValue($this->userId, 'dashboard', 'firstRun', '0');
135113

136114
$response = new TemplateResponse('dashboard', 'index', [
@@ -165,54 +143,4 @@ public function updateStatuses(string $statuses): JSONResponse {
165143
$this->config->setUserValue($this->userId, 'dashboard', 'statuses', $statuses);
166144
return new JSONResponse(['statuses' => $statuses]);
167145
}
168-
169-
/**
170-
* @NoAdminRequired
171-
*/
172-
public function setBackground(string $type = 'default', string $value = ''): JSONResponse {
173-
$currentVersion = (int)$this->config->getUserValue($this->userId, 'dashboard', 'backgroundVersion', '0');
174-
try {
175-
switch ($type) {
176-
case 'shipped':
177-
$this->backgroundService->setShippedBackground($value);
178-
break;
179-
case 'custom':
180-
$this->backgroundService->setFileBackground($value);
181-
break;
182-
case 'color':
183-
$this->backgroundService->setColorBackground($value);
184-
break;
185-
case 'default':
186-
$this->backgroundService->setDefaultBackground();
187-
break;
188-
default:
189-
return new JSONResponse(['error' => 'Invalid type provided'], Http::STATUS_BAD_REQUEST);
190-
}
191-
} catch (\InvalidArgumentException $e) {
192-
return new JSONResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
193-
} catch (\Throwable $e) {
194-
return new JSONResponse(['error' => $e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR);
195-
}
196-
$currentVersion++;
197-
$this->config->setUserValue($this->userId, 'dashboard', 'backgroundVersion', (string)$currentVersion);
198-
return new JSONResponse([
199-
'type' => $type,
200-
'value' => $value,
201-
'version' => $this->config->getUserValue($this->userId, 'dashboard', 'backgroundVersion', $currentVersion)
202-
]);
203-
}
204-
205-
/**
206-
* @NoAdminRequired
207-
* @NoCSRFRequired
208-
*/
209-
public function getBackground(): Http\Response {
210-
$file = $this->backgroundService->getBackground();
211-
if ($file !== null) {
212-
$response = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => $file->getMimeType()]);
213-
$response->cacheFor(24 * 60 * 60);
214-
return $response;
215-
}
216-
return new NotFoundResponse();
217-
}
218146
}

apps/dashboard/src/DashboardApp.vue

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@
7373

7474
<a v-if="isAdmin" :href="appStoreUrl" class="button">{{ t('dashboard', 'Get more widgets from the App Store') }}</a>
7575

76-
<h3>{{ t('dashboard', 'Change background image') }}</h3>
77-
<BackgroundSettings :background="background"
78-
:theming-default-background="themingDefaultBackground"
79-
@update:background="updateBackground" />
80-
8176
<h3>{{ t('dashboard', 'Weather service') }}</h3>
8277
<p>
8378
{{ t('dashboard', 'For your privacy, the weather data is requested by your Nextcloud server on your behalf so the weather service receives no personal information.') }}
@@ -93,7 +88,7 @@
9388
</template>
9489

9590
<script>
96-
import { generateUrl } from '@nextcloud/router'
91+
import { generateUrl, imagePath } from '@nextcloud/router'
9792
import { getCurrentUser } from '@nextcloud/auth'
9893
import { loadState } from '@nextcloud/initial-state'
9994
import axios from '@nextcloud/axios'
@@ -103,16 +98,16 @@ import NcModal from '@nextcloud/vue/dist/Components/NcModal'
10398
import Pencil from 'vue-material-design-icons/Pencil.vue'
10499
import Vue from 'vue'
105100
106-
import isMobile from './mixins/isMobile'
107-
import BackgroundSettings from './components/BackgroundSettings'
108-
import getBackgroundUrl from './helpers/getBackgroundUrl'
101+
import isMobile from './mixins/isMobile.js'
102+
import { getBackgroundUrl } from './helpers/getBackgroundUrl.js'
109103
110104
const panels = loadState('dashboard', 'panels')
111105
const firstRun = loadState('dashboard', 'firstRun')
112-
const background = loadState('dashboard', 'background')
113-
const themingDefaultBackground = loadState('dashboard', 'themingDefaultBackground')
114-
const version = loadState('dashboard', 'version')
115-
const shippedBackgroundList = loadState('dashboard', 'shippedBackgrounds')
106+
107+
const background = loadState('theming', 'background')
108+
const backgroundVersion = loadState('theming', 'backgroundVersion')
109+
const themingDefaultBackground = loadState('theming', 'themingDefaultBackground')
110+
const shippedBackgroundList = loadState('theming', 'shippedBackgrounds')
116111
117112
const statusInfo = {
118113
weather: {
@@ -128,7 +123,6 @@ const statusInfo = {
128123
export default {
129124
name: 'DashboardApp',
130125
components: {
131-
BackgroundSettings,
132126
NcButton,
133127
Draggable,
134128
NcModal,
@@ -158,12 +152,11 @@ export default {
158152
statuses: {},
159153
background,
160154
themingDefaultBackground,
161-
version,
162155
}
163156
},
164157
computed: {
165158
backgroundImage() {
166-
return getBackgroundUrl(this.background, this.version, this.themingDefaultBackground)
159+
return getBackgroundUrl(this.background, backgroundVersion, this.themingDefaultBackground)
167160
},
168161
backgroundStyle() {
169162
if ((this.background === 'default' && this.themingDefaultBackground === 'backgroundColor')
@@ -175,7 +168,6 @@ export default {
175168
backgroundImage: this.background === 'default' ? 'var(--image-main-background)' : `url('${this.backgroundImage}')`,
176169
}
177170
},
178-
179171
greeting() {
180172
const time = this.timer.getHours()
181173
@@ -280,6 +272,32 @@ export default {
280272
},
281273
282274
methods: {
275+
updateGlobalStyles() {
276+
// Override primary-invert-if-bright and color-primary-text if background is set
277+
const isBackgroundBright = shippedBackgroundList[this.background]?.theming === 'dark'
278+
if (isBackgroundBright) {
279+
document.querySelector('#header').style.setProperty('--primary-invert-if-bright', 'invert(100%)')
280+
document.querySelector('#header').style.setProperty('--color-primary-text', '#000000')
281+
// document.body.removeAttribute('data-theme-dark')
282+
// document.body.setAttribute('data-theme-light', 'true')
283+
} else {
284+
document.querySelector('#header').style.setProperty('--primary-invert-if-bright', 'no')
285+
document.querySelector('#header').style.setProperty('--color-primary-text', '#ffffff')
286+
// document.body.removeAttribute('data-theme-light')
287+
// document.body.setAttribute('data-theme-dark', 'true')
288+
}
289+
290+
const themeElements = [document.documentElement, document.querySelector('#header'), document.querySelector('body')]
291+
for (const element of themeElements) {
292+
if (this.background === 'default') {
293+
element.style.setProperty('--image-main-background', `url('${imagePath('core', 'app-background.jpg')}')`)
294+
} else if (this.background.match(/#[0-9A-Fa-f]{6}/g)) {
295+
element.style.setProperty('--image-main-background', undefined)
296+
} else {
297+
element.style.setProperty('--image-main-background', this.backgroundStyle.backgroundImage)
298+
}
299+
}
300+
},
283301
/**
284302
* Method to register panels that will be called by the integrating apps
285303
*
@@ -354,30 +372,6 @@ export default {
354372
this.firstRun = false
355373
}, 1000)
356374
},
357-
updateBackground(data) {
358-
this.background = data.type === 'custom' || data.type === 'default' ? data.type : data.value
359-
this.version = data.version
360-
this.updateGlobalStyles()
361-
},
362-
updateGlobalStyles() {
363-
// Override primary-invert-if-bright and color-primary-text if background is set
364-
const isBackgroundBright = shippedBackgroundList[this.background]?.theming === 'dark'
365-
if (isBackgroundBright) {
366-
document.querySelector('#header').style.setProperty('--primary-invert-if-bright', 'invert(100%)')
367-
document.querySelector('#header').style.setProperty('--color-primary-text', '#000000')
368-
// document.body.removeAttribute('data-theme-dark')
369-
// document.body.setAttribute('data-theme-light', 'true')
370-
} else {
371-
document.querySelector('#header').style.setProperty('--primary-invert-if-bright', 'no')
372-
document.querySelector('#header').style.setProperty('--color-primary-text', '#ffffff')
373-
// document.body.removeAttribute('data-theme-light')
374-
// document.body.setAttribute('data-theme-dark', 'true')
375-
}
376-
377-
document.documentElement.style.setProperty('--image-main-background', this.backgroundStyle.backgroundImage)
378-
document.querySelector('#header').style.setProperty('--image-main-background', this.backgroundStyle.backgroundImage)
379-
document.querySelector('body').style.setProperty('--image-main-background', this.backgroundStyle.backgroundImage)
380-
},
381375
updateSkipLink() {
382376
// Make sure "Skip to main content" link points to the app content
383377
document.getElementsByClassName('skip-navigation')[0].setAttribute('href', '#app-dashboard')

apps/dashboard/src/helpers/getBackgroundUrl.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
*/
2424

2525
import { generateUrl } from '@nextcloud/router'
26-
import prefixWithBaseUrl from './prefixWithBaseUrl'
26+
import { prefixWithBaseUrl } from './prefixWithBaseUrl.js'
2727

28-
export default (background, time = 0, themingDefaultBackground = '') => {
28+
export const getBackgroundUrl = (background, time = 0, themingDefaultBackground = '') => {
2929
const enabledThemes = window.OCA?.Theming?.enabledThemes || []
3030
const isDarkTheme = (enabledThemes.length === 0 || enabledThemes[0] === 'default')
3131
? window.matchMedia('(prefers-color-scheme: dark)').matches
@@ -42,7 +42,7 @@ export default (background, time = 0, themingDefaultBackground = '') => {
4242

4343
return prefixWithBaseUrl('kamil-porembinski-clouds.jpg')
4444
} else if (background === 'custom') {
45-
return generateUrl('/apps/dashboard/background') + '?v=' + time
45+
return generateUrl('/apps/theming/background') + '?v=' + time
4646
}
4747

4848
return prefixWithBaseUrl(background)

apps/dashboard/src/helpers/prefixWithBaseUrl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222

2323
import { generateFilePath } from '@nextcloud/router'
2424

25-
export default (url) => generateFilePath('dashboard', '', 'img/') + url
25+
export const prefixWithBaseUrl = (url) => generateFilePath('theming', '', 'img/background/') + url

apps/theming/appinfo/routes.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@
7878
'verb' => 'GET',
7979
'requirements' => ['image' => '.+']
8080
],
81+
[
82+
'name' => 'userTheme#getBackground',
83+
'url' => '/background',
84+
'verb' => 'GET',
85+
],
86+
[
87+
'name' => 'userTheme#setBackground',
88+
'url' => '/background/{type}',
89+
'verb' => 'POST',
90+
],
8191
],
8292
'ocs' => [
8393
[

apps/dashboard/img/anatoly-mikhaltsov-butterfly-wing-scale.jpg renamed to apps/theming/img/background/anatoly-mikhaltsov-butterfly-wing-scale.jpg

File renamed without changes.

apps/dashboard/img/bernard-spragg-new-zealand-fern.jpg renamed to apps/theming/img/background/bernard-spragg-new-zealand-fern.jpg

File renamed without changes.

apps/dashboard/img/bernie-cetonia-aurata-take-off-composition.jpg renamed to apps/theming/img/background/bernie-cetonia-aurata-take-off-composition.jpg

File renamed without changes.

apps/dashboard/img/dejan-krsmanovic-ribbed-red-metal.jpg renamed to apps/theming/img/background/dejan-krsmanovic-ribbed-red-metal.jpg

File renamed without changes.

0 commit comments

Comments
 (0)