Skip to content

Commit a05b7da

Browse files
committed
fix: custom background filters not applied on laod
1 parent 3529d44 commit a05b7da

2 files changed

Lines changed: 38 additions & 36 deletions

File tree

frontend/src/ts/components/pages/settings/custom-setting/CustomBackgroundFilters.tsx

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,10 @@ import { JSXElement } from "solid-js";
33
import { configMetadata } from "../../../../config/metadata";
44
import { setConfig } from "../../../../config/setters";
55
import { getConfig } from "../../../../config/store";
6-
import { qs } from "../../../../utils/dom";
6+
import { applyCustomBackgroundFilters } from "../../../../controllers/theme-controller";
77
import { Slider } from "../../../common/Slider";
88
import { Setting } from "../Setting";
99

10-
export function applyCustomBackgroundFilters(
11-
values?: [number, number, number, number],
12-
): void {
13-
const valuesToApply = values ?? getConfig.customBackgroundFilter;
14-
15-
let filterCSS = "";
16-
//blur
17-
if (valuesToApply[0] !== 0) {
18-
filterCSS += `blur(${valuesToApply[0]}rem) `;
19-
}
20-
//brightness
21-
if (valuesToApply[1] !== 1) {
22-
filterCSS += `brightness(${valuesToApply[1]}) `;
23-
}
24-
//saturate
25-
if (valuesToApply[2] !== 1) {
26-
filterCSS += `saturate(${valuesToApply[2]}) `;
27-
}
28-
//opacity
29-
if (valuesToApply[3] !== 1) {
30-
filterCSS += `opacity(${valuesToApply[3]}) `;
31-
}
32-
33-
const css = {
34-
filter: filterCSS,
35-
width: `calc(100% + ${valuesToApply[0] * 8}rem)`,
36-
height: `calc(100% + ${valuesToApply[0] * 8}rem)`,
37-
transform: `scale(${1 + valuesToApply[0] / 100})`,
38-
top: `-${valuesToApply[0] * 4}rem`,
39-
position: "absolute",
40-
};
41-
qs(".customBackground img")?.setStyle(css);
42-
}
43-
4410
export function CustomBackgroundFilters(): JSXElement {
4511
let refBlur: HTMLInputElement | undefined = undefined;
4612
let refBrightness: HTMLInputElement | undefined = undefined;

frontend/src/ts/controllers/theme-controller.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as Arrays from "../utils/arrays";
22
import { isColorDark, isColorLight } from "../utils/colors";
33

4-
import { Config } from "../config/store";
4+
import { Config, getConfig } from "../config/store";
55
import { setConfig } from "../config/setters";
66
import { configEvent } from "../events/config";
77
import * as CustomThemes from "../collections/custom-themes";
@@ -302,10 +302,45 @@ export async function applyCustomBackground(): Promise<void> {
302302

303303
container?.replaceChildren(img);
304304

305+
applyCustomBackgroundFilters();
305306
applyCustomBackgroundSize();
306307
}
307308
}
308309

310+
export function applyCustomBackgroundFilters(
311+
values?: [number, number, number, number],
312+
): void {
313+
const valuesToApply = values ?? getConfig.customBackgroundFilter;
314+
315+
let filterCSS = "";
316+
//blur
317+
if (valuesToApply[0] !== 0) {
318+
filterCSS += `blur(${valuesToApply[0]}rem) `;
319+
}
320+
//brightness
321+
if (valuesToApply[1] !== 1) {
322+
filterCSS += `brightness(${valuesToApply[1]}) `;
323+
}
324+
//saturate
325+
if (valuesToApply[2] !== 1) {
326+
filterCSS += `saturate(${valuesToApply[2]}) `;
327+
}
328+
//opacity
329+
if (valuesToApply[3] !== 1) {
330+
filterCSS += `opacity(${valuesToApply[3]}) `;
331+
}
332+
333+
const css = {
334+
filter: filterCSS,
335+
width: `calc(100% + ${valuesToApply[0] * 8}rem)`,
336+
height: `calc(100% + ${valuesToApply[0] * 8}rem)`,
337+
transform: `scale(${1 + valuesToApply[0] / 100})`,
338+
top: `-${valuesToApply[0] * 4}rem`,
339+
position: "absolute",
340+
};
341+
qs(".customBackground img")?.setStyle(css);
342+
}
343+
309344
window
310345
.matchMedia?.("(prefers-color-scheme: dark)")
311346
?.addEventListener?.("change", (event) => {
@@ -328,6 +363,7 @@ configEvent.subscribe(async ({ key, newValue, nosave }) => {
328363

329364
await clearRandom();
330365
await clearPreview(false);
366+
331367
if (Config.autoSwitchTheme) {
332368
if (prefersColorSchemeDark()) {
333369
await set(Config.themeDark, true);

0 commit comments

Comments
 (0)