From 60c146f8b7eda537622655cc3cff620ff4921269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=81=E5=86=9C=E9=98=BF=E6=A5=A0?= Date: Sun, 15 Nov 2026 19:21:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(ui):=20=E4=BF=AE=E6=AD=A3=E9=A3=8E=E6=89=87?= =?UTF-8?q?=E8=BD=AC=E8=BD=B4=E4=B8=8E=E9=80=9F=E7=8E=87=E5=9B=BE=E5=B9=B6?= =?UTF-8?q?=E7=B2=BE=E7=AE=80=E8=BF=9B=E7=A8=8B=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- docs/architecture.md | 8 +-- docs/dashboard-polish-plan.md | 35 +++++++++++++ docs/monitoring.md | 10 +++- docs/testing.md | 12 ++--- docs/ui-design-standard.md | 12 +++-- kymo/Features/MenuBar/MemoryDetailsView.swift | 5 +- .../MenuBar/MenuPanelView+Network.swift | 2 +- .../MenuBar/MenuPanelView+ResourceCards.swift | 2 +- .../Features/MenuBar/NativeProcessTable.swift | 46 +++++++++++++---- kymo/Features/MenuBar/ProcessTableView.swift | 24 ++++----- kymo/Resources/Localizable.xcstrings | 22 +++++++++ kymo/UI/Charts/NativePanelCurve.swift | 41 +++++++++++++--- kymo/UI/Charts/PanelTrendChart.swift | 3 +- kymo/UI/Components/FanSpeedIndicator.swift | 49 ++++++++++++++++--- kymoTests/FanRotorChecks.swift | 29 ++++++++--- kymoTests/MemoryChecks.swift | 9 ++++ kymoTests/NativeMetricDrawingChecks.swift | 33 ++++++++++++- kymoTests/NativeProcessTableChecks.swift | 34 +++++++++---- kymoTests/ProcessSectionChecks.swift | 7 +-- kymoTests/ResourceCardChecks.swift | 23 +-------- 21 files changed, 303 insertions(+), 107 deletions(-) create mode 100644 docs/dashboard-polish-plan.md diff --git a/README.md b/README.md index 23fe35a..886b0da 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,9 @@ Kymo 是 macOS 菜单栏资源监控工具。菜单栏常驻品牌图标,点 - 存储:主目录所在卷容量、块设备读写速率、各本地卷容量、可读取的 SMART 寿命与通电时间。 - 电池:电量、功率、电源状态、健康度、循环次数、放电时间估计。 - 网络:接口切换、收发速率与累计字节、路径状态、本地和公网 IP 及复制。 -- 进程:PID、名称、CPU、内存 footprint、CPU 平均功率、线程数和路径;支持搜索、列排序及复制,功率缺失始终排末。 +- 进程:PID、名称、CPU、内存 footprint、CPU 平均功率、线程数六列;路径仍支持搜索和右键复制,无横向滚动条;支持列排序及复制,功率缺失始终排末。 -面板支持固定显示、保持唤醒、暂停 / 恢复采样。首行 CPU / GPU / 内存,次行电池 / 存储 / 网络,第三行进程表跨满内容区;默认三行均高 176pt,面板 648×630pt,小屏退为两列或单列并滚动。趋势覆盖卡片全宽全高,文字叠放其上;CPU 系统 / 用户、内存应用 / 联动 / 压缩、GPU 占用 / 空闲按分量堆叠,悬浮查询原始历史。逐核为方块竖柱;风扇图标沿用转速档位旋转,暂停、隐藏或系统减弱动态效果时停转。数字与曲线直接更新,无背景模糊。资源和进程同时按可见性采样,后台趋势独立控制。面板刷新默认 2 秒;默认隐藏停止采样,可显式开启后台趋势并配置间隔(新配置 30 秒)。设置窗口提供系统 / 浅色 / 深色外观、简体中文 / 繁體中文 / English 和关于信息。 +面板支持固定显示、保持唤醒、暂停 / 恢复采样。首行 CPU / GPU / 内存,次行电池 / 存储 / 网络,第三行进程表跨满内容区;默认三行均高 176pt,面板 648×630pt,小屏退为两列或单列并滚动。趋势覆盖卡片全宽全高,文字叠放其上;CPU 系统 / 用户、内存应用 / 联动 / 压缩、GPU 占用 / 空闲按分量堆叠,悬浮查询原始历史;存储 / 网络以 60% 高度零轴上下显示读 / 写、上传 / 下载,内存不再重复显示容量条。逐核为方块竖柱;风扇图标沿用转速档位旋转,暂停、隐藏或系统减弱动态效果时停转。数字与曲线直接更新,无背景模糊。资源和进程同时按可见性采样,后台趋势独立控制。面板刷新默认 2 秒;默认隐藏停止采样,可显式开启后台趋势并配置间隔(新配置 30 秒)。设置窗口提供系统 / 浅色 / 深色外观、简体中文 / 繁體中文 / English 和关于信息。 部分硬件指标依赖机型、驱动与权限,缺失值显示为 `--` 或对应状态。GPU 不提供逐核占用;耗电进程显示系统归属的 CPU 能量区间平均功率,注明可读覆盖范围,不代表完整应用总耗电。指标口径和限制见[监控指标](docs/monitoring.md)。 diff --git a/docs/architecture.md b/docs/architecture.md index a54b7b7..f31a532 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -55,15 +55,15 @@ SystemSampler actor 持有差分基线。CPU / 内存 Mach 查询取得的 host ## 展示与本地状态 -ResourceCard 通过 NativeContentHost 使用固定尺寸的独立 NSHostingView,传递字体、颜色、语言及外观环境;更新沿用挂载身份,卸载清空子宿主内容。背景绘图区覆盖卡片全宽全高:底边为 0,顶边为 100% / 内存物理总量 / 自动速率上限,文字和控件叠放其上。统一 16pt 圆角、10pt 前景内边距和静态轻阴影,图表锚点和提示在同一宿主内处理;不显示常驻图例、坐标轴、网格或起止时间。 +ResourceCard 通过 NativeContentHost 使用固定尺寸的独立 NSHostingView,传递字体、颜色、语言及外观环境;更新沿用挂载身份,卸载清空子宿主内容。背景绘图区覆盖卡片全宽全高:CPU / GPU / 电池底边为 0、顶边为 100%,内存顶边为物理总量;速率采用独立双向投影,文字和控件叠放其上。统一 16pt 圆角、10pt 前景内边距和静态轻阴影,图表锚点和提示在同一宿主内处理;不显示常驻图例、数值坐标轴、网格或起止时间。 -StackedSeries 仅在渲染时构建累计上下边界:CPU 自下而上为系统 / 用户,内存为应用 / 联动 / 压缩,GPU 为总占用 / 空闲(相加为 100%,Renderer / Tiler 保留原始提示读数)。任一必要分量缺失或无效时不构造部分总量,原始历史不变。NativePanelCurve 按连续段在匹配的上下边界间闭合面积,保留真实断点;悬浮使用缓存累计边界定位,而提示读取原始分量。电池绘制电量,存储 / 网络绘制双速率曲线。 +StackedSeries 仅在渲染时构建累计上下边界:CPU 自下而上为系统 / 用户,内存为应用 / 联动 / 压缩,GPU 为总占用 / 空闲(相加为 100%,Renderer / Tiler 保留原始提示读数)。任一必要分量缺失或无效时不构造部分总量,原始历史不变。NativePanelCurve 按连续段在匹配的上下边界间闭合面积,保留真实断点;悬浮使用缓存累计边界定位,而提示读取原始分量。电池绘制电量。存储 / 网络通过 PanelCurveProjection.split 在自卡片顶向下 60% 位置绘制零轴,读取 / 上传向上、写入 / 下载向下,两侧各使用卡片高度 30% 的振幅并共享自动速率尺度,峰值不映射到卡片顶边。原始速率仍为正值,提示、标记与面积采用同一投影,保留缺失与真实断点。内存的已用三层包含匿名应用 / 系统进程、联动和压缩器物理内存;缓存 / Swap 口径见监控文档,不再显示重复容量进度条。 -数字、曲线和进度条直接更新,曲线不创建动画、渐变或遮罩图层,不使用背景模糊。风扇是唯一持续动效:FanRotor 使用原生 Core Animation 旋转 SF Symbol,按历史 RPM 档位映射 90 / 180 / 300 / 450°/s,切档保留相位;零 / 无效 / 缺失值、系统减弱动态效果、暂停、隐藏、遮挡、睡眠或卸载时停止。没有新增帧计时器。样式与异常状态见 [UI 设计规范](ui-design-standard.md)。 +数字、曲线和进度条直接更新,曲线不创建动画、渐变或遮罩图层,不使用背景模糊。风扇是唯一持续动效:FanRotor 将 SF Symbol 绘制到独立图像子图层,固定中心锚点和位置,使用原生 Core Animation 旋转子图层,AppKit 宿主图层保持不变,按历史 RPM 档位映射 90 / 180 / 300 / 450°/s,切档保留相位;零 / 无效 / 缺失值、系统减弱动态效果、暂停、隐藏、遮挡、睡眠或卸载时停止。没有新增帧计时器。样式与异常状态见 [UI 设计规范](ui-design-standard.md)。 设置使用 NeutralTabPicker 静态 AppKit 按钮组,保留 tabGroup / tabButton 语义、选中值与键盘导航。 -进程列表使用 view-based NSTableView,只创建可见单元格并原地更新。ProcessTableProjection 负责搜索、排序及悬停 / 选择 / 搜索期间的顺序保持。选择由完整 ProcessIdentity 同步,原生委托回调之后才写回 SwiftUI。列依次为 PID、名称、CPU、内存、CPU 功率、线程数、路径;路径末列可横向滚动,支持排序及复制。ProcessIconCache 保存 30×30 像素缩略图,最多 128 项 / 1 MiB,30 秒过期、LRU 淘汰、内存压力清空,无轮询任务。 +进程列表使用 view-based NSTableView,只创建可见单元格并原地更新。ProcessTableProjection 负责搜索、排序及悬停 / 选择 / 搜索期间的顺序保持。选择由完整 ProcessIdentity 同步,原生委托回调之后才写回 SwiftUI。只显示 PID、名称、CPU、内存、CPU 功率、线程数六列;使用 plain 样式消除额外行内缩进,由原生滚动宿主在 tile 时按可用宽度分配六列,禁用横向滚动及手动扩宽。路径保留在模型中用于搜索与右键复制。原可见口径 / 能量覆盖说明行移至进程标题提示,保留状态且不占行高。ProcessIconCache 保存 30×30 像素缩略图,最多 128 项 / 1 MiB,30 秒过期、LRU 淘汰、内存压力清空,无轮询任务。 外观、语言和采样配置写入 UserDefaults;固定、暂停、保持唤醒与进程交互不持久化。旧减弱动画偏好键忽略但不清除。AppLanguageScope 传递应用语言并刷新宿主,AppLocalization 为原生菜单取文案;编号风扇保留参数化 Text。 diff --git a/docs/dashboard-polish-plan.md b/docs/dashboard-polish-plan.md new file mode 100644 index 0000000..d948cf3 --- /dev/null +++ b/docs/dashboard-polish-plan.md @@ -0,0 +1,35 @@ +# 单页监控细节修正方案 + +## 目标与范围 + +根据本轮两张截图修正风扇转轴、速率背景尺度、内存重复进度条与进程表。工作区及暂存区开始时干净。涉及 UI/Components、UI/Charts、Features/MenuBar、相关检查与 docs;Core 指标及系统 API 不改变,不新增依赖。 + +## 方案 + +1. 风扇不再旋转 AppKit 管理的宿主 backing layer。独立图像子图层以 (0.5, 0.5) 为锚点,位置固定为图标区域中心;布局改变只更新尺寸 / 位置,沿用既有速度档位、相位和停转条件。 +2. 存储 / 网络采用双向速率曲线:自卡片顶向下 60% 处为零轴,上方读取 / 上传,下方写入 / 下载;两侧各使用卡片高度 30% 的振幅,共享同一自动速率尺度,峰值不触及卡片顶边。保留原始正速率和提示读数、采样断点及缓存几何,不将速率解释为百分比。CPU / GPU / 内存 / 电池继续原尺度。 +3. 内存检查实际采样调用链:internal − purgeable 为匿名应用 / 系统进程部分,wired 含内核和驱动等常驻内存,compressed 为压缩器实际物理占用;三者为已用内存。缓存属于可回收 / 可用部分,Swap 为磁盘占用,均不能再次叠入已用。保留三层趋势和分类 / 可用数值,移除额外容量进度条,通过提示及文档说明口径。 +4. 进程表只显示 PID、名称、CPU、内存、CPU 功率、线程六列,列宽随视口适配,关闭横向滚动;路径仍在数据模型中,支持搜索和右键复制。移除截图中的整行说明 / 能量覆盖文案,把口径与状态保留在进程标题提示中。 + +## 实施与验证 + +- [x] 实现图层中心、双向投影、内存和表格调整。 +- [x] 补充旋转中心在多角度 / 多尺寸下不漂移、双向面积 / 悬浮 / 断点、内存分类守恒、六列表格视口适配与真实复制动作检查。 +- [x] Debug 构建,运行受影响独立检查;隔离副本实测真实面板、三语 / 浅深色及相关控件,只采集本应用区域。 +- [x] 同步架构 / 设计规范 / 监控口径和测试说明;生成新 dist 包并核验,清理本轮临时产物,提交代码,不推送。 + +## 风险与边界 + +内存分组是系统统计口径,匿名系统进程不另立一项重复统计;不能保证与另一时间点活动监视器逐字节相同。窄屏六列会截断长名称和标题,完整名称 / 路径可复制。风扇中心使用实际原生图层及多个角度验证,单张静态截图不证明动画全过程;长期能耗与多屏仍需对应环境。 + +## 验证结果(2026-11-15) + +- Debug 构建通过,隔离副本使用 ENABLE_DEBUG_DYLIB=NO;未改变沙盒或权限。仅有未使用 AppIntents 的元数据提示。 +- 8 项受影响检查通过:FanRotorChecks、NativeMetricDrawingChecks、NativeProcessTableChecks、ProcessSectionChecks、MemoryChecks、ResourceCardChecks、StackedSeriesChecks、PanelLayoutChecks;161 个目录键的三语和格式参数检查通过。 +- 风扇:独立子图层在 11 / 20 / 32pt、0 / 45 / 90 / 180 / 270° 下中心不偏移,宿主变换保持恒等,档位时长、无效 / 零 / 缺失值、非活动 / 减弱动态效果和卸载停转通过。 +- 速率:实际图层面积位于各自零轴一侧;存储 / 网络上下方向、共同尺度、真实断点、悬浮位置 / 缓存及静态图层检查通过。检查发现新增零轴更新曾在禁用隐式动画事务之外,已修正并通过无动画检查。 +- 内存:实际采样分类守恒;压缩较多 / 缓存 / Swap 夹具不重复叠加;已用与可用合计物理总量。采样公式不变,核对依据与限制记录于 monitoring.md。 +- 表格:默认 uniform / inset 布局在窄屏有列被挤出,改为 plain 样式并在滚动宿主 tile 时分配视口宽度;900 / 628 / 340pt 实际窗口中六列末端位于视口内,没有横向滚动条。隐藏路径列后真实 NSMenu 复制动作仍取得完整路径,检查后恢复原剪贴板。三语 / 浅深色的生产区域保持 176pt 高且移除说明行后表格占满剩余空间。 +- 隔离实际应用深色简体面板截图与 AX 状态核对:六卡与进程同页;风扇图标位置、双向趋势、无重复内存容量条、六列无路径 / 横向滚动及说明行移到标题帮助均符合设计。只截取本应用内容,保留原安装副本。AX 右键动作只观察到行选择,未把它记为系统鼠标弹出菜单通过;复制能力由上述原生菜单动作检查验证。 +- 新 dist/dashboard-polish-v1 的普通 Release 构建、原始 / 解压包签名、Hardened Runtime、沙盒 / 网络权限及压缩包内容通过;版本 1.2 (14),arm64,macOS 27.0 起,ad-hoc 未公证。SHA-256 单独复核。 +- 清理本轮隔离应用、容器、截图、脚本、日志、检查崩溃报告及临时构建。真实鼠标悬浮 / 右键菜单手感、多屏及长期能耗仍未完成本轮实测。 diff --git a/docs/monitoring.md b/docs/monitoring.md index 3b3103d..6fcd92d 100644 --- a/docs/monitoring.md +++ b/docs/monitoring.md @@ -4,7 +4,7 @@ 趋势图跳过无值节点,按真实时间连接前后有效点;有效 0 仍绘制,暂停 / 休眠等显式断点及真实采样空档仍断线。连接只影响曲线外观:缺失时刻悬浮读数为 `--`,原历史不补值。 -趋势覆盖整张卡片,底边为 0、顶边为 100% / 物理内存总量 / 自动速率上限,文字和控件叠放其上。CPU 自下而上堆叠系统态 / 用户态,内存堆叠应用 / 联动 / 压缩,GPU 堆叠占用 / 空闲(相加为 100%);Renderer / Tiler 可能重叠,仅保留原始历史提示。电池显示电量,功率提示独立标 W;存储与网络显示读写 / 收发双曲线。不显示常驻坐标轴、网格或图例。静态淡色面积在匹配的累计上下边界间按真实连续段闭合,不跨暂停或长空档;单点只显示真实点,必要分量缺失不构造部分总量。悬浮不会替换上方实时主数值。 +趋势覆盖整张卡片,CPU / GPU / 电池底边为 0、顶边为 100%,内存顶边为物理总量,文字和控件叠放其上。CPU 自下而上堆叠系统态 / 用户态,内存堆叠应用 / 联动 / 压缩,GPU 堆叠占用 / 空闲(相加为 100%);Renderer / Tiler 可能重叠,仅保留原始历史提示。电池显示电量,功率提示独立标 W;存储 / 网络以自顶向下 60% 高度为零轴,读取 / 上传向上、写入 / 下载向下;两侧同样使用 30% 卡片高度振幅及共享自动速率尺度,原始值和提示均保持正速率。不显示常驻数值坐标轴、网格或图例。静态淡色面积在匹配的累计上下边界间按真实连续段闭合,不跨暂停或长空档;单点只显示真实点,必要分量缺失不构造部分总量。悬浮不会替换上方实时主数值。 ## 数据来源 @@ -29,6 +29,12 @@ 内存容量使用 GiB / MiB 等二进制单位,存储容量与常规字节 / 速率采用十进制格式;进程 footprint 表列按活动监视器习惯,以 1,048,576 字节折算并标为 MB。 +## 内存堆叠核对 + +当前实现保持应用 + 联动 + 压缩 = 已用,已用 + 可用 = 物理总量。应用分类来自 internal − purgeable,包含应用与系统进程的匿名内存,并非仅用户打开的 GUI 应用;联动包含内核 / 驱动等常驻内存;压缩使用 compressor_page_count 的实际物理页,而非压缩前大小。[Apple XNU 字段定义](https://github.com/apple-oss-distributions/xnu/blob/main/osfmk/mach/vm_statistics.h)及[统计实现](https://github.com/apple-oss-distributions/xnu/blob/main/osfmk/kern/host.c)可对照采样字段。 + +可回收文件缓存包含在可用部分,Swap 是磁盘交换空间,不另加到物理内存已用堆叠。Apple 活动监视器同样区分 App / Wired / Compressed、Cached Files 与 Swap Used,见[官方口径说明](https://support.apple.com/en-uz/guide/activity-monitor/actmntr1004/10.14/mac/15.0)。背景三层已承担分布表达,因此移除额外容量进度条;前景仍保留分类、可用量、压力及其提示。不同时间点和系统版本不保证与活动监视器逐字节相同。 + ## 需要明确区分的指标 - GPU Renderer / Tiler 是活动阶段指标,可能重叠,不能相加成为总占用。GPU 核心数不代表逐核计数;目前没有独立逐核 GPU 占用。 @@ -65,7 +71,7 @@ AppleSMC 和 GPU 驱动字段不是稳定公开的跨机型指标接口,缺失 该口径是系统归属的 CPU 能量,参考 [Apple XNU task.c](https://github.com/apple-oss-distributions/xnu/blob/main/osfmk/kern/task.c) 和 [recount.c](https://github.com/apple-oss-distributions/xnu/blob/main/osfmk/kern/recount.c);开源主线不保证与目标系统二进制完全一致。它不含完整 GPU / 屏幕 / 网络 / 整机功耗,不聚合应用子进程,不等于活动监视器 Energy Impact。进程表以 W/mW 显示 CPU 平均功率,列头可切换升降序;缺失值显示 -- 并始终排末。悬浮功率单元格可查看实际统计窗口。 -按全部可测候选的有效能量差分排名。权限受限、进程退出和截止会降低覆盖率;进程区域显示已形成差分数 / 枚举总数,首帧等待,失败或不支持明确显示状态。零增量只有连续两帧有效时才代表 0 W。身份变化、计数回退、无效时间和超过允许窗口均不形成排名。超大进程集合在总截止下可能只覆盖部分批次,尚未验证极端规模下的公平轮转。 +按全部可测候选的有效能量差分排名。权限受限、进程退出和截止会降低覆盖率;进程标题提示显示已形成差分数 / 枚举总数,首帧等待,失败或不支持明确显示状态。零增量只有连续两帧有效时才代表 0 W。身份变化、计数回退、无效时间和超过允许窗口均不形成排名。超大进程集合在总截止下可能只覆盖部分批次,尚未验证极端规模下的公平轮转。 进程 CPU 的 `pti_total_user` / `pti_total_system` 是 task absolute CPU 时间:累计值先做整数差分,经本机 `mach_timebase_info` 转为纳秒,再除以单调时钟间隔;单逻辑核满载为 100%,多线程可超过 100%。不按整机核心数再平均。真实 CPU 能量采用独立 nJ 计数差分。 diff --git a/docs/testing.md b/docs/testing.md index 5c9f3d0..d6f2028 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -30,7 +30,7 @@ python3 tools/check.py --list | BackgroundTrendChecks、PanelCurveChecks | 真实时间域、周期切换、短暂隐藏连续性、60 点有界历史、缺失与非有限点、有效 0、显式停采及真实空档 | | UnifiedPanelChecks、StageCChecks | 本机采样边界、网络汇总与接口历史、电池估时及系统报告解析 | | MachPortChecks | CPU / 内存各 1,000 轮后 host 发送权引用无增长 | -| MemoryChecks、MemoryHeaderChecks | 分类守恒、二进制容量、压力 / 缓存 / Swap 标题及三语缺失 / 零值 | +| MemoryChecks、MemoryHeaderChecks | 含压缩 / 缓存 / Swap 的分类守恒、二进制容量、压力 / 缓存 / Swap 标题及三语缺失 / 零值 | | GPUStatisticsChecks、CPUTemperatureChecks、FanChecks、DiskHealthChecks | 当前 GPU 利用率与历史、温度范围与解码、风扇零值 / 无效值、历史速度边界与切档相位、SMART 边界与多物理存储拒绝合并 | | SensorScheduleChecks、BoundedProcessChecks | 各能力独立退避;真实受控子进程输出上限、超时、取消、异常退出与回收 | | ProcessEnergyChecks、ProcessEnergyReaderChecks、ProcessCPULiveChecks | UInt64 能量差分、身份 / UID / 缺失 / 回退 / 时间边界、受控本机能量增长和 Mach 时基 CPU 差分 | @@ -39,12 +39,12 @@ python3 tools/check.py --list | NetworkAddressChecks、ProcessIconCacheChecks | 沙盒下地址格式 / 速率;图标位图、尺寸、共享、过期、LRU 与严格预算 | | AppearancePreferencesChecks、LocalizationChecks、PresentationChecks | 外观与偏好隔离、语言持久化、编译资源、窗口显式 / 系统外观切换 | | CodeIdentityChecks、PanelAssetChecks、KeepAwakeChecks | 签名身份拒绝边界、编译颜色及对比度、真实 IOPM 断言开关与释放 | -| NativeMetricDrawingChecks(--gui) | 实际曲线 / 堆叠色带面积像素和累计边界定位、单点无虚构填充、隐藏序列隔离、缺失点接续与真实断点、悬浮缓存、无动画 / 渐变 / 遮罩、卸载 | -| FanRotorChecks(--gui) | 原生旋转动画时长、无效 / 零 / 缺失、非活动 / 减弱动态效果及卸载停转 | -| ResourceCardChecks(--gui) | 生产卡片与曲线真实挂载,190 / 205⅓ / 400pt、浅深色及三语下的全宽全高图区、前景覆盖、实际内存容量条像素与卸载;比较 AppKit 实际尺寸,允许分数点窗口尺寸取整 | -| ProcessSectionChecks(--gui) | 生产进程区域固定 176pt,三语 / 浅深色及 340 / 628pt 下说明换行后表格仍占满剩余高度 | +| NativeMetricDrawingChecks(--gui) | 实际曲线 / 堆叠色带、双向速率面积和零轴、方向 / 悬浮 / 断点及累计边界定位、单点无虚构填充、隐藏序列隔离、缺失点接续与真实断点、悬浮缓存、无动画 / 渐变 / 遮罩、卸载 | +| FanRotorChecks(--gui) | 独立图层多角度 / 多尺寸旋转中心不漂移,原生旋转动画时长、无效 / 零 / 缺失、非活动 / 减弱动态效果及卸载停转 | +| ResourceCardChecks(--gui) | 生产卡片与曲线真实挂载,190 / 205⅓ / 400pt、浅深色及三语下的全宽全高图区、前景覆盖、卸载;比较 AppKit 实际尺寸,允许分数点窗口尺寸取整 | +| ProcessSectionChecks(--gui) | 生产进程区域固定 176pt,三语 / 浅深色及 340 / 628pt 下移除说明行后表格占满剩余高度且无横向滚动条 | | NativeContentHostChecks(--gui) | 数字更新、父环境继承、挂载身份、有限尺寸和卸载 | -| NativeProcessTableChecks(--gui) | 原生虚拟表格、原地更新、身份选择、排序 / 列序 / 复制 / 三语列头、合成 Esc 投递 | +| NativeProcessTableChecks(--gui) | 原生虚拟表格、原地更新、身份选择、六列窄宽度适配、隐藏路径列但真实菜单复制路径、排序 / 列序 / 复制 / 三语列头、合成 Esc 投递 | | TabPickerChecks、LanguageScopeChecks、SettingsWindowChecks(--gui) | 原生页签选择与键盘、已挂载语言即时切换、设置焦点 / 最小化恢复 / Dock 生命周期 | | PanelWindowChecks(--gui) | 真实 NSPanel 居中、尺寸反馈、固定、遮挡可见性、显式关闭重开和退出复位 | | ReleaseServiceChecks(--services) | 临时 hardened sandbox 主程序调用本轮实际嵌入服务,核对同 UID footprint / 能量与传感器 | diff --git a/docs/ui-design-standard.md b/docs/ui-design-standard.md index 31e5c1e..6e210cc 100644 --- a/docs/ui-design-standard.md +++ b/docs/ui-design-standard.md @@ -1,4 +1,4 @@ -# Kymo 界面设计规范 v1.2 +# Kymo 界面设计规范 v1.3 2026-11-15 根据用户确认的[背景趋势设计稿](designs/card-background-trends-v1/README.md)制定,并按后续反馈将首版卡片宽、高缩至 2/3,恢复图稿中的紧凑左对齐排布;本轮将图表扩展到整卡、采用分量堆叠,并合并进程为第三行。本文为实现与验收标准,效果图中的示例数据、品牌重绘与核心格子不作为数据或素材依据。 @@ -19,7 +19,7 @@ | 卡片 | 基础高 176,圆角 16,前景内边距 10 | | 动态高度 | CPU 核型横向分组,逐核竖柱一行基础预算,超出每行增加 34;GPU 超过一行风扇后每行增加 14;所有行采用最大结构预算,不裁掉硬件数据 | | 标题 / 主值区域 | 标题行 14,主值行 34,区域间距 4 | -| 背景趋势 | 覆盖全卡宽高,底边 0、顶边 100% / 物理内存总量 / 速率上限;文字与控件覆盖其上,按卡片圆角裁切 | +| 背景趋势 | 覆盖全卡宽高,CPU / GPU / 电池底边 0、顶边 100%;内存顶边为物理总量;速率采用 60% 高度零轴的上下双向投影;文字与控件覆盖其上,按卡片圆角裁切 | | 逐核格子 | 每核四个 6×6 方块,间距 2,柱高 30;底部先填充,最后一格部分填充保留真实比例;核型短标签在柱上方 | | 顶栏 / 底栏 | 32 / 26;操作可键盘访问 | @@ -35,7 +35,7 @@ ## 曲线与悬浮 - 移除常驻图例、坐标轴、网格、起止时间与独立图框。背景曲线线宽 1.4,填充为同色静态实色透明度:浅色 12%、深色 16%;不使用渐变层、遮罩层或动画层。 -- CPU 自下而上堆叠系统态 / 用户态;内存堆叠应用 / 联动 / 压缩,顶边为物理总量、空余为可用空间;GPU 堆叠占用 / 空闲至 100%,Renderer / Tiler 仅保留原始提示读数,不叠加为总占用。电池背景显示电量,功率在悬浮中单独注明 W,不能与电量共用未解释的尺度。存储与网络显示双曲线、共用速率尺度。 +- CPU 自下而上堆叠系统态 / 用户态;内存堆叠应用 / 联动 / 压缩,顶边为物理总量、空余为可用空间;GPU 堆叠占用 / 空闲至 100%,Renderer / Tiler 仅保留原始提示读数,不叠加为总占用。电池背景显示电量,功率在悬浮中单独注明 W,不能与电量共用未解释的尺度。存储和网络采用上下双向曲线:自顶向下 60% 为零轴(细线),向上读取 / 上传、向下写入 / 下载,两侧各有卡片高度 30% 的振幅,共用自动速率尺度,峰值不触及卡片顶边。 - 百分比固定 0–100%;内存固定当前物理总量;速率保留既有自动范围及延迟缩小策略,不为视觉任意改变振幅。 - 时间使用真实采样日期;有效 0 保留,nil / 非有限数值不补值。沿用既有缺失节点接续与显式断点 / 长空档策略。堆叠缺少任一必要分量时不构造部分总量;面积在匹配上下边界之间按每个连续段分别闭合,不能填过暂停空档。 - 单点历史仅显示真实点,不绘制虚构面积。全缺失无曲线和填充。 @@ -48,16 +48,18 @@ | --- | --- | | CPU | 总占用、温度 / 高温状态、左对齐用户 / 系统;核型横向分组、每核独立方块竖柱,数值通过悬浮和辅助功能提供;禁止把核数画成亮灯计数 | | GPU | 总占用、温度;主值下一行核心数,再显示旋转风扇图标与转速或等待状态;Renderer / Tiler 保留在历史提示 | -| 内存 | 已用 / 总量 GiB、压力标签;应用 / 联动 / 压缩单行、容量条、可用量;占用率、缓存和 Swap 保留在压力提示中 | +| 内存 | 已用 / 总量 GiB、压力标签;应用 / 联动 / 压缩单行及可用量,移除重复容量条;占用率、缓存和 Swap 保留在压力提示中 | | 电池 | 电量;电源在标题右侧;功率、健康 / 循环、估时依次左对齐;保留无电池、失败和不适用状态 | | 存储 | 已用 / 总量 GB;本地卷入口在标题右侧;可用、读写、寿命 / 通电依次左对齐;保留卷弹出层与口径说明 | | 网络 | 黑白主数值与着色方向箭头;单行累计收发;标题右侧接口与路径状态;两行公网 / 本地 IP 及全文提示 / 选择 / 复制 | +进程表显示 PID / 名称 / CPU / 内存 / CPU 功率 / 线程六列,随视口适配且没有横向滚动条。路径不作为可见列,保留路径搜索与右键复制。移除整行口径 / 能量覆盖文案,标题提示保留说明与状态。 + 三语必须复用或补齐资源键;单位延续现有口径。长 IPv6、设备名和大数值可截断,但通过悬浮或复制取得完整内容。固定、暂停、保持唤醒与设置流程维持原语义。 ## 风扇动效 -仅风扇 SF Symbol 使用原生循环旋转:正值 <2000 RPM 为 90°/s,<4000 为 180°/s,<6000 为 300°/s,更高为 450°/s;这是沿用的视觉映射,不是物理 RPM。切档保持角度连续。零 / 缺失 / 无效值、暂停、隐藏 / 遮挡、睡眠、卸载及系统减弱动态效果时停转;数值、图表和进度条不增加动画。 +风扇宿主图层不旋转,SF Symbol 独立子图层以图标区域中心为固定转轴;仅图标使用原生循环旋转:正值 <2000 RPM 为 90°/s,<4000 为 180°/s,<6000 为 300°/s,更高为 450°/s;这是沿用的视觉映射,不是物理 RPM。切档保持角度连续。零 / 缺失 / 无效值、暂停、隐藏 / 遮挡、睡眠、卸载及系统减弱动态效果时停转;数值、图表和进度条不增加动画。 ## 性能与验收 diff --git a/kymo/Features/MenuBar/MemoryDetailsView.swift b/kymo/Features/MenuBar/MemoryDetailsView.swift index 61ea444..5a70de0 100644 --- a/kymo/Features/MenuBar/MemoryDetailsView.swift +++ b/kymo/Features/MenuBar/MemoryDetailsView.swift @@ -2,9 +2,8 @@ import SwiftUI struct MemoryDetailsView: View { let memory: MemoryMetrics - private var values: [UInt64] { [memory.app, memory.wired, memory.compressed, memory.available] } + private var values: [UInt64] { [memory.app, memory.wired, memory.compressed] } private let labels: [LocalizedStringKey] = ["memory.appShort", "memory.wiredShort", "memory.compressedShort"] - private var colors: [Color] { [Color("MemoryApplication"), Color("MemoryWired"), Color("MemoryCompressed"), Color("MemoryAvailable")] } var body: some View { VStack(alignment: .leading, spacing: 4) { @@ -21,12 +20,12 @@ struct MemoryDetailsView: View { } .font(.system(size: 8)).foregroundStyle(.secondary) .lineLimit(1).minimumScaleFactor(0.75) - CapacityBar(values: values.map { Double($0) }, colors: colors, total: Double(memory.total), height: 4) HStack(spacing: 4) { Text("memory.available").foregroundStyle(.secondary) MetricText(value: MetricFormat.memory(memory.available)) }.font(.system(size: 9)).lineLimit(1) } + .help(Text("memory.distributionHelp")) .accessibilityElement(children: .contain) .accessibilityLabel(Text("memory.distribution")) } diff --git a/kymo/Features/MenuBar/MenuPanelView+Network.swift b/kymo/Features/MenuBar/MenuPanelView+Network.swift index 5c19dde..028f0d5 100644 --- a/kymo/Features/MenuBar/MenuPanelView+Network.swift +++ b/kymo/Features/MenuBar/MenuPanelView+Network.swift @@ -11,7 +11,7 @@ extension MenuPanelView { PanelTrendChart( dates: networkDates, first: networkDownloads, second: networkUploads, color: Color("MetricMemory"), secondColor: Color("SeriesUpload"), fixedScale: nil, firstLabel: "network.download", secondLabel: "network.upload", - expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: networkIntervals, visibleSeriesCount: 2 + expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: networkIntervals, visibleSeriesCount: 2, projection: .split(upwardSeries: 1) ).id(selectedInterface) } ) { diff --git a/kymo/Features/MenuBar/MenuPanelView+ResourceCards.swift b/kymo/Features/MenuBar/MenuPanelView+ResourceCards.swift index 107235f..98e02cb 100644 --- a/kymo/Features/MenuBar/MenuPanelView+ResourceCards.swift +++ b/kymo/Features/MenuBar/MenuPanelView+ResourceCards.swift @@ -141,7 +141,7 @@ extension MenuPanelView { PanelTrendChart( dates: samples.map(\.date), first: samples.map(\.read), second: samples.map(\.write), color: Color("MetricDisk"), secondColor: Color("MetricNetwork"), fixedScale: nil, firstLabel: "disk.read", secondLabel: "disk.write", - expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: chartIntervals, visibleSeriesCount: 2 + expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: chartIntervals, visibleSeriesCount: 2, projection: .split(upwardSeries: 0) ) } ) { diff --git a/kymo/Features/MenuBar/NativeProcessTable.swift b/kymo/Features/MenuBar/NativeProcessTable.swift index 16abbf2..e28b9d9 100644 --- a/kymo/Features/MenuBar/NativeProcessTable.swift +++ b/kymo/Features/MenuBar/NativeProcessTable.swift @@ -17,20 +17,22 @@ import SwiftUI func makeCoordinator() -> Coordinator { Coordinator(self) } func makeNSView(context: Context) -> NSScrollView { - let scroll = NSScrollView() - scroll.hasVerticalScroller = true; scroll.hasHorizontalScroller = true + let scroll = FittingScrollView() + scroll.hasVerticalScroller = true; scroll.hasHorizontalScroller = false + scroll.horizontalScrollElasticity = .none scroll.autohidesScrollers = true; scroll.drawsBackground = false let table = ProcessNSTableView() - table.style = .inset; table.rowHeight = 20 + table.style = .plain; table.rowHeight = 20 table.usesAlternatingRowBackgroundColors = true; table.backgroundColor = .clear table.allowsMultipleSelection = false; table.allowsEmptySelection = true - table.columnAutoresizingStyle = .sequentialColumnAutoresizingStyle - for (key, width) in [("pid", 48.0), ("name", 140), ("cpu", 65), ("memory", 85), ("power", 90), ("threads", 65), ("path", 250)] { + table.columnAutoresizingStyle = .noColumnAutoresizing + table.intercellSpacing.width = 0 + for (key, width) in [("pid", 48.0), ("name", 140), ("cpu", 65), ("memory", 85), ("power", 90), ("threads", 65)] { let column = NSTableColumn(identifier: NSUserInterfaceItemIdentifier(key)) column.width = width - column.minWidth = key == "path" ? 150 : key == "name" ? 90 : width - column.maxWidth = key == "name" ? 180 : key == "path" ? 10_000 : width - column.resizingMask = key == "path" ? [.autoresizingMask, .userResizingMask] : .userResizingMask + column.minWidth = 0 + column.maxWidth = 10_000 + column.resizingMask = [] column.sortDescriptorPrototype = NSSortDescriptor(key: key, ascending: false) table.addTableColumn(column) } @@ -47,7 +49,32 @@ import SwiftUI context.coordinator.apply(self, to: table) } + private final class FittingScrollView: NSScrollView { + private var fitting = false + override func tile() { + super.tile() + guard !fitting, let table = documentView as? ProcessNSTableView else { return } + fitting = true; defer { fitting = false } + table.fitColumns(to: contentView.bounds.width) + } + } + final class ProcessNSTableView: NSTableView { + /// Allocate the complete viewport; AppKit's uniform resizing can leave columns clipped at narrow widths. + func fitColumns(to width: CGFloat) { + guard width.isFinite, width > 0, tableColumns.count == 6 else { return } + let minimum: [CGFloat] = [32,54,40,52,54,32] + let preferred: [CGFloat] = [48,140,65,85,90,65] + let minimumTotal = minimum.reduce(0, +) + let baseScale = min(1, width / minimumTotal) + let extraScale = max(0, width - minimumTotal) / (preferred.reduce(0, +) - minimumTotal) + for index in tableColumns.indices { + let value = minimum[index] * baseScale + (preferred[index] - minimum[index]) * extraScale + if abs(tableColumns[index].width - value) > 0.01 { tableColumns[index].width = value } + } + if abs(frame.width - width) > 0.01 { setFrameSize(CGSize(width: width, height: frame.height)) } + } + var contextMenu: ((Int) -> NSMenu?)? var cancel: (() -> Void)? override func keyDown(with event: NSEvent) { @@ -145,7 +172,6 @@ import SwiftUI switch key { case "pid": text = String(process.id.pid) case "name": text = process.name - case "path": text = process.path ?? "--" case "cpu": text = process.cpu.map { String(format: "%.1f", $0 * 100) } ?? "--" case "memory": text = process.footprintBytes.map { String(format: "%.1f MB", Double($0) / 1_048_576) } ?? "--" case "power": text = process.formattedPower @@ -228,7 +254,7 @@ import SwiftUI text.font = ["pid", "cpu", "memory", "threads", "power"].contains(key) ? .monospacedDigitSystemFont(ofSize: 11, weight: .regular) : .systemFont(ofSize: 11) text.alignment = ["cpu", "memory", "threads", "power"].contains(key) ? .right : .left text.lineBreakMode = .byTruncatingMiddle - text.textColor = key == "path" ? .secondaryLabelColor : .labelColor + text.textColor = .labelColor addSubview(text); textField = text if key == "name" || key == "threads" { let image = NSImageView(); image.imageScaling = .scaleProportionallyDown diff --git a/kymo/Features/MenuBar/ProcessTableView.swift b/kymo/Features/MenuBar/ProcessTableView.swift index f0ccf5c..2c37637 100644 --- a/kymo/Features/MenuBar/ProcessTableView.swift +++ b/kymo/Features/MenuBar/ProcessTableView.swift @@ -31,11 +31,6 @@ struct ProcessTableView: View { Spacer(minLength: 0) searchField.frame(maxWidth: 180) } - HStack(spacing: 8) { - Text("panel.processScope").lineLimit(2) - Spacer(minLength: 4) - energyStatus - }.font(.system(size: 9)).foregroundStyle(.secondary) if snapshot?.failed == true { Text("panel.processFailed") } else if snapshot == nil { Text("metric.waiting").foregroundStyle(.secondary) } NativeProcessTable(rows: rows, selection: $state.selected, sorting: $state.sortOrder, locale: locale, onExit: handleExit) @@ -72,22 +67,21 @@ struct ProcessTableView: View { private var processTitle: some View { Label("panel.processes", systemImage: "list.bullet.rectangle") .font(PanelStyle.title) + .help(Text("\(Text("panel.processScope"))\n\(energyStatus)")) } private var searchField: some View { NativeSearchField(text: $state.search, isFocused: $searchFocused, placeholder: AppLocalization.string("panel.search", locale: locale)) } - private var energyStatus: some View { - Group { - switch energy?.state { - case .unsupported: Text("energy.unsupported") - case .unavailable: Text("energy.unavailable") - case .available, .partial: - Text("energy.coverage \(energy?.measured ?? 0) \(energy?.candidates ?? 0)") - default: Text("energy.waiting") - } - }.help(Text("energy.scopeHelp")).lineLimit(1) + private var energyStatus: Text { + switch energy?.state { + case .unsupported: Text("energy.unsupported") + case .unavailable: Text("energy.unavailable") + case .available, .partial: + Text("energy.coverage \(energy?.measured ?? 0) \(energy?.candidates ?? 0)") + default: Text("energy.waiting") + } } private func rebuild(retainOrder: Bool) { diff --git a/kymo/Resources/Localizable.xcstrings b/kymo/Resources/Localizable.xcstrings index a966d48..46106d5 100644 --- a/kymo/Resources/Localizable.xcstrings +++ b/kymo/Resources/Localizable.xcstrings @@ -1,6 +1,28 @@ { "sourceLanguage" : "en", "strings" : { + "memory.distributionHelp" : { + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "App includes anonymous memory used by apps and system processes. Wired includes resident kernel and driver memory. Compressed is physical compressor memory. Reclaimable cache is included in available memory; disk Swap is not added to physical memory usage." + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "应用包含应用和系统进程使用的匿名内存;联动包含内核、驱动等常驻内存;压缩为压缩器的实际物理占用。可回收缓存计入可用空间,磁盘 Swap 不再叠加到物理内存已用量。" + } + }, + "zh-Hant": { + "stringUnit": { + "state": "translated", + "value": "應用包含應用和系統程序使用的匿名記憶體;連動包含核心、驅動等常駐記憶體;壓縮為壓縮器的實際實體佔用。可回收快取計入可用空間,磁碟 Swap 不再疊加到實體記憶體已用量。" + } + } + } + }, "gpu.idle" : { "localizations": { "en": { diff --git a/kymo/UI/Charts/NativePanelCurve.swift b/kymo/UI/Charts/NativePanelCurve.swift index b2c28e1..4b51aeb 100644 --- a/kymo/UI/Charts/NativePanelCurve.swift +++ b/kymo/UI/Charts/NativePanelCurve.swift @@ -1,6 +1,20 @@ import AppKit import SwiftUI +/// Rate plots share a zero axis and equal positive amplitudes on either side. +nonisolated enum PanelCurveProjection: Equatable { + case fullHeight + case split(upwardSeries: Int) + + func y(value: Double, scale: Double, series: Int, height: Double) -> Double { + let fraction = min(1, max(0, value / (scale.isFinite && scale > 0 ? scale : 1))) + switch self { + case .fullHeight: return height * (1 - fraction) + case .split(let upward): return height * (0.6 + (series == upward ? -0.3 : 0.3) * fraction) + } + } +} + /// Bounded static lines and per-run area paths. Hover never rebuilds geometry. struct NativePanelCurve: NSViewRepresentable { let frame: PanelCurveFrame @@ -11,6 +25,7 @@ struct NativePanelCurve: NSViewRepresentable { var visibleSeriesCount: Int? = nil var filledSeriesCount = 1 var stacked = false + var projection: PanelCurveProjection = .fullHeight func sizeThatFits(_ proposal: ProposedViewSize, nsView: PlotView, context: Context) -> CGSize? { CGSize(width: proposal.width.flatMap { $0.isFinite ? $0 : nil } ?? 10, @@ -19,7 +34,7 @@ struct NativePanelCurve: NSViewRepresentable { func makeNSView(context: Context) -> PlotView { PlotView() } func updateNSView(_ view: PlotView, context: Context) { view.configure(Input(frame: frame, colors: colors, scales: scales, maximumGap: maximumGap, - hoveredIndex: hoveredIndex, visibleSeriesCount: visibleSeriesCount, filledSeriesCount: filledSeriesCount, stacked: stacked)) + hoveredIndex: hoveredIndex, visibleSeriesCount: visibleSeriesCount, filledSeriesCount: filledSeriesCount, stacked: stacked, projection: projection)) } struct Input: Equatable { let frame: PanelCurveFrame @@ -30,11 +45,13 @@ struct NativePanelCurve: NSViewRepresentable { var visibleSeriesCount: Int? = nil var filledSeriesCount = 1 var stacked = false + var projection: PanelCurveProjection = .fullHeight } final class PlotView: NSView { private(set) var input: Input? private(set) var pathBuildCount = 0 let grid = CAShapeLayer() + let baseline = CAShapeLayer() let curves = CALayer() let hoverLine = CAShapeLayer() private var hoverDots: [CAShapeLayer] = [] @@ -52,7 +69,8 @@ struct NativePanelCurve: NSViewRepresentable { grid.fillColor = nil; grid.lineWidth = 0.5 grid.isHidden = true hoverLine.fillColor = nil; hoverLine.lineWidth = 1; hoverLine.lineDashPattern = [3, 2] - for child in [grid, curves, hoverLine] { layer?.addSublayer(child) } + baseline.fillColor = nil; baseline.lineWidth = 0.5; baseline.isHidden = true + for child in [grid, baseline, curves, hoverLine] { layer?.addSublayer(child) } setAccessibilityElement(false) } required init?(coder: NSCoder) { nil } @@ -63,6 +81,7 @@ struct NativePanelCurve: NSViewRepresentable { let frameChanged = old?.frame != value.frame input = value CATransaction.begin(); CATransaction.setDisableActions(true) + if old?.projection != value.projection { updateBaseline() } curves.isHidden = value.colors.isEmpty || value.scales.isEmpty ensureLayers(value.frame.series.count) if old?.colors != value.colors || old?.frame.series.count != value.frame.series.count @@ -70,7 +89,7 @@ struct NativePanelCurve: NSViewRepresentable { for index in seriesLayers.indices { seriesLayers[index].root.isHidden = index >= (value.visibleSeriesCount ?? value.frame.series.count) } - if frameChanged || old?.scales != value.scales || old?.maximumGap != value.maximumGap || old?.stacked != value.stacked { + if frameChanged || old?.scales != value.scales || old?.maximumGap != value.maximumGap || old?.stacked != value.stacked || old?.projection != value.projection { rebuildPaths() } updateHover() @@ -89,6 +108,7 @@ struct NativePanelCurve: NSViewRepresentable { private func updatePalette() { effectiveAppearance.performAsCurrentDrawingAppearance { palette = input?.colors.map(NSColor.init) ?? [] + baseline.strokeColor = NSColor.labelColor.withAlphaComponent(0.12).cgColor grid.strokeColor = NSColor.labelColor.withAlphaComponent(0.10).cgColor hoverLine.strokeColor = NSColor.labelColor.withAlphaComponent(0.45).cgColor guard !palette.isEmpty else { return } @@ -102,7 +122,16 @@ struct NativePanelCurve: NSViewRepresentable { } } } + private func updateBaseline() { + baseline.frame = bounds + baseline.isHidden = input?.projection == .fullHeight || input == nil + let path = CGMutablePath() + path.move(to: CGPoint(x: 0, y: bounds.height * 0.6)) + path.addLine(to: CGPoint(x: bounds.width, y: bounds.height * 0.6)) + baseline.path = path + } private func updateGrid() { + updateBaseline() grid.frame = bounds; hoverLine.frame = bounds curves.bounds = bounds; curves.position = .zero let path = CGMutablePath() @@ -138,7 +167,7 @@ struct NativePanelCurve: NSViewRepresentable { let line = CGMutablePath(), dots = CGMutablePath(), area = CGMutablePath() for run in runs { let points = run.map { CGPoint(x: bounds.width * domain.position($0.date), - y: bounds.height * (1 - min(1, max(0, $0.value / scale)))) } + y: input.projection.y(value: $0.value, scale: scale, series: index, height: bounds.height)) } guard let start = points.first else { continue } if points.count == 1 { dots.addEllipse(in: CGRect(x: start.x - 2, y: start.y - 2, width: 4, height: 4)); continue @@ -151,7 +180,7 @@ struct NativePanelCurve: NSViewRepresentable { line.addPath(segment) // Close against the matching lower boundary, never against another run or missing component. let lowerPoints = run.reversed().map { CGPoint(x: bounds.width * domain.position($0.date), - y: bounds.height * (1 - min(1, max(0, $0.lower / scale)))) } + y: input.projection.y(value: $0.lower, scale: scale, series: index, height: bounds.height)) } let fill = CGMutablePath(); fill.addPath(segment) if let lowerStart = lowerPoints.first { fill.addLine(to: lowerStart) } for (a, b) in zip(lowerPoints, lowerPoints.dropFirst()) { @@ -178,7 +207,7 @@ struct NativePanelCurve: NSViewRepresentable { let values = input.stacked && plottedBands.indices.contains(series) ? plottedBands[series].upper : input.frame.series[series] guard values.indices.contains(index), let value = values[index], value.isFinite else { continue } let scale = input.scales[input.stacked ? 0 : min(series, input.scales.count - 1)] - let y = bounds.height * (1 - min(1, max(0, value / (scale.isFinite && scale > 0 ? scale : 1)))) + let y = input.projection.y(value: value, scale: scale, series: series, height: bounds.height) hoverDots[series].path = CGPath(ellipseIn: CGRect(x: x - 2.5, y: y - 2.5, width: 5, height: 5), transform: nil) } } diff --git a/kymo/UI/Charts/PanelTrendChart.swift b/kymo/UI/Charts/PanelTrendChart.swift index 507f6dd..5a99447 100644 --- a/kymo/UI/Charts/PanelTrendChart.swift +++ b/kymo/UI/Charts/PanelTrendChart.swift @@ -32,6 +32,7 @@ struct PanelTrendChart: View { var intervals: [TimeInterval] = [] var visibleSeriesCount = 1 var stackOrder: [Int] = [] + var projection: PanelCurveProjection = .fullHeight @State private var retainedScale: Double = 1 @State private var smallSamples = 0 @State private var retainedSecondScale: Double = 1 @@ -114,7 +115,7 @@ struct PanelTrendChart: View { scales: [scale, hasSecondaryScale ? secondaryScale : scale, scale, scale], maximumGap: max(5, expectedInterval * 2), hoveredIndex: hoveredDate == nil ? nil : index, visibleSeriesCount: stackOrder.isEmpty ? visibleSeriesCount : stackOrder.count, - filledSeriesCount: stackOrder.isEmpty ? visibleSeriesCount : stackOrder.count, stacked: !stackOrder.isEmpty) + filledSeriesCount: stackOrder.isEmpty ? visibleSeriesCount : stackOrder.count, stacked: !stackOrder.isEmpty, projection: projection) .contentShape(Rectangle()) .onContinuousHover { phase in switch phase { diff --git a/kymo/UI/Components/FanSpeedIndicator.swift b/kymo/UI/Components/FanSpeedIndicator.swift index 25548b6..8956e81 100644 --- a/kymo/UI/Components/FanSpeedIndicator.swift +++ b/kymo/UI/Components/FanSpeedIndicator.swift @@ -58,7 +58,9 @@ struct FanRotor: NSViewRepresentable { } static func dismantleNSView(_ view: RotorView, coordinator: ()) { view.stop() } - final class RotorView: NSImageView { + final class RotorView: NSView { + let rotorLayer = CALayer() + private var artworkSize = CGSize.zero static let animationKey = "fan.rotation" private var rpm: Double? private var active = false @@ -68,9 +70,9 @@ struct FanRotor: NSViewRepresentable { init() { super.init(frame: .zero) wantsLayer = true - image = NSImage(systemSymbolName: "fanblades.fill", accessibilityDescription: nil) - contentTintColor = .secondaryLabelColor - imageScaling = .scaleProportionallyUpOrDown + rotorLayer.anchorPoint = CGPoint(x: 0.5, y: 0.5) + rotorLayer.contentsGravity = .resizeAspect + layer?.addSublayer(rotorLayer) setAccessibilityElement(false) } required init?(coder: NSCoder) { nil } @@ -81,10 +83,41 @@ struct FanRotor: NSViewRepresentable { } func stop() { active = false; refresh() - layer?.removeAnimation(forKey: Self.animationKey) + rotorLayer.removeAnimation(forKey: Self.animationKey) } override func viewDidMoveToWindow() { super.viewDidMoveToWindow(); refresh() } + override func layout() { + super.layout() + CATransaction.begin(); CATransaction.setDisableActions(true) + rotorLayer.bounds = CGRect(origin: .zero, size: bounds.size) + rotorLayer.position = CGPoint(x: bounds.midX, y: bounds.midY) + if artworkSize != bounds.size { updateArtwork() } + CATransaction.commit() + } + override func viewDidChangeEffectiveAppearance() { + super.viewDidChangeEffectiveAppearance(); updateArtwork() + } + override func viewDidChangeBackingProperties() { + super.viewDidChangeBackingProperties(); updateArtwork() + } + private func updateArtwork() { + artworkSize = bounds.size + guard bounds.width > 0, bounds.height > 0 else { return } + effectiveAppearance.performAsCurrentDrawingAppearance { + let symbol = NSImage(systemSymbolName: "fanblades.fill", accessibilityDescription: nil) + let artwork = NSImage(size: bounds.size, flipped: false) { rect in + symbol?.draw(in: rect) + NSColor.secondaryLabelColor.setFill(); rect.fill(using: .sourceIn) + return true + } + CATransaction.begin(); CATransaction.setDisableActions(true) + rotorLayer.contentsScale = window?.backingScaleFactor ?? 2 + rotorLayer.contents = artwork.cgImage(forProposedRect: nil, context: nil, hints: nil) + CATransaction.commit() + } + } + private func refresh() { let readable = active && window != nil ? rpm : nil let speed = FanRotation.speed(rpm: readable, reducedMotion: reducedMotion) @@ -92,15 +125,15 @@ struct FanRotor: NSViewRepresentable { rotation.update(rpm: readable, reducedMotion: reducedMotion, at: CACurrentMediaTime()) let radians = rotation.phase * .pi / 180 CATransaction.begin(); CATransaction.setDisableActions(true) - layer?.removeAnimation(forKey: Self.animationKey) - layer?.transform = CATransform3DMakeRotation(radians, 0, 0, 1) + rotorLayer.removeAnimation(forKey: Self.animationKey) + rotorLayer.transform = CATransform3DMakeRotation(radians, 0, 0, 1) if speed > 0 { let animation = CABasicAnimation(keyPath: "transform.rotation.z") animation.fromValue = radians; animation.toValue = radians + .pi * 2 animation.duration = 360 / speed animation.repeatCount = .infinity animation.timingFunction = CAMediaTimingFunction(name: .linear) - layer?.add(animation, forKey: Self.animationKey) + rotorLayer.add(animation, forKey: Self.animationKey) } CATransaction.commit() } diff --git a/kymoTests/FanRotorChecks.swift b/kymoTests/FanRotorChecks.swift index 4fa663d..c72c15d 100644 --- a/kymoTests/FanRotorChecks.swift +++ b/kymoTests/FanRotorChecks.swift @@ -10,25 +10,40 @@ import SwiftUI let rotor = FanRotor.RotorView(); rotor.frame = NSRect(x: 4, y: 4, width: 20, height: 20) window.contentView!.addSubview(rotor); window.orderFrontRegardless() try? await Task.sleep(for: .milliseconds(100)) + for size: CGFloat in [11,20,32] { + rotor.setFrameSize(NSSize(width: size, height: size)); rotor.layoutSubtreeIfNeeded() + precondition(rotor.rotorLayer.anchorPoint == CGPoint(x: 0.5, y: 0.5)) + precondition(rotor.rotorLayer.contents != nil) + precondition(CATransform3DIsIdentity(rotor.layer!.transform), "AppKit's host layer must never rotate") + CATransaction.begin(); CATransaction.setDisableActions(true) + for degrees in [0.0,45,90,180,270] { + rotor.rotorLayer.transform = CATransform3DMakeRotation(degrees * .pi / 180, 0, 0, 1) + let center = rotor.rotorLayer.convert(CGPoint(x: size / 2, y: size / 2), to: rotor.layer!) + precondition(abs(center.x - rotor.bounds.midX) < 1e-9 && abs(center.y - rotor.bounds.midY) < 1e-9, + "The icon center must not orbit at any angle or size") + } + rotor.rotorLayer.transform = CATransform3DIdentity + CATransaction.commit() + } for (rpm, duration) in [(1000.0,4.0),(2000,2),(4000,1.2),(6000,0.8)] { rotor.configure(rpm: rpm, active: true, reducedMotion: false) - precondition(abs(rotor.layer!.animation(forKey: FanRotor.RotorView.animationKey)!.duration - duration) < 1e-9) + precondition(abs(rotor.rotorLayer.animation(forKey: FanRotor.RotorView.animationKey)!.duration - duration) < 1e-9) } for rpm: Double? in [0,nil,.nan,-1] { rotor.configure(rpm: rpm, active: true, reducedMotion: false) - precondition(rotor.layer!.animationKeys()?.isEmpty != false) + precondition(rotor.rotorLayer.animationKeys()?.isEmpty != false) } rotor.configure(rpm: 3000, active: true, reducedMotion: false) - precondition(rotor.layer!.animationKeys()?.isEmpty == false) + precondition(rotor.rotorLayer.animationKeys()?.isEmpty == false) rotor.configure(rpm: 3000, active: false, reducedMotion: false) - precondition(rotor.layer!.animationKeys()?.isEmpty != false) + precondition(rotor.rotorLayer.animationKeys()?.isEmpty != false) rotor.configure(rpm: 3000, active: true, reducedMotion: true) - precondition(rotor.layer!.animationKeys()?.isEmpty != false) + precondition(rotor.rotorLayer.animationKeys()?.isEmpty != false) rotor.configure(rpm: 3000, active: true, reducedMotion: false) rotor.removeFromSuperview() - precondition(rotor.layer!.animationKeys()?.isEmpty != false, "Detached fans must stop rotating") + precondition(rotor.rotorLayer.animationKeys()?.isEmpty != false, "Detached fans must stop rotating") window.orderOut(nil); window.close() - print("PASS: native rotor speed tiers, nil/zero/invalid readings, inactive/reduced motion and detach stop") + print("PASS: centered child-layer rotation at multiple angles/sizes, native rotor speed tiers, nil/zero/invalid readings, inactive/reduced motion and detach stop") NSApp.terminate(nil) } NSApp.run() diff --git a/kymoTests/MemoryChecks.swift b/kymoTests/MemoryChecks.swift index 00de641..25fea9c 100644 --- a/kymoTests/MemoryChecks.swift +++ b/kymoTests/MemoryChecks.swift @@ -4,6 +4,15 @@ import Foundation precondition(MetricFormat.memory(51_539_607_552) == "48.0 GiB") precondition(MetricFormat.memory(0) == "0 B") precondition(MetricFormat.memory(nil) == "--") + for m in [ + MemoryMetrics(total: 48 << 30, used: 26 << 30, wired: 3 << 30, compressed: 1 << 30, swapUsed: 8 << 30, pressure: 1, cached: 17 << 30), + MemoryMetrics(total: 32 << 30, used: 20 << 30, wired: 2 << 30, compressed: 13 << 30, swapUsed: 4 << 30, pressure: 2, cached: 8 << 30), + MemoryMetrics(total: 16 << 30, used: 0, wired: 0, compressed: 0, swapUsed: 0, pressure: 1, cached: 12 << 30) + ] { + precondition(m.app + m.wired + m.compressed == m.used) + precondition(m.app + m.wired + m.compressed + m.available == m.total) + precondition(m.available == m.total - m.used, "Reclaimable cache and disk swap must not be added again") + } guard let m = MemoryMonitor.sample() else { fatalError("No sample") } precondition(m.app + m.wired + m.compressed + m.available == m.total) var snapshot = MetricsSnapshot() diff --git a/kymoTests/NativeMetricDrawingChecks.swift b/kymoTests/NativeMetricDrawingChecks.swift index 5d35865..ed5014c 100644 --- a/kymoTests/NativeMetricDrawingChecks.swift +++ b/kymoTests/NativeMetricDrawingChecks.swift @@ -129,10 +129,41 @@ import QuartzCore plot.configure(stack) precondition(redPixels(bitmap(plot), from: 0.4, to: 0.6) == 0, "Every stack band must respect the same real sampling break") + // Rate panels use a common zero axis, not a percent scale at the card top. + var rates = NativePanelCurve.Input(frame: .init(dates: dates, + series: [Array(repeating: 0.8, count: 4), Array(repeating: 0.4, count: 4)], + intervals: [2,2,2,2], boundaryDates: []), colors: [.red,.blue], scales: [1], maximumGap: 5, + filledSeriesCount: 2, projection: .split(upwardSeries: 0)) + plot.configure(rates) + @MainActor func areaBox(_ index: Int) -> CGRect { + (plot.curves.sublayers![index].sublayers![0] as! CAShapeLayer).path!.boundingBoxOfPath + } + precondition(abs(areaBox(0).minY - 21.6) < 1e-9 && abs(areaBox(0).maxY - 36) < 1e-9) + precondition(abs(areaBox(1).minY - 36) < 1e-9 && abs(areaBox(1).maxY - 43.2) < 1e-9) + precondition(!plot.baseline.isHidden && abs(plot.baseline.path!.boundingBoxOfPath.midY - 36) < 1e-9) + precondition(redPixels(bitmap(plot)) > 10) + let rateBuilds = plot.pathBuildCount + rates.hoveredIndex = 1; plot.configure(rates) + precondition(abs((plot.layer!.sublayers!.last as! CAShapeLayer).path!.boundingBoxOfPath.midY - 43.2) < 1e-9) + precondition(plot.pathBuildCount == rateBuilds) + rates.projection = .split(upwardSeries: 1); plot.configure(rates) + precondition(abs(areaBox(0).maxY - 50.4) < 1e-9 && abs(areaBox(1).minY - 28.8) < 1e-9, + "Network download must go down and upload up without negating raw rates") + precondition(plot.pathBuildCount == rateBuilds + 1) + rates = .init(frame: .init(dates: dates, + series: [Array(repeating: 0.8, count: 4), Array(repeating: 0.4, count: 4)], + intervals: [2,2,2,2], boundaryDates: [dates[2]]), colors: [.red,.blue], scales: [1], maximumGap: 5, + filledSeriesCount: 2, projection: .split(upwardSeries: 0)) + plot.configure(rates) + precondition(redPixels(bitmap(plot), from: 0.4, to: 0.6) == 0) + for series in 0...1 { + precondition(PanelCurveProjection.split(upwardSeries: 0).y(value: 0, scale: 10, series: series, height: 176) == 105.6) + } + precondition(abs(PanelCurveProjection.split(upwardSeries: 0).y(value: 10, scale: 10, series: 0, height: 176) - 52.8) < 1e-9) assertStatic(plot.layer!) plot.removeFromSuperview() window.orderOut(nil); window.close() - print("PASS: stacked component pixels and cumulative hover, static background lines/area pixels, no single-point fill, hidden-series isolation, immediate stable updates, no animation/material/gradient layers, real gaps, hover cache, palette growth, appearance, full history and unmount") + print("PASS: bidirectional rate areas/zero axis/direction/hover/gaps, stacked component pixels and cumulative hover, static background lines/area pixels, no single-point fill, hidden-series isolation, immediate stable updates, no animation/material/gradient layers, real gaps, hover cache, palette growth, appearance, full history and unmount") fflush(stdout); NSApp.terminate(nil) } NSApp.run() diff --git a/kymoTests/NativeProcessTableChecks.swift b/kymoTests/NativeProcessTableChecks.swift index 2cbe455..525d699 100644 --- a/kymoTests/NativeProcessTableChecks.swift +++ b/kymoTests/NativeProcessTableChecks.swift @@ -62,18 +62,32 @@ private struct Host: View { let coordinator = table.delegate as! NativeProcessTable.Coordinator let probe = DelegateProbe(state, coordinator) table.delegate = probe - precondition(table.numberOfRows == 500 && table.tableColumns.count == 7) - precondition(table.tableColumns.map(\.identifier.rawValue) == ["pid", "name", "cpu", "memory", "power", "threads", "path"], - "The path column must follow all process metrics") + precondition(table.numberOfRows == 500 && table.tableColumns.count == 6) + precondition(table.tableColumns.map(\.identifier.rawValue) == ["pid", "name", "cpu", "memory", "power", "threads"], + "Only the six metric columns must be visible") precondition(table.frame.width >= table.enclosingScrollView!.contentSize.width - 1, "Native table must fill its viewport") precondition(coordinator.createdCells > 0 && coordinator.createdCells < 200, "Rows must be virtualized") - let pathCell = table.view(atColumn: table.tableColumns.count - 1, row: 0, makeIfNecessary: true) as! NSTableCellView - precondition(pathCell.textField?.stringValue == "/test/worker-0") - let copyPath = coordinator.menu(row: 0)!.items[2] + let copyMenu = coordinator.menu(row: 0)!, copyPath = copyMenu.items[2] precondition(copyPath.isEnabled && copyPath.representedObject as? String == "/test/worker-0") - for ascending in [false, true] { - table.sortDescriptors = [NSSortDescriptor(key: "path", ascending: ascending)] - await until { state.sorting == [ProcessSort(key: .path, order: ascending ? .forward : .reverse)] } + let savedPasteboard = NSPasteboard.general.pasteboardItems?.map { item in + item.types.compactMap { type in item.data(forType: type).map { (type, $0) } } + } ?? [] + copyMenu.performActionForItem(at: 2) + precondition(NSPasteboard.general.string(forType: .string) == "/test/worker-0", + "Hiding the path column must preserve the real Copy Path action") + NSPasteboard.general.clearContents() + let restored = savedPasteboard.map { values in + let item = NSPasteboardItem(); for (type, data) in values { item.setData(data, forType: type) }; return item + } + NSPasteboard.general.writeObjects(restored) + for width: CGFloat in [900,628,340] { + window.setContentSize(CGSize(width: width, height: 260)) + try? await Task.sleep(for: .milliseconds(100)); host.layoutSubtreeIfNeeded() + precondition(abs(host.bounds.width - width) < 1) + let scroll = table.enclosingScrollView! + precondition(!scroll.hasHorizontalScroller) + precondition(table.rect(ofColumn: 5).maxX <= scroll.contentView.bounds.width + 1, + "All six columns must fit the viewport without horizontal scrolling: \(width), \(table.rect(ofColumn: 5)), \(scroll.contentView.bounds)") } let memoryColumn = table.tableColumns.firstIndex { $0.identifier.rawValue == "memory" }! let memoryCell = table.view(atColumn: memoryColumn, row: 0, makeIfNecessary: true) as! NSTableCellView @@ -124,7 +138,7 @@ private struct Host: View { window.sendEvent(escape) await until { state.exits == 1 } window.orderOut(nil); window.close() - print("PASS: real native table virtualization/reuse, deferred delegate writes, identity selection, sorting, copy menu, missing paths, removal, locale and in-window Esc event routing") + print("PASS: six columns fit narrow/regular viewports, real hidden-path copy, native table virtualization/reuse, deferred delegate writes, identity selection, sorting, copy menu, missing paths, removal, locale and in-window Esc event routing") fflush(stdout); NSApp.terminate(nil) } NSApp.run() diff --git a/kymoTests/ProcessSectionChecks.swift b/kymoTests/ProcessSectionChecks.swift index b7575b4..4f27480 100644 --- a/kymoTests/ProcessSectionChecks.swift +++ b/kymoTests/ProcessSectionChecks.swift @@ -1,7 +1,7 @@ import AppKit import SwiftUI -/// Verify the production section fills its assigned row even when the scope note wraps. +/// Verify the production section fills its assigned row after removing the scope row. @main struct ProcessSectionChecks { @MainActor static func main() { _ = NSApplication.shared; NSApp.setActivationPolicy(.accessory) @@ -26,16 +26,17 @@ import SwiftUI try? await Task.sleep(for: .milliseconds(100)); host.layoutSubtreeIfNeeded() let scrolls = descendants(host).compactMap { $0 as? NSScrollView }.filter { $0.documentView is NSTableView } precondition(scrolls.count == 1) + precondition(!scrolls[0].hasHorizontalScroller) let scroll = scrolls[0], rect = scroll.convert(scroll.bounds, to: host) let topRect = host.isFlipped ? rect : CGRect(x: rect.minX, y: host.bounds.height - rect.maxY, width: rect.width, height: rect.height) - precondition(abs(topRect.maxY - 166) < 1 && topRect.height > 75, + precondition(abs(topRect.maxY - 166) < 1 && topRect.height > 110, "The native table must fill the equal-height row down to its 10pt inset: \(language), \(width), \(topRect)") precondition(abs(topRect.minX - 10) < 1 && abs(topRect.maxX - (width - 10)) < 1) } } } host.rootView = AnyView(EmptyView()); window.orderOut(nil); window.close() - print("PASS: production process section at 176pt, wrapped scope notes, full remaining table height, two widths, three languages and light/dark") + print("PASS: production process section at 176pt, no scope row or horizontal scrollbar, full remaining table height, two widths, three languages and light/dark") NSApp.terminate(nil) } NSApp.run() diff --git a/kymoTests/ResourceCardChecks.swift b/kymoTests/ResourceCardChecks.swift index ee3c6f3..6381d1f 100644 --- a/kymoTests/ResourceCardChecks.swift +++ b/kymoTests/ResourceCardChecks.swift @@ -39,32 +39,11 @@ import SwiftUI } } } - // Render the production memory distribution: real UInt64 capacities must form visible segments. - window.appearance = NSAppearance(named: .aqua) - let memory = MemoryMetrics(total: 48 << 30, used: 26 << 30, wired: 3 << 30, - compressed: 1 << 30, swapUsed: 0, pressure: 1) - host.rootView = AnyView(MemoryDetailsView(memory: memory) - .frame(width: 185, height: 44, alignment: .topLeading) - .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading) - .environment(\.colorScheme, .light)) - try? await Task.sleep(for: .milliseconds(120)) - host.layoutSubtreeIfNeeded() - let bitmap = host.bitmapImageRepForCachingDisplay(in: host.bounds)! - host.cacheDisplay(in: host.bounds, to: bitmap) - var colored = 0 - for y in 0.. 0.2 && c.alphaComponent > 0.2 { colored += 1 } - } - } - precondition(colored > 200, "Memory classification capacities must produce a visible proportion bar") host.rootView = AnyView(EmptyView()) try? await Task.sleep(for: .milliseconds(100)) precondition(descendants(host).allSatisfy { !($0 is NativePanelCurve.PlotView) }) window.orderOut(nil); window.contentView = nil; window.close() - print("PASS: production card geometry at 190/205⅓/400pt, light/dark, three languages, full-height chart overlay, memory distribution pixels and unmount") + print("PASS: production card geometry at 190/205⅓/400pt, light/dark, three languages, full-height chart overlay, unmount") NSApp.terminate(nil) } NSApp.run()