Skip to content

Commit 9c3d07c

Browse files
morethanwordsclaude
andcommitted
Themes: a Day theme's gradient that starts at white keeps its wallpaper
The check for the plain white the server gives a cloud theme's Day base (#752) read only the first stop, so a wallPaperNoFile gradient from white to another colour was taken for it too and gave way to the Classic wallpaper. It now asks for a white alone, with the trailing 0 stops getWallPaperColors drops as no colour, which is how the server sends that white. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 06edcb2 commit 9c3d07c

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

‎src/config/themePresets.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
import type {BaseTheme, Theme, ThemeSettings, WallPaper} from '@layer';
14-
import {hsvToRgb, rgbToHsv} from '@helpers/color';
14+
import {getColorsFromWallPaper, hsvToRgb, rgbToHsv} from '@helpers/color';
1515

1616
export type AccentPresetWallpaper = {
1717
intensity: number, // 1..100; sign is derived from `dark`
@@ -146,12 +146,13 @@ export function tintedBaseWallpaperFor(baseColor: BaseColorName): AccentPresetWa
146146

147147
// The server gives the Day base of its cloud themes a plain white instead of a wallpaper; the theme's
148148
// own wallpaper is on its Classic base, which is a light one too. A white picked by the user is
149-
// kept on the AppTheme and never comes through here.
149+
// kept on the AppTheme and never comes through here. Only a white alone gives way (its trailing 0
150+
// stop is no colour, see getWallPaperColors): a gradient that starts at white is a wallpaper.
150151
export function getCloudThemeWallpaper(theme: Theme, themeSettings: ThemeSettings): WallPaper {
151152
const wallPaper = themeSettings.wallpaper;
152153
const isPlainDay = themeSettings.base_theme._ === 'baseThemeDay' &&
153154
wallPaper?._ === 'wallPaperNoFile' &&
154-
wallPaper.settings?.background_color === 0xffffff;
155+
getColorsFromWallPaper(wallPaper) === '#ffffff';
155156
return isPlainDay ? theme.settings.find((s) => s.base_theme._ === 'baseThemeClassic')?.wallpaper ?? wallPaper : wallPaper;
156157
}
157158

‎src/tests/themeWallpaperFallback.test.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ const makeTheme = (wallpaper?: Theme['settings'][number]['wallpaper']) => ({
1717
} as Theme);
1818

1919
describe('the plain white the server gives the Day base of a cloud theme', () => {
20-
const white = {_: 'wallPaperNoFile', id: 1, pFlags: {}, settings: {_: 'wallPaperSettings', pFlags: {}, background_color: 0xffffff}} as const;
20+
// as the server sends it: a 0 in a later stop is no colour
21+
const white = {_: 'wallPaperNoFile', id: 1, pFlags: {}, settings: {_: 'wallPaperSettings', pFlags: {}, background_color: 0xffffff, second_background_color: 0}} as const;
2122
const classic = {...factoryWallpaper, slug: 'classic'};
2223
const make = (base: 'baseThemeDay' | 'baseThemeNight', wallpaper: any) => {
2324
const entry = {_: 'themeSettings', pFlags: {}, base_theme: {_: base}, accent_color: 0, wallpaper} as any;
@@ -29,10 +30,13 @@ describe('the plain white the server gives the Day base of a cloud theme', () =>
2930
expect(getCloudThemeWallpaper(theme, theme.settings[0])).toBe(classic);
3031
});
3132

32-
test('another colour, or another base, stays', () => {
33+
test('another colour, a gradient from white, or another base, stays', () => {
3334
const colored = {...white, settings: {...white.settings, background_color: 0xff0000}};
3435
const day = make('baseThemeDay', colored);
3536
expect(getCloudThemeWallpaper(day, day.settings[0])).toBe(colored);
37+
const gradient = {...white, settings: {...white.settings, second_background_color: 0x2d7ed5}};
38+
const gradientDay = make('baseThemeDay', gradient);
39+
expect(getCloudThemeWallpaper(gradientDay, gradientDay.settings[0])).toBe(gradient);
3640
const night = make('baseThemeNight', white);
3741
expect(getCloudThemeWallpaper(night, night.settings[0])).toBe(white);
3842
});

0 commit comments

Comments
 (0)