Files
MyGoNavi/frontend/src/utils/windowsScaleFix.test.ts
Syngnat 2580e4d6f3 🐛 fix(window): 直接调 WebView2 zoom factor 零感知修复 Windows 字体异常
- 新增 ResetWebViewZoom RPC:从 ctx 反射拿 Wails 内部 *edge.Chromium,调 PutZoomFactor(1.0) 强制 WebView2 重算 D2D/DirectWrite 字体度量,完全不动窗口零动画
- 自动路径:maximised + restore + drift 时直接调 backend reset,告别 9848b8b2 之后字体偶发变大的取舍
- 手动路径:保留 Ctrl+Shift+0 快捷键作为兜底(优先 WebView2 reset,失败回退 toggle)
- 撤回上一版 CSS zoom nudge:实测在 WebView2 上不能修字体度量(度量缓存在 D2D 层不在 Chromium layout 层)
- 反射做了 3 层签名校验(frontend value / chromium 字段 / PutZoomFactor 方法签名),wails 升级破坏接口时返回 error 不让进程崩溃
- 新增 windows-only 反射逻辑测试 4 个、跨平台 RPC 行为测试 2 个、Ctrl+Shift+0 快捷键注册测试
2026-05-15 16:01:18 +08:00

46 lines
1.2 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
computeWindowsViewportScaleRatio,
getWindowsScaleFixNudgedWidth,
hasWindowsViewportScaleDrift,
} from './windowsScaleFix';
describe('windowsScaleFix', () => {
it('treats matching window and viewport metrics as stable', () => {
const ratio = computeWindowsViewportScaleRatio({
windowWidth: 1920,
innerWidth: 1280,
devicePixelRatio: 1.5,
});
expect(ratio).toBeCloseTo(1, 5);
expect(hasWindowsViewportScaleDrift({
windowWidth: 1920,
innerWidth: 1280,
devicePixelRatio: 1.5,
})).toBe(false);
});
it('detects zoom drift from viewport width mismatch', () => {
expect(hasWindowsViewportScaleDrift({
windowWidth: 1920,
innerWidth: 1100,
devicePixelRatio: 1.5,
})).toBe(true);
});
it('detects zoom drift from visual viewport scale', () => {
expect(hasWindowsViewportScaleDrift({
windowWidth: 1600,
innerWidth: 1600,
devicePixelRatio: 1,
visualViewportScale: 1.12,
})).toBe(true);
});
it('returns a one-pixel nudge width for normal windows', () => {
expect(getWindowsScaleFixNudgedWidth(960)).toBe(959);
expect(getWindowsScaleFixNudgedWidth(420)).toBe(421);
});
});