Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 8869374

Browse files
authored
Honor font settings in Element Call (#9751)
Because this encodes font settings into widget URLs at the time that the client first loads a call, this has the consequence that users may need to restart their client to see font setting changes take effect in Element Call. For users who rely on these settings for accessibility, it's a lot better than nothing, though.
1 parent 8a0b62c commit 8869374

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/models/Call.ts

+18-2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import PlatformPeg from "../PlatformPeg";
5252
import { getCurrentLanguage } from "../languageHandler";
5353
import DesktopCapturerSourcePicker from "../components/views/elements/DesktopCapturerSourcePicker";
5454
import Modal from "../Modal";
55+
import { FontWatcher } from "../settings/watchers/FontWatcher";
5556

5657
const TIMEOUT_MS = 16000;
5758

@@ -626,8 +627,6 @@ export class ElementCall extends Call {
626627

627628
private constructor(public readonly groupCall: GroupCall, client: MatrixClient) {
628629
// Splice together the Element Call URL for this call
629-
const url = new URL(SdkConfig.get("element_call").url ?? DEFAULTS.element_call.url!);
630-
url.pathname = "/room";
631630
const params = new URLSearchParams({
632631
embed: "",
633632
preload: "",
@@ -637,7 +636,24 @@ export class ElementCall extends Call {
637636
roomId: groupCall.room.roomId,
638637
baseUrl: client.baseUrl,
639638
lang: getCurrentLanguage().replace("_", "-"),
639+
fontScale: `${SettingsStore.getValue("baseFontSize") / FontWatcher.DEFAULT_SIZE}`,
640640
});
641+
642+
// Set custom fonts
643+
if (SettingsStore.getValue("useSystemFont")) {
644+
SettingsStore.getValue<string>("systemFont")
645+
.split(",")
646+
.map((font) => {
647+
// Strip whitespace and quotes
648+
font = font.trim();
649+
if (font.startsWith('"') && font.endsWith('"')) font = font.slice(1, -1);
650+
return font;
651+
})
652+
.forEach((font) => params.append("font", font));
653+
}
654+
655+
const url = new URL(SdkConfig.get("element_call").url ?? DEFAULTS.element_call.url!);
656+
url.pathname = "/room";
641657
url.hash = `#?${params.toString()}`;
642658

643659
// To use Element Call without touching room state, we create a virtual

test/models/Call-test.ts

+26
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,32 @@ describe("ElementCall", () => {
596596

597597
expect(Call.get(room)).toBeNull();
598598
});
599+
600+
it("passes font settings through widget URL", async () => {
601+
const originalGetValue = SettingsStore.getValue;
602+
SettingsStore.getValue = <T>(name: string, roomId?: string, excludeDefault?: boolean) => {
603+
switch (name) {
604+
case "baseFontSize":
605+
return 12 as T;
606+
case "useSystemFont":
607+
return true as T;
608+
case "systemFont":
609+
return "OpenDyslexic, DejaVu Sans" as T;
610+
default:
611+
return originalGetValue<T>(name, roomId, excludeDefault);
612+
}
613+
};
614+
615+
await ElementCall.create(room);
616+
const call = Call.get(room);
617+
if (!(call instanceof ElementCall)) throw new Error("Failed to create call");
618+
619+
const urlParams = new URLSearchParams(new URL(call.widget.url).hash.slice(1));
620+
expect(urlParams.get("fontScale")).toBe("1.2");
621+
expect(urlParams.getAll("font")).toEqual(["OpenDyslexic", "DejaVu Sans"]);
622+
623+
SettingsStore.getValue = originalGetValue;
624+
});
599625
});
600626

601627
describe("instance in a non-video room", () => {

0 commit comments

Comments
 (0)