mirror of
https://github.com/element-hq/element-call.git
synced 2026-10-15 17:41:07 +00:00
- A catalogue of what can be chosen: no effect, blur, and two shipped backgrounds, the app's own gradients flattened onto its canvas colour. Their ids are what a saved choice stores, so they are named for the pictures. - One setting for the choice, typed as the ids an effect can have and defaulting to blur for anyone who had it on. A stored value we no longer ship, or one that isn't even a string, reads as no effect: it comes from storage another build or a hand may have written. - The pipeline follows it, switching in place to a picture as readily as to blur, and the camera menu's blur toggle reads and writes it. - So does Settings' blur checkbox: a picture reads as blur off, and checking it replaces the picture with blur. The old on/off setting is only read, to carry blur over. First tests for the Settings modal, which fail with the checkbox on the old setting. - The transformer's own init loads a picture chosen before it was built, as the base init does and it had not: the first effect always is, and the picture was drawn black. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
63 lines
1.7 KiB
TypeScript
63 lines
1.7 KiB
TypeScript
/*
|
|
Copyright 2026 Element Creations Ltd.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
Please see LICENSE in the repository root for full details.
|
|
*/
|
|
|
|
import arc from "../graphics/background-arc.jpg?url";
|
|
import glow from "../graphics/background-glow.jpg?url";
|
|
|
|
export const blurRadius = 15;
|
|
|
|
export interface ShippedBackground {
|
|
/** Stored in the user's settings when chosen, so it must not change. */
|
|
id: string;
|
|
imagePath: string;
|
|
}
|
|
|
|
export const shippedBackgrounds: ShippedBackground[] = [
|
|
{ id: "arc", imagePath: arc },
|
|
{ id: "glow", imagePath: glow },
|
|
];
|
|
|
|
export type BackgroundEffect =
|
|
| { kind: "none" }
|
|
| { kind: "blur" }
|
|
| { kind: "shipped"; id: string };
|
|
|
|
/** An effect as the setting stores it, and as the menu names its option. */
|
|
export type EffectId = "none" | "blur" | `image:${string}`;
|
|
|
|
export const noEffect: BackgroundEffect = { kind: "none" };
|
|
|
|
/**
|
|
* Reads a stored effect; one we no longer ship reads as no effect. Stored by
|
|
* hand or by another build, the value need not even be a string.
|
|
*/
|
|
export function parseEffect(raw: unknown): BackgroundEffect {
|
|
if (typeof raw !== "string") return noEffect;
|
|
if (raw === "blur") return { kind: "blur" };
|
|
if (raw.startsWith("image:")) {
|
|
const id = raw.slice("image:".length);
|
|
if (shippedBackgrounds.some((b) => b.id === id))
|
|
return { kind: "shipped", id };
|
|
}
|
|
return noEffect;
|
|
}
|
|
|
|
export function serializeEffect(effect: BackgroundEffect): EffectId {
|
|
switch (effect.kind) {
|
|
case "blur":
|
|
return "blur";
|
|
case "shipped":
|
|
return `image:${effect.id}`;
|
|
default:
|
|
return "none";
|
|
}
|
|
}
|
|
|
|
export function imagePathFor(id: string): string | undefined {
|
|
return shippedBackgrounds.find((b) => b.id === id)?.imagePath;
|
|
}
|