mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-07-18 11:22:08 +08:00
- 新增 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 快捷键注册测试
47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
type WindowsViewportScaleInput = {
|
|
windowWidth: number;
|
|
innerWidth: number;
|
|
devicePixelRatio: number;
|
|
visualViewportScale?: number | null;
|
|
};
|
|
|
|
export const computeWindowsViewportScaleRatio = ({
|
|
windowWidth,
|
|
innerWidth,
|
|
devicePixelRatio,
|
|
}: WindowsViewportScaleInput): number => {
|
|
const normalizedWindowWidth = Number(windowWidth);
|
|
const normalizedInnerWidth = Number(innerWidth);
|
|
const normalizedDevicePixelRatio = Number(devicePixelRatio);
|
|
if (
|
|
!Number.isFinite(normalizedWindowWidth) || normalizedWindowWidth <= 0 ||
|
|
!Number.isFinite(normalizedInnerWidth) || normalizedInnerWidth <= 0 ||
|
|
!Number.isFinite(normalizedDevicePixelRatio) || normalizedDevicePixelRatio <= 0
|
|
) {
|
|
return 1;
|
|
}
|
|
return (normalizedWindowWidth / normalizedDevicePixelRatio) / normalizedInnerWidth;
|
|
};
|
|
|
|
export const hasWindowsViewportScaleDrift = (
|
|
metrics: WindowsViewportScaleInput,
|
|
tolerance = 0.08,
|
|
): boolean => {
|
|
const normalizedTolerance = Math.max(0.01, Number(tolerance) || 0.08);
|
|
const visualViewportScale = Number(metrics.visualViewportScale);
|
|
if (Number.isFinite(visualViewportScale) && Math.abs(visualViewportScale - 1) > normalizedTolerance) {
|
|
return true;
|
|
}
|
|
|
|
const viewportScaleRatio = computeWindowsViewportScaleRatio(metrics);
|
|
return Math.abs(viewportScaleRatio - 1) > normalizedTolerance;
|
|
};
|
|
|
|
export const getWindowsScaleFixNudgedWidth = (width: number): number => {
|
|
const normalizedWidth = Math.trunc(Number(width) || 0);
|
|
if (normalizedWidth <= 0) {
|
|
return 0;
|
|
}
|
|
return normalizedWidth > 480 ? normalizedWidth - 1 : normalizedWidth + 1;
|
|
};
|