Skip to content

Commit d3933cf

Browse files
skjnldsvszaimen
authored andcommitted
Fix primary and debounce to avoid infinite loop
Signed-off-by: John Molakvoæ <[email protected]>
1 parent b3bc7aa commit d3933cf

4 files changed

Lines changed: 30 additions & 24 deletions

File tree

apps/theming/lib/Themes/DefaultTheme.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,12 @@ public function __construct(Util $util,
6767
$this->l = $l;
6868

6969
$this->defaultPrimaryColor = $this->themingDefaults->getDefaultColorPrimary();
70+
$this->primaryColor = $this->themingDefaults->getColorPrimary();
7071

71-
// Override default codefaultPrimaryColorlor if set to improve accessibility
72-
$this->primaryColor = $this->defaultPrimaryColor === BackgroundService::DEFAULT_COLOR
73-
? BackgroundService::DEFAULT_ACCESSIBLE_COLOR
74-
: $this->themingDefaults->getColorPrimary();
72+
// Override default defaultPrimaryColor if set to improve accessibility
73+
if ($this->primaryColor === BackgroundService::DEFAULT_COLOR) {
74+
$this->primaryColor = BackgroundService::DEFAULT_ACCESSIBLE_COLOR;
75+
}
7576
}
7677

7778
public function getId(): string {

apps/theming/lib/ThemingDefaults.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public function getColorPrimary() {
226226
// user-defined primary color
227227
$themingBackground = '';
228228
if (!empty($user)) {
229-
$themingBackground = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background', 'default');
229+
$themingBackground = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background', '');
230230

231231
// if the user-selected background is a background reference
232232
if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $themingBackground)) {

apps/theming/src/components/BackgroundSettings.vue

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,6 @@
3232
@click="pickFile">
3333
{{ t('theming', 'Pick from Files') }}
3434
</button>
35-
<NcColorPicker v-model="Theming.color" @input="pickColor">
36-
<button class="background color"
37-
:class="{ active: background === Theming.color}"
38-
tabindex="0"
39-
:data-color="Theming.color"
40-
:data-color-bright="invertTextColor(Theming.color)"
41-
:style="{ backgroundColor: Theming.color, color: invertTextColor(Theming.color) ? '#000000' : '#ffffff'}"
42-
@click="pickColor">
43-
{{ t('theming', 'Custom color') }}
44-
</button>
45-
</NcColorPicker>
4635

4736
<!-- Default background -->
4837
<button class="background default"
@@ -52,14 +41,26 @@
5241
{{ t('theming', 'Default image') }}
5342
</button>
5443

44+
<!-- Custom color picker -->
45+
<NcColorPicker v-model="Theming.color" @input="debouncePickColor">
46+
<button class="background color"
47+
:class="{ active: background === Theming.color}"
48+
tabindex="0"
49+
:data-color="Theming.color"
50+
:data-color-bright="invertTextColor(Theming.color)"
51+
:style="{ backgroundColor: Theming.color, color: invertTextColor(Theming.color) ? '#000000' : '#ffffff'}">
52+
{{ t('theming', 'Custom color') }}
53+
</button>
54+
</NcColorPicker>
55+
5556
<!-- Default admin primary color -->
5657
<button class="background color"
5758
:class="{ active: background === Theming.defaultColor }"
5859
tabindex="0"
5960
:data-color="Theming.defaultColor"
6061
:data-color-bright="invertTextColor(Theming.defaultColor)"
6162
:style="{ color: invertTextColor(Theming.defaultColor) ? '#000000' : '#ffffff'}"
62-
@click="pickColor">
63+
@click="debouncePickColor">
6364
{{ t('theming', 'Plain background') }}
6465
</button>
6566

@@ -77,13 +78,14 @@
7778
</template>
7879

7980
<script>
80-
import axios from '@nextcloud/axios'
81-
import Tooltip from '@nextcloud/vue/dist/Directives/Tooltip'
82-
import NcColorPicker from '@nextcloud/vue/dist/Components/NcColorPicker'
8381
import { generateUrl } from '@nextcloud/router'
84-
import { loadState } from '@nextcloud/initial-state'
8582
import { getBackgroundUrl } from '../helpers/getBackgroundUrl.js'
83+
import { loadState } from '@nextcloud/initial-state'
8684
import { prefixWithBaseUrl } from '../helpers/prefixWithBaseUrl.js'
85+
import axios from '@nextcloud/axios'
86+
import debounce from 'debounce'
87+
import NcColorPicker from '@nextcloud/vue/dist/Components/NcColorPicker'
88+
import Tooltip from '@nextcloud/vue/dist/Directives/Tooltip'
8789
8890
const shippedBackgroundList = loadState('theming', 'shippedBackgrounds')
8991
@@ -179,6 +181,9 @@ export default {
179181
const result = await axios.post(generateUrl('/apps/theming/background/custom'), { value: path })
180182
this.update(result.data)
181183
},
184+
debouncePickColor: debounce(function() {
185+
this.pickColor(...arguments)
186+
}, 200),
182187
async pickColor(event) {
183188
this.loading = 'color'
184189
const color = event?.target?.dataset?.color || this.Theming?.color || '#0082c9'

apps/theming/tests/ThemingDefaultsTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ public function testGetColorPrimaryWithCustomBackground() {
468468
$this->config
469469
->expects($this->once())
470470
->method('getUserValue')
471-
->with('user', 'theming', 'background', 'default')
471+
->with('user', 'theming', 'background', '')
472472
->willReturn(array_keys(BackgroundService::SHIPPED_BACKGROUNDS)[$backgroundIndex]);
473473

474474
$this->assertEquals($background['primary_color'], $this->template->getColorPrimary());
@@ -486,7 +486,7 @@ public function testGetColorPrimaryWithCustomBackgroundColor() {
486486
$this->config
487487
->expects($this->once())
488488
->method('getUserValue')
489-
->with('user', 'theming', 'background', 'default')
489+
->with('user', 'theming', 'background', '')
490490
->willReturn('#fff');
491491

492492
$this->assertEquals('#fff', $this->template->getColorPrimary());
@@ -504,7 +504,7 @@ public function testGetColorPrimaryWithInvalidCustomBackgroundColor() {
504504
$this->config
505505
->expects($this->once())
506506
->method('getUserValue')
507-
->with('user', 'theming', 'background', 'default')
507+
->with('user', 'theming', 'background', '')
508508
->willReturn('nextcloud');
509509

510510
$this->assertEquals($this->template->getDefaultColorPrimary(), $this->template->getColorPrimary());

0 commit comments

Comments
 (0)