fix(window): 启动时把窗口夹进当前屏幕,修「画面被顶起来」
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 1m21s

用户两次反馈:底部工具栏跑到屏幕中间、左右栏底部被拉长。之前按「文档滚动」修过(html/body overflow:hidden),
仍复现 —— 说明不是滚动,而是**窗口本身比当前屏幕还高**:
src-tauri 的 restore_geom 会恢复上次窗口尺寸,只校验中心点是否落在某块显示器内,不夹尺寸。
换显示器 / 远程会话分辨率变小后,恢复出超大窗口 ⇒ 底部工具栏与侧栏底部落到屏幕外,看起来就是「被顶起来」。

改动:
- src-tauri/src/lib.rs:新增 clamp_geom(win, min_w, min_h) —— 取窗口中心所在显示器,
  把宽高夹到 屏幕尺寸-40px(不小于窗口下限),并把位置夹回屏幕内;
  restore_geom 末尾调用一次,无历史几何时在 setup 里也调用一次
- src/runtime-boot-load.js:启动时往 _boot.log 记一行 viewport/screen/dpr,
  下次再出现可直接判断是不是窗口比屏幕大
This commit is contained in:
qiqi committed 2026-11-28 00:31:33 +08:00
1 parent ab3833ade7
commit 0b46512667
3 files changed
+51 -1

No files matched your search

