Skip to content

Commit

Permalink
Honor font settings in Element Call (matrix-org#9751)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
robintown authored Dec 14, 2022
1 parent 8a0b62c commit 8869374
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/models/Call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import PlatformPeg from "../PlatformPeg";
import { getCurrentLanguage } from "../languageHandler";
import DesktopCapturerSourcePicker from "../components/views/elements/DesktopCapturerSourcePicker";
import Modal from "../Modal";
import { FontWatcher } from "../settings/watchers/FontWatcher";

const TIMEOUT_MS = 16000;

Expand Down Expand Up @@ -626,8 +627,6 @@ export class ElementCall extends Call {

private constructor(public readonly groupCall: GroupCall, client: MatrixClient) {
// Splice together the Element Call URL for this call
const url = new URL(SdkConfig.get("element_call").url ?? DEFAULTS.element_call.url!);
url.pathname = "/room";
const params = new URLSearchParams({
embed: "",
preload: "",
Expand All @@ -637,7 +636,24 @@ export class ElementCall extends Call {
roomId: groupCall.room.roomId,
baseUrl: client.baseUrl,
lang: getCurrentLanguage().replace("_", "-"),
fontScale: `${SettingsStore.getValue("baseFontSize") / FontWatcher.DEFAULT_SIZE}`,
});

// Set custom fonts
if (SettingsStore.getValue("useSystemFont")) {
SettingsStore.getValue<string>("systemFont")
.split(",")
.map((font) => {
// Strip whitespace and quotes
font = font.trim();
if (font.startsWith('"') && font.endsWith('"')) font = font.slice(1, -1);
return font;
})
.forEach((font) => params.append("font", font));
}

const url = new URL(SdkConfig.get("element_call").url ?? DEFAULTS.element_call.url!);
url.pathname = "/room";
url.hash = `#?${params.toString()}`;

// To use Element Call without touching room state, we create a virtual
Expand Down
26 changes: 26 additions & 0 deletions test/models/Call-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,32 @@ describe("ElementCall", () => {

expect(Call.get(room)).toBeNull();
});

it("passes font settings through widget URL", async () => {
const originalGetValue = SettingsStore.getValue;
SettingsStore.getValue = <T>(name: string, roomId?: string, excludeDefault?: boolean) => {
switch (name) {
case "baseFontSize":
return 12 as T;
case "useSystemFont":
return true as T;
case "systemFont":
return "OpenDyslexic, DejaVu Sans" as T;
default:
return originalGetValue<T>(name, roomId, excludeDefault);
}
};

await ElementCall.create(room);
const call = Call.get(room);
if (!(call instanceof ElementCall)) throw new Error("Failed to create call");

const urlParams = new URLSearchParams(new URL(call.widget.url).hash.slice(1));
expect(urlParams.get("fontScale")).toBe("1.2");
expect(urlParams.getAll("font")).toEqual(["OpenDyslexic", "DejaVu Sans"]);

SettingsStore.getValue = originalGetValue;
});
});

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

0 comments on commit 8869374

Please sign in to comment.