feat(settings): preview locale and serialize UI scale application
This commit is contained in:
9 files changed
+284
-20
No files matched your search
@@ -0,0 +1,39 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { createUiScaleApplyQueue } from "@/lib/app/uiScaleApplyQueue";
|
||||
|
||||
function deferred() {
|
||||
let resolve: (() => void) | undefined;
|
||||
return {
|
||||
promise: new Promise<void>((done) => {
|
||||
resolve = done;
|
||||
}),
|
||||
resolve: () => resolve?.(),
|
||||
};
|
||||
}
|
||||
|
||||
describe("ui scale apply queue", () => {
|
||||
it("serializes zoom IPC and only publishes the newest completed target", async () => {
|
||||
const first = deferred();
|
||||
const latest = deferred();
|
||||
const apply = vi.fn((scale: number) => (scale === 0.75 ? first.promise : latest.promise));
|
||||
const applied = vi.fn();
|
||||
const queue = createUiScaleApplyQueue(apply, applied, vi.fn());
|
||||
|
||||
queue.request(0.75);
|
||||
queue.request(1.25);
|
||||
expect(apply).toHaveBeenCalledTimes(1);
|
||||
expect(apply).toHaveBeenLastCalledWith(0.75);
|
||||
|
||||
first.resolve();
|
||||
await Promise.resolve();
|
||||
expect(apply).toHaveBeenCalledTimes(2);
|
||||
expect(apply).toHaveBeenLastCalledWith(1.25);
|
||||
expect(applied).not.toHaveBeenCalled();
|
||||
|
||||
latest.resolve();
|
||||
await queue.whenIdle();
|
||||
|
||||
expect(applied).toHaveBeenCalledTimes(1);
|
||||
expect(applied).toHaveBeenCalledWith(1.25);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,65 @@
|
||||
export interface UiScaleApplyQueue {
|
||||
request: (scale: number) => void;
|
||||
whenIdle: () => Promise<void>;
|
||||
}
|
||||
|
||||
export function createUiScaleApplyQueue(apply: (scale: number) => Promise<void>, onApplied: (scale: number) => void, onError: (scale: number, error: unknown) => void): UiScaleApplyQueue {
|
||||
let queuedScale: number | undefined;
|
||||
let applying = false;
|
||||
let lastAppliedScale: number | undefined;
|
||||
let idleResolvers: Array<() => void> = [];
|
||||
|
||||
function resolveIdle() {
|
||||
if (applying || queuedScale !== undefined) return;
|
||||
const resolvers = idleResolvers;
|
||||
idleResolvers = [];
|
||||
resolvers.forEach((resolve) => resolve());
|
||||
}
|
||||
|
||||
async function flush() {
|
||||
try {
|
||||
while (queuedScale !== undefined) {
|
||||
const scale = queuedScale;
|
||||
queuedScale = undefined;
|
||||
if (scale === lastAppliedScale) continue;
|
||||
|
||||
try {
|
||||
await apply(scale);
|
||||
} catch (error) {
|
||||
onError(scale, error);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Newer requests replace this completed IPC result. Repeating the same
|
||||
// scale is already satisfied by this call, so coalesce it as well.
|
||||
if (queuedScale === undefined || queuedScale === scale) {
|
||||
queuedScale = undefined;
|
||||
lastAppliedScale = scale;
|
||||
onApplied(scale);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
applying = false;
|
||||
if (queuedScale !== undefined) {
|
||||
applying = true;
|
||||
void flush();
|
||||
} else {
|
||||
resolveIdle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function request(scale: number) {
|
||||
queuedScale = scale;
|
||||
if (applying) return;
|
||||
applying = true;
|
||||
void flush();
|
||||
}
|
||||
|
||||
function whenIdle() {
|
||||
if (!applying && queuedScale === undefined) return Promise.resolve();
|
||||
return new Promise<void>((resolve) => idleResolvers.push(resolve));
|
||||
}
|
||||
|
||||
return { request, whenIdle };
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const searchableSelectSource = readFileSync(new URL("../../../components/ui/searchable-select/SearchableSelect.vue", import.meta.url), "utf8");
|
||||
const editorSettingsDialogSource = readFileSync(new URL("../../../components/editor/EditorSettingsDialog.vue", import.meta.url), "utf8");
|
||||
const dataTransferDialogSource = readFileSync(new URL("../../../components/transfer/DataTransferDialog.vue", import.meta.url), "utf8");
|
||||
const editorToolbarSource = readFileSync(new URL("../../../components/layout/EditorToolbar.vue", import.meta.url), "utf8");
|
||||
const schemaDiffConfigStepSource = readFileSync(new URL("../../../components/diff/SchemaDiffConfigStep.vue", import.meta.url), "utf8");
|
||||
@@ -20,6 +21,15 @@ describe("SearchableSelect layout", () => {
|
||||
expect(searchableSelectSource).toContain("props.trimCustom ? searchText.value.trim() : searchText.value");
|
||||
});
|
||||
|
||||
it("forwards an optional style to its portaled content for local preview isolation", () => {
|
||||
expect(searchableSelectSource).toContain('contentStyle?: HTMLAttributes["style"]');
|
||||
expect(searchableSelectSource).toContain(':style="contentStyle"');
|
||||
expect(editorSettingsDialogSource).toContain(':content-style="{ fontFamily: editUiFontFamily || DEFAULT_UI_FONT_FAMILY }"');
|
||||
expect(editorSettingsDialogSource).toContain('@option-hover="previewUiFontOption"');
|
||||
expect(editorSettingsDialogSource).toContain('@option-highlight="previewUiFontOption"');
|
||||
expect(editorSettingsDialogSource).toContain('@option-leave="restoreUiFontFamilyPreview"');
|
||||
});
|
||||
|
||||
it("renders data transfer connection pickers as sidebar-like trees", () => {
|
||||
const treeSelects = dataTransferDialogSource.match(/<ConnectionTreeSelect/g) ?? [];
|
||||
|
||||
|
||||
Reference in new issue
Block a user