+1 -1
View File
@@ -22,7 +22,7 @@
- 图片**新写入主通道 = IndexedDB Blob `{__blob}` / key `imgblob_<hash>_<len>`** (A) `app.js:2143`;`{__cache}`(Cache Storage)为兜底;\`ref_\`(`app.js` 内定义的 `IDB_REF_PREFIX = 'ref_'`)为 legacy 形态 (A)。
- 大图判定:`isBigDataUrl` = `data:` 且 `length > 3000` (A) `app.js:2018`;**画布保存保留阈值** `< 16384` 才原样保留 (A) `app.js:2182`。**两处阈值并存,含义不同**。
- 单测是**源码契约测试**:`tests/` 目录共 **493** 处源码文本钉点(`source.includes` / `source.indexOf` / `/re/.test(source)`),分布在 **20** 个文件(其中 `iwb-v32-web-test.js` 一个就占 **407**)→ **结构性重构会先打红测试**。**该数字已由 `tests/source-text-ratchet-test.js` 的「只减不增」棘轮守门**(2026-10-20 起守卫范围从 1 个文件扩到全目录:新增任何一处源码文本钉点都会打红)。**2026-11-12 复算**(`npm run audit:pins`,v3.24.76):二分 STRUCT **417** / NAME **76**;形态 **POS 403 / NEG 87 / COUNT 3**;难度 **易 62 / 中 316 / 难 115**。钉点减法第一批(v3.24.72)把 **537 → 505**:8 条探针钉点改为「门禁内 spec 是否真的读该计数器」、5 条改为运行时断言(生产态 `window` 上无探针)、10 条改为 DOM 断言(质量档位禁用 / 传输页无三模式按钮 / 模型项 title)、4 条改为运行时对象断言(健康检查两域、策略对象冻结)、其余 9 条有同文件 DOM 等价断言或仅剩 NEG。第二批(v3.24.76)把 **505 → 493**:94-5~7 三条「多标签释放语义」(10 处正则)换成 `tests/iwb-tabs-release.spec.js` 的 3 条真 e2e,剩 1 条「消费方契约」(断言该 spec 在门禁内且 spec 源码真的读两个探针);另 2 条 `wPurgeIntent.add` 钉点改为读 `src/workspace-purge.js`。**这一批一换就查出 3 个真缺陷**(objectURL 从未释放 / 彻底删除留孤儿标签 · session / 刷新后误回收打开标签的图)—— 见 CHANGELOG v3.24.76。
- `app.js` = 单 IIFE **8,329 行**(**双层预算**:绝对上限 8,329 / 占总源码 ≤ 40%,现 **26.1%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **2,174 行**(上限 **2,179**,余量 5;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **117** 个模块 / 23,562 行,`sourceModules` 117 项;v3.24.68 新增 `clipboard-graph.js`,v3.24.74 新增 `image-admit.js`,v3.24.75 新增 `image-dedupe.js`,v3.24.76 新增 `workspace-purge.js`,v3.24.79 新增 `generation-provider-ping.js`,v3.24.80 删除无调用的 `createWBFlushViewport` 17 行)。
- `app.js` = 单 IIFE **8,329 行**(**双层预算**:绝对上限 8,329 / 占总源码 ≤ 40%,现 **26.1%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **2,174 行**(上限 **2,179**,余量 5;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **117** 个模块 / 23,564 行,`sourceModules` 117 项;v3.24.68 新增 `clipboard-graph.js`,v3.24.74 新增 `image-admit.js`,v3.24.75 新增 `image-dedupe.js`,v3.24.76 新增 `workspace-purge.js`,v3.24.79 新增 `generation-provider-ping.js`,v3.24.80 删除无调用的 `createWBFlushViewport` 17 行)。
- 门禁:`npm run verify` = `verify:ci`(`build` → `node --check app.js` → `node --check dist/app.js` → `check-dist.js` → `lint`(ESLint 正确性规则,`src/` + `app.js`,P4-16a)→ `test:unit` → `test` → `test:facts`)+ `test:e2e` (A) `package.json`。
## 2. 门禁与环境现状
+48
View File
@@ -60,6 +60,51 @@ fn save_geom(app: &AppHandle, label: &str) {
}
// 恢复上次窗口大小与位置;中心点不在任何显示器内就只恢复尺寸(换过显示器不至于把窗口丢到屏幕外)
fn clamp_geom(win: &tauri::Window, min_w: u32, min_h: u32) {
// v3.26.109:窗口不能被“恢复”成比当前屏幕还大。
// 换显示器 / 远程会话分辨率变小后,恢复出的超大窗口会让底部工具栏与左右栏底部落到屏幕外,
// 看起来就是“画面被顶起来、工具栏跑到中间”(2026-11-27 用户两次报告)。
let Ok(size) = win.outer_size() else { return };
let monitors = win.available_monitors().unwrap_or_default();
if monitors.is_empty() {
return;
}
let pos = win.outer_position().unwrap_or(PhysicalPosition::new(0, 0));
let cx = pos.x + size.width as i32 / 2;
let cy = pos.y + size.height as i32 / 2;
let mut target = None;
for m in &monitors {
let mp = m.position();
let ms = m.size();
if cx >= mp.x && cx <= mp.x + ms.width as i32 && cy >= mp.y && cy <= mp.y + ms.height as i32 {
target = Some((mp.x, mp.y, ms.width, ms.height));
break;
}
}
let Some((mx, my, mw, mh)) = target.or_else(|| {
monitors.first().map(|m| {
let mp = m.position();
let ms = m.size();
(mp.x, mp.y, ms.width, ms.height)
})
}) else {
return;
};
const MARGIN: u32 = 40;
let max_w = mw.saturating_sub(MARGIN).max(min_w);
let max_h = mh.saturating_sub(MARGIN).max(min_h);
let w = size.width.min(max_w);
let h = size.height.min(max_h);
if w != size.width || h != size.height {
let _ = win.set_size(PhysicalSize::new(w, h));
}
let x = pos.x.max(mx).min(mx + mw as i32 - w as i32);
let y = pos.y.max(my).min(my + mh as i32 - h as i32);
if x != pos.x || y != pos.y {
let _ = win.set_position(PhysicalPosition::new(x, y));
}
}
fn restore_geom(app: &AppHandle, label: &str, min_w: u32, min_h: u32) {
let Some(win) = app.get_window(label) else {
return;
@@ -96,6 +141,7 @@ fn restore_geom(app: &AppHandle, label: &str, min_w: u32, min_h: u32) {
if visible {
let _ = win.set_position(PhysicalPosition::new(g.x, g.y));
}
clamp_geom(&win, min_w, min_h);
}
fn show_main(app: &AppHandle) {
@@ -1547,6 +1593,8 @@ pub fn run() {
restore_file_grants(app.handle());
// 恢复上次窗口大小/位置(主窗口下限与 tauri.conf 的 minWidth/minHeight 对齐)
restore_geom(app.handle(), "main", 1024, 640);
// 没有历史几何时也要夹一次:默认尺寸可能大于当前屏幕(远程/小屏场景)
if let Some(w) = app.handle().get_window("main") { clamp_geom(&w, 1024, 640); }
build_tray(app.handle())?;
// macOS 必须有应用菜单,否则 Cmd+C / Cmd+V / Cmd+X 根本不会进 WebView(Tauri 已知问题)
#[cfg(target_os = "macos")]
+2
View File
@@ -25,6 +25,8 @@
}
} catch (e) { /* ignore */ }
if (window.IWBBootProgress) window.IWBBootProgress.report('finalize', 1, 1)
// v3.26.109 诊断:记一次视口/屏幕尺寸,用来确认「画面被顶起来」是不是窗口比屏幕还高
try { const stg = (typeof window !== 'undefined') ? window.IWBStorageFile : null; if (stg && stg.logLine) stg.logLine('viewport ' + window.innerWidth + 'x' + window.innerHeight + ' screen ' + (screen && screen.width) + 'x' + (screen && screen.height) + ' dpr ' + window.devicePixelRatio) } catch (e) { /* ignore */ }
api('config').then((r) => { if (r && Array.isArray(r.providers)) setConfig(r) }).catch(() => setServer({ ok: false }))
api('prompts').then((r) => {
if (r && Array.isArray(r.prompts)) setPrompts(r.prompts)