diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2022-10-05 11:34:05 +0200 |
---|---|---|
committer | John Molakvoæ <skjnldsv@protonmail.com> | 2022-10-13 12:13:39 +0200 |
commit | 4b46c5a5a02b6c1c77b99cf21b9ff933fabbcc35 (patch) | |
tree | 17de2e626c685d93f112a7a4c90efa150e6afe11 /apps | |
parent | f6efd54242de80f4391a7bac57dab7ddc01cb981 (diff) | |
download | nextcloud-server-4b46c5a5a02b6c1c77b99cf21b9ff933fabbcc35.tar.gz nextcloud-server-4b46c5a5a02b6c1c77b99cf21b9ff933fabbcc35.zip |
Use default system primary
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/theming/lib/Service/JSDataService.php | 1 | ||||
-rw-r--r-- | apps/theming/lib/Settings/Admin.php | 2 | ||||
-rw-r--r-- | apps/theming/lib/Themes/CommonThemeTrait.php | 1 | ||||
-rw-r--r-- | apps/theming/lib/Themes/DefaultTheme.php | 10 | ||||
-rw-r--r-- | apps/theming/lib/ThemingDefaults.php | 29 | ||||
-rw-r--r-- | apps/theming/src/UserThemes.vue | 8 | ||||
-rw-r--r-- | apps/theming/src/components/BackgroundSettings.vue | 63 |
7 files changed, 92 insertions, 22 deletions
diff --git a/apps/theming/lib/Service/JSDataService.php b/apps/theming/lib/Service/JSDataService.php index fdc85ea445a..26cda8c0012 100644 --- a/apps/theming/lib/Service/JSDataService.php +++ b/apps/theming/lib/Service/JSDataService.php @@ -55,6 +55,7 @@ class JSDataService implements \JsonSerializable { 'url' => $this->themingDefaults->getBaseUrl(), 'slogan' => $this->themingDefaults->getSlogan(), 'color' => $this->themingDefaults->getColorPrimary(), + 'defaultColor' => $this->themingDefaults->getDefaultColorPrimary(), 'imprintUrl' => $this->themingDefaults->getImprintUrl(), 'privacyUrl' => $this->themingDefaults->getPrivacyUrl(), 'inverted' => $this->util->invertTextColor($this->themingDefaults->getColorPrimary()), diff --git a/apps/theming/lib/Settings/Admin.php b/apps/theming/lib/Settings/Admin.php index 6caa174d99b..e89ea6b6fe9 100644 --- a/apps/theming/lib/Settings/Admin.php +++ b/apps/theming/lib/Settings/Admin.php @@ -75,7 +75,7 @@ class Admin implements IDelegatedSettings { 'name' => $this->themingDefaults->getEntity(), 'url' => $this->themingDefaults->getBaseUrl(), 'slogan' => $this->themingDefaults->getSlogan(), - 'color' => $this->themingDefaults->getColorPrimary(), + 'color' => $this->themingDefaults->getDefaultColorPrimary(), 'uploadLogoRoute' => $this->urlGenerator->linkToRoute('theming.Theming.uploadImage'), 'canThemeIcons' => $this->imageManager->shouldReplaceIcons(), 'iconDocs' => $this->urlGenerator->linkToDocs('admin-theming-icons'), diff --git a/apps/theming/lib/Themes/CommonThemeTrait.php b/apps/theming/lib/Themes/CommonThemeTrait.php index 631879ea832..d88a6a319fb 100644 --- a/apps/theming/lib/Themes/CommonThemeTrait.php +++ b/apps/theming/lib/Themes/CommonThemeTrait.php @@ -42,6 +42,7 @@ trait CommonThemeTrait { // primary related colours return [ '--color-primary' => $this->primaryColor, + '--color-primary-default' => $this->defaultPrimaryColor, '--color-primary-text' => $this->util->invertTextColor($this->primaryColor) ? '#000000' : '#ffffff', '--color-primary-hover' => $this->util->mix($this->primaryColor, $colorMainBackground, 60), '--color-primary-light' => $colorPrimaryLight, diff --git a/apps/theming/lib/Themes/DefaultTheme.php b/apps/theming/lib/Themes/DefaultTheme.php index e295d5d880a..b6c84e82d7b 100644 --- a/apps/theming/lib/Themes/DefaultTheme.php +++ b/apps/theming/lib/Themes/DefaultTheme.php @@ -48,6 +48,7 @@ class DefaultTheme implements ITheme { public IConfig $config; public IL10N $l; + public string $defaultPrimaryColor; public string $primaryColor; public function __construct(Util $util, @@ -65,9 +66,12 @@ class DefaultTheme implements ITheme { $this->config = $config; $this->l = $l; - $initialPrimaryColor = $this->themingDefaults->getColorPrimary(); - // Override default color if set to improve accessibility - $this->primaryColor = $initialPrimaryColor === BackgroundService::DEFAULT_COLOR ? BackgroundService::DEFAULT_ACCESSIBLE_COLOR : $initialPrimaryColor; + $this->defaultPrimaryColor = $this->themingDefaults->getDefaultColorPrimary(); + + // Override default codefaultPrimaryColorlor if set to improve accessibility + $this->primaryColor = $this->defaultPrimaryColor === BackgroundService::DEFAULT_COLOR + ? BackgroundService::DEFAULT_ACCESSIBLE_COLOR + : $this->themingDefaults->getColorPrimary(); } public function getId(): string { diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php index ae12530fb5c..cc23053a9c3 100644 --- a/apps/theming/lib/ThemingDefaults.php +++ b/apps/theming/lib/ThemingDefaults.php @@ -219,9 +219,12 @@ class ThemingDefaults extends \OC_Defaults { */ public function getColorPrimary() { $user = $this->userSession->getUser(); - $color = $this->config->getAppValue(Application::APP_ID, 'color', ''); + $defaultColor = $this->getDefaultColorPrimary(); + $themingBackground = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background'); - if ($color === '' && !empty($user)) { + // if the user is defined and the selected background is not a colour + if ($user !== null + && !preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $themingBackground)) { $themingBackground = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background', 'default'); if ($themingBackground === 'default') { return BackgroundService::DEFAULT_COLOR; @@ -230,10 +233,30 @@ class ThemingDefaults extends \OC_Defaults { } } - if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $color)) { + // If the user selected a specific colour + if (preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $themingBackground)) { + return $themingBackground; + } + + // If the default color is not valid, return the default background one + if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $defaultColor)) { return BackgroundService::DEFAULT_COLOR; } + // Finally, return the system global primary color + return $defaultColor; + } + + /** + * Return the default color primary + * + * @return string + */ + public function getDefaultColorPrimary() { + $color = $this->config->getAppValue(Application::APP_ID, 'color', $this->color); + if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $color)) { + $color = '#0082c9'; + } return $color; } diff --git a/apps/theming/src/UserThemes.vue b/apps/theming/src/UserThemes.vue index 3e3b0afed16..1eeeb3c5b21 100644 --- a/apps/theming/src/UserThemes.vue +++ b/apps/theming/src/UserThemes.vue @@ -156,16 +156,16 @@ export default { }, }, - mounted() { - this.updateGlobalStyles() - }, - watch: { shortcutsDisabled(newState) { this.changeShortcutsDisabled(newState) }, }, + mounted() { + this.updateGlobalStyles() + }, + methods: { updateBackground(data) { this.background = (data.type === 'custom' || data.type === 'default') ? data.type : data.value diff --git a/apps/theming/src/components/BackgroundSettings.vue b/apps/theming/src/components/BackgroundSettings.vue index 39210569689..aa65a333f0f 100644 --- a/apps/theming/src/components/BackgroundSettings.vue +++ b/apps/theming/src/components/BackgroundSettings.vue @@ -25,30 +25,41 @@ <template> <div class="background-selector"> + <!-- Custom background --> <button class="background filepicker" :class="{ active: background === 'custom' }" tabindex="0" @click="pickFile"> {{ t('theming', 'Pick from Files') }} </button> + + <!-- Default background --> <button class="background default" tabindex="0" :class="{ 'icon-loading': loading === 'default', active: background === 'default' }" @click="setDefault"> {{ t('theming', 'Default image') }} </button> + + <!-- Default admin primary color --> <button class="background color" :class="{ active: background.startsWith('#') }" tabindex="0" + :data-color="Theming.defaultColor" + :data-color-bright="invertTextColor(Theming.defaultColor)" + :style="{ color: invertTextColor(Theming.defaultColor) ? '#000000' : '#ffffff'}" @click="pickColor"> {{ t('theming', 'Plain background') }} </button> + + <!-- Background set selection --> <button v-for="shippedBackground in shippedBackgrounds" :key="shippedBackground.name" v-tooltip="shippedBackground.details.attribution" :class="{ 'icon-loading': loading === shippedBackground.name, active: background === shippedBackground.name }" tabindex="0" class="background" + :data-color-bright="shippedBackground.details.theming === 'dark'" :style="{ 'background-image': 'url(' + shippedBackground.preview + ')' }" @click="setShipped(shippedBackground.name)" /> </div> @@ -69,6 +80,7 @@ export default { directives: { Tooltip, }, + props: { background: { type: String, @@ -79,12 +91,15 @@ export default { default: '', }, }, + data() { return { backgroundImage: generateUrl('/apps/theming/background') + '?v=' + Date.now(), loading: false, + Theming: loadState('theming', 'data', {}), } }, + computed: { shippedBackgrounds() { return Object.keys(shippedBackgroundList).map(fileName => { @@ -97,7 +112,27 @@ export default { }) }, }, + methods: { + invertTextColor(color) { + const l = this.calculateLuma(color) + if (l > 0.6) { + return true + } else { + return false + } + }, + calculateLuma(color) { + const [red, green, blue] = this.hexToRGB(color) + return (0.2126 * red + 0.7152 * green + 0.0722 * blue) / 255 + }, + hexToRGB(hex) { + const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex) + return result + ? [parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16)] + : null + }, + async update(data) { const background = data.type === 'custom' || data.type === 'default' ? data.type : data.value this.backgroundImage = getBackgroundUrl(background, data.version, this.themingDefaultBackground) @@ -128,9 +163,9 @@ export default { const result = await axios.post(generateUrl('/apps/theming/background/custom'), { value: path }) this.update(result.data) }, - async pickColor() { + async pickColor(event) { this.loading = 'color' - const color = OCA && OCA.Theming ? OCA.Theming.color : '#0082c9' + const color = event?.target?.dataset?.color || this.Theming?.color || '#0082c9' const result = await axios.post(generateUrl('/apps/theming/background/color'), { value: color }) this.update(result.data) }, @@ -171,7 +206,7 @@ export default { } &.color { - background-color: var(--color-main-background-not-plain, var(--color-primary)); + background-color: var(--color-primary-default); color: var(--color-primary-text); } @@ -181,14 +216,20 @@ export default { border: 2px solid var(--color-primary); } - &.active:not(.icon-loading):after { - background-image: var(--icon-checkmark-white); - background-repeat: no-repeat; - background-position: center; - background-size: 44px; - content: ''; - display: block; - height: 100%; + &.active:not(.icon-loading) { + &:after { + background-image: var(--icon-checkmark-white); + background-repeat: no-repeat; + background-position: center; + background-size: 44px; + content: ''; + display: block; + height: 100%; + } + + &[data-color-bright]:after { + background-image: var(--icon-checkmark-dark); + } } } } |