From d4542d2308ec5e5ad69af92b33555d153eec166d Mon Sep 17 00:00:00 2001 From: xiaomakuaiz Date: Sat, 25 Jul 2026 16:09:53 +0000 Subject: [PATCH] =?UTF-8?q?fix(desktop):=20mac=20=E7=BA=A2=E7=BB=BF?= =?UTF-8?q?=E7=81=AF=E4=B8=8D=E5=86=8D=E5=8E=8B=E4=BD=8F=E4=B8=80=E7=BA=A7?= =?UTF-8?q?=E5=AF=BC=E8=88=AA=E6=A0=8F=E7=9A=84=E5=88=86=E9=9A=94=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 几何差 4px。mac 壳用 TitleBarStyle::Overlay(src/main.rs),原生红绿灯直接落在 UI 上、位置由系统决定:三颗 12pt 按钮圆心 x=20/40/60,最右那颗缩放键右缘到 x≈66;而一级导航栏宽 62px、右边框正好在 x=62。窄窗下媒体查询把栏收到 58px, 压得更多。 mac 下把栏加宽到 76px(红绿灯落区 + 10px 余量),窄窗 74px(底线是不低于 66)。 这是 mac 上的通行做法:系统自家的 Finder / 邮件 / 备忘录都让侧栏通栏到顶、红绿灯 浮在其上,Slack 的工作区栏、Discord 的服务器栏那种窄图标栏也都在 70px 上下—— 宽度本就是为装下红绿灯留的。竖向留白早就有了(MacDragSpacer 的 50px),这次只是 把横向补齐。 没走另外两条路: - 用 traffic_light_position 把红绿灯右移让开这一栏——移过去它们就浮在二级侧栏上、 脱离窗口左上角,比压线更怪(该 API 的常见用法是**下移**与工具栏对齐,不是右移躲避) - 顶部加一条横贯整宽的标题条(VS Code 那种)——Windows 端走的正是这条(自绘 36px 标题栏),但 mac 端这么做要拆掉通栏侧栏的观感。两平台各随各的惯例,不是不一致 栏宽从内联样式挪进 CSS(.mc-nav-rail):内联 width 会压过平台与窄窗两条规则, 是这个修复的单点失效处。补了一条渲染断言守它——内联 width 一回来测试就挂, 反向验证过(加回 width: 62 确实挂,去掉即过)。原来媒体查询里的 !important 是 用来压内联值的,一并去掉。 data-platform="mac" 由 main.tsx 在首帧前落到根节点,与 data-theme / data-accent 同一姿势(styles.css 头部已补记这一维)。判定不成立时按非 mac 走,即维持现状、 不会崩。 验证:tsc --noEmit 无输出;vitest 230 passed(新增 1 例);vite build OK,产物里 四条栏宽规则 62/76/58/74 俱在。**未做视觉验证**——需要在 mac 上确认按钮与分隔线 真的分开了、data-platform 确实落上了;若 76px 观感偏宽,改 styles.css 那两个数即可。 --- desktop/ui/src/main.tsx | 7 +++++- desktop/ui/src/navigation.test.tsx | 38 ++++++++++++++++++++++++++++++ desktop/ui/src/sidebar.tsx | 4 +++- desktop/ui/src/styles.css | 15 +++++++++++- tasks/todo.md | 21 +++++++++++++++++ 5 files changed, 82 insertions(+), 3 deletions(-) diff --git a/desktop/ui/src/main.tsx b/desktop/ui/src/main.tsx index 3b50d32d..d3162b3e 100644 --- a/desktop/ui/src/main.tsx +++ b/desktop/ui/src/main.tsx @@ -1,13 +1,18 @@ import { StrictMode } from "react"; import { createRoot } from "react-dom/client"; import App from "./App"; -import { inDesktopShell } from "./host"; +import { inDesktopShell, isMacShell } from "./host"; import { applyStoredTheme } from "./theme"; import "./styles.css"; // 主题偏好在首帧前落到根节点:深色下不会先闪一帧浅色底 applyStoredTheme(); +// 平台也落到根节点:mac 壳的原生红绿灯直接盖在 UI 左上角(Overlay 标题栏), +// 最左栏要为它让出宽度。具体宽度是布局的事,写在 styles.css 的 .mc-nav-rail; +// 这里只声明"我是谁"。判定不成立时按非 mac 走,即维持原样、不会崩。 +if (isMacShell()) document.documentElement.dataset.platform = "mac"; + // 桌面壳内屏蔽 WebView 默认右键菜单(重新加载/检查元素等浏览器项); // 输入框与选中文本保留系统菜单(复制/粘贴依赖它)。浏览器模式不干预。 // 壳判定放进处理器而非注册时:不依赖 __TAURI__ 注入与模块求值的先后 diff --git a/desktop/ui/src/navigation.test.tsx b/desktop/ui/src/navigation.test.tsx index e7873f26..f8ac2482 100644 --- a/desktop/ui/src/navigation.test.tsx +++ b/desktop/ui/src/navigation.test.tsx @@ -18,6 +18,44 @@ afterEach(() => { vi.unstubAllGlobals(); }); +describe("一级导航栏的栏宽归属", () => { + // mac 壳的红绿灯盖在这一栏上,栏宽因此要随平台/窗宽变(styles.css .mc-nav-rail)。 + // 内联 width 会压过那两条 CSS 规则,红绿灯压线的毛病就会静默复发—— + // 这条断言守的是"宽度必须留在 CSS 里"。 + it("栏宽不写在内联样式里,留给 CSS 按平台与窗宽决定", () => { + const html = renderToStaticMarkup( + {}} + onRefreshCloud={() => {}} + onNewCloudTask={() => {}} + onOpenCloudTask={() => {}} + onSelect={() => {}} + onNewTask={() => {}} + onProjectArchive={() => {}} + onNewChat={() => {}} + onOpenSettings={() => {}} + onArchive={() => {}} + onDelete={() => {}} + onRename={() => {}} + />, + ); + + const rail = /
{ it("云端任务标题栏提供新建按钮", () => { const html = renderToStaticMarkup( diff --git a/desktop/ui/src/sidebar.tsx b/desktop/ui/src/sidebar.tsx index a2684ed4..7a031f72 100644 --- a/desktop/ui/src/sidebar.tsx +++ b/desktop/ui/src/sidebar.tsx @@ -990,7 +990,9 @@ export function Sidebar({ return (
-
+ {/* 栏宽在 styles.css(.mc-nav-rail):mac 壳要让开红绿灯,窄窗要收窄, + 两条规则都得能压过来——写成内联样式就把它们全挡了 */} +
{!isWindowsShell() && MonkeyCode}
diff --git a/desktop/ui/src/styles.css b/desktop/ui/src/styles.css index 1a6258f9..018c45e6 100644 --- a/desktop/ui/src/styles.css +++ b/desktop/ui/src/styles.css @@ -9,6 +9,8 @@ * 外观是正交的两维,都落在根节点属性上(见 ui/src/theme.ts): * data-theme 深浅——:root(浅) / [data-theme="dark"] * data-accent 主题色——缺省即默认绿,其余见文件末尾的生成块 + * 另有一维不是偏好而是环境,由 ui/src/main.tsx 落上: + * data-platform 宿主平台——目前只有 "mac",用于给原生红绿灯让位(.mc-nav-rail) * 主题色那几十个色值由 scripts/gen_accent_tokens.py 算好写死(运行时算不了色), * 改它请改脚本后重新生成,别手改生成块。 */ :root { @@ -572,8 +574,19 @@ textarea::placeholder, input::placeholder { color: var(--t6); } background: var(--card) !important; } +/* 一级空间导航的栏宽。 + * + * mac 壳用 TitleBarStyle::Overlay(src/main.rs),原生红绿灯直接落在 UI 上, + * 位置由系统给:三颗 12pt 按钮圆心在 x=20/40/60,最右那颗缩放键右缘到 x≈66。 + * 62px 的栏放不下它——按钮会正好压在栏的右边框上。mac 下加宽到 76px,给红绿灯 + * 留出整条落区外加 10px 余量;窄窗也不能收到 66px 以下,否则压线原样复现。 + * data-platform 在 ui/src/main.tsx 落到根节点。 */ +.mc-nav-rail { width: 62px; } +[data-platform="mac"] .mc-nav-rail { width: 76px; } + @media (max-width: 1080px) { - .mc-nav-rail { width: 58px !important; } + .mc-nav-rail { width: 58px; } + [data-platform="mac"] .mc-nav-rail { width: 74px; } .mc-sidebar-panel { width: 220px !important; } } diff --git a/tasks/todo.md b/tasks/todo.md index 00c0c266..f4d97d00 100644 --- a/tasks/todo.md +++ b/tasks/todo.md @@ -2161,3 +2161,24 @@ index.html 的首帧底色(样式表还没加载,已被检查器盯住)、`cloud 验证:`tsc --noEmit` 无输出;`vitest` 30 files / 229 passed(本次新增 6); `vite build` OK;四个检查器 + scripts 单测全 OK。 + +## mac 红绿灯压住一级导航栏的分隔线(2026-07-25) + +几何对不上:mac 壳用 `TitleBarStyle::Overlay`(`src/main.rs`),原生红绿灯直接 +落在 UI 上,位置由系统给——三颗 12pt 按钮圆心 x=20/40/60,最右那颗缩放键右缘 +到 x≈66;而一级导航栏宽 62px、右边框正好在 x=62。差 4px,压上去了。窄窗下 +媒体查询把栏收到 58px,压得更多。 + +- [x] mac 下把栏加宽到 76px(红绿灯落区 + 10px 余量),窄窗 74px(不能低于 66) +- [x] 栏宽从内联样式挪进 CSS(`.mc-nav-rail`):内联 width 会压过平台与窄窗 + 两条规则。补了渲染断言守这条——内联 width 一回来测试就挂(反向验证过) +- [x] `data-platform="mac"` 由 `main.tsx` 在首帧前落到根节点,与 data-theme / + data-accent 同一姿势;判定不成立时按非 mac 走,即维持原样、不会崩 + +没选的方案:用 Tauri 的 `traffic_light_position` 把红绿灯右移让开这一栏—— +移过去它们就浮在二级侧栏上、脱离窗口左上角,比压线更怪。"最左栏够宽、红绿灯 +落在它上面"是 mac 上的通行做法(Slack / Linear / Notion 都是)。 + +验证:`tsc --noEmit` 无输出;`vitest` 230 passed;`vite build` OK,产物里四条 +栏宽规则(62/76/58/74)俱在。**未做视觉验证**——需要在 mac 上确认按钮与分隔线 +真的分开了,以及 `data-platform` 确实落上了。