Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 1 addition & 27 deletions apps/dashboard/src/DashboardApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
</template>

<script>
import { generateUrl, imagePath } from '@nextcloud/router'
import { generateUrl } from '@nextcloud/router'
import { getCurrentUser } from '@nextcloud/auth'
import { loadState } from '@nextcloud/initial-state'
import axios from '@nextcloud/axios'
Expand All @@ -99,13 +99,11 @@ import Pencil from 'vue-material-design-icons/Pencil.vue'
import Vue from 'vue'

import isMobile from './mixins/isMobile.js'
import { getBackgroundUrl } from './helpers/getBackgroundUrl.js'

const panels = loadState('dashboard', 'panels')
const firstRun = loadState('dashboard', 'firstRun')

const background = loadState('theming', 'background')
const backgroundVersion = loadState('theming', 'backgroundVersion')
const themingDefaultBackground = loadState('theming', 'themingDefaultBackground')
const shippedBackgroundList = loadState('theming', 'shippedBackgrounds')

Expand Down Expand Up @@ -155,19 +153,6 @@ export default {
}
},
computed: {
backgroundImage() {
return getBackgroundUrl(this.background, backgroundVersion, this.themingDefaultBackground)
},
backgroundStyle() {
if ((this.background === 'default' && this.themingDefaultBackground === 'backgroundColor')
|| this.background.match(/#[0-9A-Fa-f]{6}/g)) {
return null
}

return {
backgroundImage: this.background === 'default' ? 'var(--image-main-background)' : `url('${this.backgroundImage}')`,
}
},
greeting() {
const time = this.timer.getHours()

Expand Down Expand Up @@ -286,17 +271,6 @@ export default {
// document.body.removeAttribute('data-theme-light')
// document.body.setAttribute('data-theme-dark', 'true')
}

const themeElements = [document.documentElement, document.querySelector('#header'), document.querySelector('body')]
for (const element of themeElements) {
if (this.background === 'default') {
element.style.setProperty('--image-main-background', `url('${imagePath('core', 'app-background.jpg')}')`)
} else if (this.background.match(/#[0-9A-Fa-f]{6}/g)) {
element.style.setProperty('--image-main-background', undefined)
} else {
element.style.setProperty('--image-main-background', this.backgroundStyle.backgroundImage)
}
}
},
/**
* Method to register panels that will be called by the integrating apps
Expand Down
49 changes: 0 additions & 49 deletions apps/dashboard/src/helpers/getBackgroundUrl.js

This file was deleted.

25 changes: 0 additions & 25 deletions apps/dashboard/src/helpers/prefixWithBaseUrl.js

This file was deleted.

6 changes: 6 additions & 0 deletions apps/theming/lib/Themes/DefaultTheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,15 @@ public function getCSSVariables(): array {
$themingBackground = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background', 'default');

if ($themingBackground === 'custom') {
// Custom
$variables['--image-main-background'] = "url('" . $this->urlGenerator->linkToRouteAbsolute('theming.userTheme.getBackground') . "')";
} elseif ($themingBackground !== 'default' && substr($themingBackground, 0, 1) !== '#') {
// Shipped background
$variables['--image-main-background'] = "url('" . $this->urlGenerator->linkTo(Application::APP_ID, "/img/background/$themingBackground") . "')";
} elseif (substr($themingBackground, 0, 1) === '#') {
// Color
unset($variables['--image-main-background']);
$variables['--color-main-background-plain'] = $this->primaryColor;
}
}

Expand Down
31 changes: 4 additions & 27 deletions apps/theming/src/UserThemes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
</template>

<script>
import { generateOcsUrl, imagePath } from '@nextcloud/router'
import { generateOcsUrl } from '@nextcloud/router'
import { loadState } from '@nextcloud/initial-state'
import axios from '@nextcloud/axios'
import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch'
Expand All @@ -83,8 +83,6 @@ import NcSettingsSection from '@nextcloud/vue/dist/Components/NcSettingsSection'
import BackgroundSettings from './components/BackgroundSettings.vue'
import ItemPreview from './components/ItemPreview.vue'

import { getBackgroundUrl } from '../src/helpers/getBackgroundUrl.js'

const availableThemes = loadState('theming', 'themes', [])
const enforceTheme = loadState('theming', 'enforceTheme', '')
const shortcutsDisabled = loadState('theming', 'shortcutsDisabled', false)
Expand All @@ -111,24 +109,12 @@ export default {
enforceTheme,
shortcutsDisabled,
background,
backgroundVersion,
themingDefaultBackground,
}
},

computed: {
backgroundImage() {
return getBackgroundUrl(this.background, backgroundVersion, this.themingDefaultBackground)
},
backgroundStyle() {
if ((this.background === 'default' && this.themingDefaultBackground === 'backgroundColor')
|| this.background.match(/#[0-9A-Fa-f]{6}/g)) {
return null
}

return {
backgroundImage: this.background === 'default' ? 'var(--image-main-background)' : `url('${this.backgroundImage}')`,
}
},
themes() {
return this.availableThemes.filter(theme => theme.type === 1)
},
Expand Down Expand Up @@ -183,7 +169,9 @@ export default {
methods: {
updateBackground(data) {
this.background = (data.type === 'custom' || data.type === 'default') ? data.type : data.value
this.backgroundVersion = data.version
this.updateGlobalStyles()
this.$emit('update:background')
},
updateGlobalStyles() {
// Override primary-invert-if-bright and color-primary-text if background is set
Expand All @@ -199,17 +187,6 @@ export default {
// document.body.removeAttribute('data-theme-light')
// document.body.setAttribute('data-theme-dark', 'true')
}

const themeElements = [document.documentElement, document.querySelector('#header'), document.querySelector('body')]
for (const element of themeElements) {
if (this.background === 'default') {
element.style.setProperty('--image-main-background', `url('${imagePath('core', 'app-background.jpg')}')`)
} else if (this.background.match(/#[0-9A-Fa-f]{6}/g)) {
element.style.setProperty('--image-main-background', undefined)
} else {
element.style.setProperty('--image-main-background', this.backgroundStyle.backgroundImage)
}
}
},
changeTheme({ enabled, id }) {
// Reset selected and select new one
Expand Down
2 changes: 1 addition & 1 deletion apps/theming/src/components/BackgroundSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
{{ t('theming', 'Default image') }}
</button>
<button class="background color"
:class="{ active: background === 'custom' }"
:class="{ active: background.startsWith('#') }"
tabindex="0"
@click="pickColor">
{{ t('theming', 'Plain background') }}
Expand Down
2 changes: 0 additions & 2 deletions apps/theming/src/helpers/getBackgroundUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
*
*/

// FIXME hoist this into a package? The same logic is used in `apps/dashboard/src/helpers/getBackgroundUrl.js`

import { generateUrl } from '@nextcloud/router'
import { prefixWithBaseUrl } from './prefixWithBaseUrl.js'

Expand Down
2 changes: 0 additions & 2 deletions apps/theming/src/helpers/prefixWithBaseUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
*
*/

// FIXME hoist this into a package? The same logic is used in `apps/dashboard/src/helpers/prefixWithBaseUrl.js`

import { generateFilePath } from '@nextcloud/router'

export const prefixWithBaseUrl = (url) => generateFilePath('theming', '', 'img/background/') + url
12 changes: 12 additions & 0 deletions apps/theming/src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,15 @@ Vue.prototype.t = t
const View = Vue.extend(App)
const theming = new View()
theming.$mount('#theming')

theming.$on('update:background', () => {
// Refresh server-side generated theming CSS
[...document.head.querySelectorAll('link.theme')].forEach(theme => {
const url = new URL(theme.href)
url.searchParams.set('v', Date.now())
const newTheme = theme.cloneNode()
newTheme.href = url.toString()
newTheme.onload = () => theme.remove()
document.head.append(newTheme)
})
})
4 changes: 2 additions & 2 deletions core/css/apps.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions core/css/apps.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ html {
width: 100%;
height: 100%;
position: absolute;
background-color: var(--color-primary);
background-color: var(--color-main-background-plain, var(--color-main-background));
background-image: var(--image-main-background);
background-size: cover;
background-position: center;
}

body {
background-color: var(--color-primary);
background-color: var(--color-main-background-plain, var(--color-main-background));
background-image: var(--image-main-background);
background-size: cover;
background-position: center;
Expand Down
5 changes: 2 additions & 3 deletions core/css/server.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/css/server.css.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion core/css/styles.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading