feat(desktop): deliver font settings to plugin sandboxes

This commit is contained in:
Jinpy authored and GitHub committed 2026-09-19 19:13:30 +08:00
1 parent ba6b74beea
commit b1b99eccfb
15 files changed
+309 -25

No files matched your search

+51
View File
@@ -175,4 +175,55 @@ describe("useTheme on Linux", () => {
expect(theme.customUiColors.value.background).toBe("#ffffff");
expect(theme.customUiColorsDark.value.background).toBe("#1a1b1e");
});
it("bumps the theme revision so out-of-band token writers (font settings) reach plugin bridges", async () => {
const theme = await loadTheme("light");
const before = theme.themeRevision.value;
theme.bumpThemeRevision();
expect(theme.themeRevision.value).toBe(before + 1);
// No theme classes are touched: this is a pure revision bump.
expect(document.documentElement.classList.contains("disable-transitions")).toBe(false);
});
it("writeRootToken writes the inline override and bumps the revision", async () => {
const theme = await loadTheme("light");
const before = theme.themeRevision.value;
theme.writeRootToken("--dbx-test-token", "1px");
expect(document.documentElement.style.getPropertyValue("--dbx-test-token")).toBe("1px");
expect(theme.themeRevision.value).toBe(before + 1);
document.documentElement.style.removeProperty("--dbx-test-token");
});
it("writeRootToken coalesces rapid writes into one debounced bump", async () => {
const theme = await loadTheme("light");
const before = theme.themeRevision.value;
theme.writeRootToken("--dbx-test-token", "1px", { debounceMs: 30 });
theme.writeRootToken("--dbx-test-token", "2px", { debounceMs: 30 });
// Neither bump has fired yet, but the write itself is immediate.
expect(theme.themeRevision.value).toBe(before);
expect(document.documentElement.style.getPropertyValue("--dbx-test-token")).toBe("2px");
await new Promise((resolve) => setTimeout(resolve, 60));
expect(theme.themeRevision.value).toBe(before + 1);
document.documentElement.style.removeProperty("--dbx-test-token");
});
it("writeRootToken with an immediate write supersedes a pending debounced bump", async () => {
const theme = await loadTheme("light");
const before = theme.themeRevision.value;
theme.writeRootToken("--dbx-test-token", "1px", { debounceMs: 30 });
theme.writeRootToken("--dbx-test-token", "2px");
expect(theme.themeRevision.value).toBe(before + 1);
await new Promise((resolve) => setTimeout(resolve, 60));
// The superseded timer must not fire a second bump.
expect(theme.themeRevision.value).toBe(before + 1);
document.documentElement.style.removeProperty("--dbx-test-token");
});
});