From 8d3891966a7d9672765ea9cced819496669f3af9 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, 8 Nov 2026 18:47:01 +0800 Subject: [PATCH] =?UTF-8?q?feat(menubar):=20=E5=AE=9E=E7=8E=B0=E7=B4=A7?= =?UTF-8?q?=E5=87=91=E7=8B=AC=E7=AB=8B=E5=8F=8C=E5=88=97=E4=B8=8E=E6=8C=89?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E5=AE=9A=E9=AB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 + README.md | 2 +- docs/README.md | 2 +- docs/architecture.md | 6 +- docs/compact-panel-refinement-plan.md | 48 ++++++++++++-- docs/free-test-distribution.md | 6 +- docs/testing.md | 4 +- kymo.xcodeproj/project.pbxproj | 4 +- kymo/App/kymoApp.swift | 2 + kymo/Features/MenuBar/CPUCoreGrid.swift | 11 ++-- kymo/Features/MenuBar/MemoryDetailsView.swift | 4 +- .../MenuBar/MenuPanelController.swift | 16 ++++- .../MenuBar/MenuPanelView+Network.swift | 30 ++++----- .../MenuBar/MenuPanelView+ResourceCards.swift | 19 ++++-- kymo/Features/MenuBar/MenuPanelView.swift | 60 ++++++++++-------- kymo/Features/MenuBar/PanelLayout.swift | 63 +++++++++++++------ .../MenuBar/PanelWindowObserver.swift | 2 +- .../Features/MenuBar/StorageDetailsView.swift | 38 ++++++----- kymo/UI/Components/PanelStyle.swift | 4 +- kymoTests/CPUCoreGridChecks.swift | 10 ++- kymoTests/PanelLayoutChecks.swift | 43 ++++++++----- kymoTests/PanelWindowChecks.swift | 11 ++++ 22 files changed, 259 insertions(+), 128 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7c57d0..a07d6f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ ### 界面与性能 +- 1.1(10):概览改为固定顺序的独立双列,卡片按内容预算定高;常规窗口由 640×800 缩至 640×706pt,顶部 Tab 与底部刷新间隔保留原位。趋势图压至 48pt,收紧核心 / 风扇 / 内存 / 存储 / 网络信息;高核心数增加可读行数,较矮屏幕继续滚动。 + - 1.1(9):640pt 面板恢复顶部单行 Tab,刷新间隔移至底部右侧;同步调整工具栏高度预算,让常规六卡概览完整显示。 - 1.1(8):最大宽度由 960pt 缩至 640pt 并保留两列;监控与设置共享原生胶囊 Tab,窄卡片省略重复图例值、简写外接电源时间并为截断字段提供完整提示。卡片高度方案另列,当前行对齐与 800pt 高度上限保留。 diff --git a/README.md b/README.md index c126da3..e92dd37 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Kymo 是 macOS 菜单栏资源监控工具。菜单栏常驻品牌图标,点 - 网络:接口切换、收发速率与累计字节、路径状态、本地和公网 IP 及复制。 - 进程:PID、名称、路径、CPU、内存 footprint、CPU 平均功率和线程数;支持搜索、列排序及复制,功率缺失始终排末。 -面板支持固定显示、保持唤醒、暂停 / 恢复采样。概览采用紧凑两列,小屏可滚动,极窄屏退为单列;进程页独占内容区。概览停止进程 / footprint / 功率读取,进程页卸载资源图表并停用概览慢读取与公网任务,基础趋势跨页连续。保留彩色卡片,数字、曲线和进度条随采样直接更新,不播放应用自定义动画或背景模糊特效;后台记录独立控制。面板刷新默认 2 秒;默认隐藏停止采样,可显式开启后台趋势并配置间隔(新配置 30 秒)。设置窗口提供系统 / 浅色 / 深色外观、简体中文 / 繁體中文 / English 和关于信息。 +面板支持固定显示、保持唤醒、暂停 / 恢复采样。概览采用按内容定高的独立双列,常规 640×706pt,小屏可滚动,极窄屏退为单列;进程页独占内容区。概览停止进程 / footprint / 功率读取,进程页卸载资源图表并停用概览慢读取与公网任务,基础趋势跨页连续。保留彩色卡片,数字、曲线和进度条随采样直接更新,不播放应用自定义动画或背景模糊特效;后台记录独立控制。面板刷新默认 2 秒;默认隐藏停止采样,可显式开启后台趋势并配置间隔(新配置 30 秒)。设置窗口提供系统 / 浅色 / 深色外观、简体中文 / 繁體中文 / English 和关于信息。 部分硬件指标依赖机型、驱动与权限,缺失值显示为 `--` 或对应状态。GPU 不提供逐核占用;耗电进程显示系统归属的 CPU 能量区间平均功率,注明可读覆盖范围,不代表完整应用总耗电。指标口径和限制见[监控指标](docs/monitoring.md)。 diff --git a/docs/README.md b/docs/README.md index 0f829f5..f1b770b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -14,7 +14,7 @@ | [静态呈现与轻量图表](static-presentation-plan.md) | 当前:保留卡片配色,移除动效与特效,原生静态图表与验证 | | [后台趋势连续性修复](background-trend-continuity-fix.md) | 1.1(4):短暂隐藏未到后台采样截止时,重开曲线仍保持连续 | | [图表跳过无值点](chart-missing-value-policy.md) | 1.1(5):只绘制有效节点并接续,保留真实时间、有效 0 和主动停采断点 | -| [640pt 面板与高度方案](compact-panel-refinement-plan.md) | 本轮:中性色 Tab 与 640pt 宽度;后续:独立双列、按内容定高方案 | +| [640pt 面板与高度方案](compact-panel-refinement-plan.md) | 已实现:中性色 Tab、640pt 独立双列、按内容定高与共用窗口高度 | | [紧凑双页面板](compact-tab-panel-plan.md) | 已实现:概览 / 进程页签、CPU 功率列、按页采样及三轮对照与限制 | 首批实施证据见[轻量化实施记录](efficiency-first-batch.md);第二批见[能量列表与纯文字对照记录](efficiency-second-batch.md)。第三批见[原生绘制与进程表记录](efficiency-third-batch.md);第四批见[动效与效率排查](motion-and-efficiency-plan.md);其淡入实现已由[保留原动效的优化](motion-preservation-plan.md)替代。进程内存显示修正见[footprint 口径与单位对齐](process-memory-alignment-plan.md)。包体积已收敛,真实 CPU 能量列表已实现;内存与长期性能预算仍待通过。 diff --git a/docs/architecture.md b/docs/architecture.md index 4472b3b..a4165f3 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -23,7 +23,7 @@ 入口为 `kymoApp.main()`,由 `NSApplication` 与 `ApplicationLifecycle` 驱动,当前不使用 `MenuBarExtra`。应用以 accessory 模式启动,通过 `NSHostingSceneRepresentation` 注册 Settings 场景。 -`MenuPanelController` 拥有模板品牌状态项和无边框、可成为 key 的非激活 `MonitoringPanel`。左键切换面板;右键菜单提供打开 / 隐藏、设置和退出。面板不播放开关窗动画、不添加装饰阴影。窗口按状态项所在屏幕可见区域定位,水平居中、顶部预留 16pt;最大内容尺寸 640 × 800pt,并按屏幕缩小。面板顶部为概览 / 进程页签,每次显式打开重置概览。常规概览两列,CPU / 电池、GPU / 存储、内存 / 网络逐行配对;宽度小于 560pt 时退为单列,高度不足时滚动。进程页独占中间内容区。底栏左侧显示设备信息,右侧依次为运行时间与刷新间隔。640pt 下品牌 / 居中页签 / 操作组处于顶部同一行;只有宽度小于 560pt 时将页签另放一行,避免极窄屏重叠。几何观察器以实际 contentLayoutRect 和屏幕上限共同确定布局尺寸。 +`MenuPanelController` 拥有模板品牌状态项和无边框、可成为 key 的非激活 `MonitoringPanel`。左键切换面板;右键菜单提供打开 / 隐藏、设置和退出。面板不播放开关窗动画、不添加装饰阴影。窗口按状态项所在屏幕可见区域定位,水平居中、顶部预留 16pt;最大宽度 640pt,常规内容高度 706pt;按卡片结构预算可升降,最大 800pt,并按屏幕缩小。面板顶部为概览 / 进程页签,每次显式打开重置概览。常规概览为独立双列:左 CPU / GPU / 内存,右电池 / 存储 / 网络,仅列顶对齐,不强制同行同高;宽度小于 560pt 时退为单列,高度不足时滚动。进程页独占中间内容区。底栏左侧显示设备信息,右侧依次为运行时间与刷新间隔。640pt 下品牌 / 居中页签 / 操作组处于顶部同一行;只有宽度小于 560pt 时将页签另放一行,避免极窄屏重叠。几何观察器以实际 contentLayoutRect 和屏幕上限共同确定布局尺寸。 固定按钮切换普通 / floating 层级。未固定时外部交互或应用失活可收起,固定时仍可通过状态项或显式关闭收起。进程表的 Esc 依次处理搜索、选中和搜索焦点,随后关闭窗口。隐藏面板时先卸载内容视图、关闭底层窗口资源(保留控制器拥有的窗口对象供重开),并停止监听外部鼠标事件;仅显式启用后台趋势时保留常规采样。 @@ -68,7 +68,7 @@ CPU / GPU / 风扇合并为一次只读 XPC 请求,按到期类别选择读取 面板和资源卡片使用颜色资产中的不透明背景,顶部操作组使用低透明度静态胶囊背景;不再以全窗口液态玻璃概念图作为实现依据。品牌图标与颜色以 Assets 为运行时来源。 -固定 frame 的面板宿主关闭 NSHostingView 自动尺寸协商。每张 ResourceCard 通过 UI 层 NativeContentHost 获得独立、固定尺寸的 NSHostingView,局部数据和状态更新在卡片宿主内处理;父层仍负责列数、卡片尺寸和窗口布局。完整 SwiftUI 环境注入子宿主,保留字体、前景样式、语言和外观;更新沿用原有挂载身份,卸载时清空子宿主内容。坐标、图例、悬浮偏好与提示层都保留在同一卡片宿主内,不跨原生边界传递锚点。趋势图的业务投影继续由 Features 管理;曲线 / 网格 / 悬浮标记与百分比圆环分别由 UI 层 NativePanelCurve、NativeMetricRing 绘制。保留 PanelCurveGeometry 的真实时间、缺失值与断点规则。 +固定 frame 的面板宿主关闭 NSHostingView 自动尺寸协商。每张 ResourceCard 通过 UI 层 NativeContentHost 获得独立、固定尺寸的 NSHostingView,局部数据和状态更新在卡片宿主内处理;父层按稳定列顺序、内容行数和硬件拓扑计算卡片尺寸,并经 App 注入首选高度回调交给 MenuPanelController 约束到屏幕可用区域。窗口高度取较长列加顶部、底栏和间隔,两页共用外框;结构预算相同不触发重复 setFrame,数值刷新不改变高度。核心数优先使用静态拓扑 / 硬件核数,避免首帧无值收缩;风扇在本次打开保留已发现槽位,确认无风扇时可移除发现占位。完整 SwiftUI 环境注入子宿主,保留字体、前景样式、语言和外观;更新沿用原有挂载身份,卸载时清空子宿主内容。坐标、图例、悬浮偏好与提示层都保留在同一卡片宿主内,不跨原生边界传递锚点。趋势图的业务投影继续由 Features 管理;曲线 / 网格 / 悬浮标记与百分比圆环分别由 UI 层 NativePanelCurve、NativeMetricRing 绘制。保留 PanelCurveGeometry 的真实时间、缺失值与断点规则。 进程表使用 MenuBar 的 NativeProcessTable(view-based NSTableView),继续消费 ProcessTableProjection 的搜索 / 排序 / 冻结投影。仅创建可见单元格,行数改变时增删尾行,刷新时原地修改可见文本与图像;选择以完整 ProcessIdentity 同步,用户选择 / 排序延后到委托回调之外写回 SwiftUI。原生 Esc 转发至原有分层退出逻辑,右键菜单保留复制能力。共享 ProcessIconCache 将 NSWorkspace 原图绘制为 30×30 像素、15pt 的单一位图,不保留原图;最多 128 项 / 1 MiB 解码像素,30 秒过期、LRU 淘汰、内存压力清空,不启动轮询。其预算不代表系统图标服务内部缓存已受控。 @@ -108,4 +108,4 @@ PublicIPAddressService 默认持有专用 ephemeral URLSession,URLCache / HTTP CPU 逐核显示使用数值与静态短条,内存保留分布条;GPU 渲染器 / 分块器独立进度条和统计区、电池内的耗电前三列表已移除,存储重复容量条改为可用容量 / 健康 / 通电时长 / 卷入口文本。六张趋势保留既有真实时间及断点规则。页面布局和数据需求详见[实施记录](compact-tab-panel-plan.md)。 -进一步收窄阶段中,概览与设置共享 UI/Components/NeutralTabPicker,保持中性色分段导航;窄卡片的内存趋势图例省略重复实时值,完整分类数值仍在内存分布区及悬浮中提供。外接电源的时间项简写为不适用,完整说明在提示中。独立双列和按内容定高尚为[下一阶段方案](compact-panel-refinement-plan.md),当前仍按物理行对齐,800pt 高度上限未变。 +进一步收窄阶段中,概览与设置共享 UI/Components/NeutralTabPicker,保持中性色分段导航;窄卡片的内存趋势图例省略重复实时值,完整分类数值仍在内存分布区及悬浮中提供。外接电源的时间项简写为不适用,完整说明在提示中。独立双列和按内容定高已按[实施方案](compact-panel-refinement-plan.md)落实:趋势绘图区 48pt、分隔线竖向留白 2pt;内存使用率移至标题徽标,存储为双列文本,网络合并状态 / 接口及地址行。核心按至少 16pt 单元格动态增加行数,不再限制最多三行;超出屏幕时通过概览滚动访问。 diff --git a/docs/compact-panel-refinement-plan.md b/docs/compact-panel-refinement-plan.md index 059a053..e389d8c 100644 --- a/docs/compact-panel-refinement-plan.md +++ b/docs/compact-panel-refinement-plan.md @@ -5,7 +5,7 @@ ## 本轮范围与现状 - 第一阶段直接实施 Tab 与宽度:960 → 640pt;保留两列,只有更窄屏幕退为单列;对窄卡片内的图例和冗长值做必要适配。 -- 卡片高度第二阶段仍只做方案。后续用户已明确:Tab 保留顶部,刷新间隔放底部右侧;该工具栏修订单独实施,不改变卡片排列或窗口高度上限。 +- 卡片高度第二阶段已由用户明确授权并实施;Tab 保留顶部,刷新间隔位于底部右侧,工具栏位置与上一版一致。 - 工作开始时工作区与暂存区干净,当前分支 codex/compact-tab-panel。 - 修改前设置与面板都使用 SwiftUI segmented Picker,但面板继承蓝色 tint,设置位于工具栏上下文;改成共享中性色 Tab 控件,避免两个 Features 相互依赖。 - 现状按行取 max(左右卡高),另有卡片最小高度和内部 Spacer。当前两列行高为 220 / 204 / 260pt(高核心数或多风扇时增加),不能仅靠取消行对齐就明显降低整体高度。 @@ -17,7 +17,7 @@ - [x] 检查 Debug 构建、布局、三语和相关原生窗口 / 表格回归;实际检查 640pt 下概览与进程、Tab 外观及交互。 - [x] 同步架构与验收记录,提交本轮相关修改,不推送。 -## 第二阶段建议:按内容定高的独立双列 +## 第二阶段设计:按内容定高的独立双列 保持左列 CPU / GPU / 内存、右列电池 / 存储 / 网络,各列自上而下紧凑排列。只对齐两列顶部,允许中间卡片边缘错开;两列底部剩余高度差保留在列外,不填进卡片。不要按每轮数值动态变高,避免刷新时抖动。 @@ -47,12 +47,50 @@ - 这轮只调整呈现,不改变两页采样、XPC、安全边界及后台记录偏好;布局更小不能直接当作功耗降低证据。 - 后续高度实施需要验证图表提示位置、所有核心 / 风扇可达、两页表格交互、切页停止非当前页面工作及实际资源占用。 -## 本轮结果 +## 第一阶段结果(1.1(8)) -Tab 已改为共享 AppKit NSSegmentedControl(tabs role + capsule 样式),避免 SwiftUI 的 body / toolbar 语义造成不同外观。仅覆盖 tint 的试验未采用。已通过 7 项相关回归及新增 TabPickerChecks,后者验证原生控件双向绑定、三语即时更新和选择保留;目录共 213 项。实际 CUA 检查了 640pt 双列、监控页签来回切换、设置中的常规 / 关于切换及两种宿主的胶囊外观。最终 Debug 构建通过,1.1(8)普通 Release 测试包构建、签名 / 权限 / ZIP 解压复核通过;第二阶段仍为方案。已清理本轮临时副本、构建、脚本、日志和随机容器。测试前记录的 /Applications/kymo.app(PID 50403)及其 SMARTService(PID 50406)保留,未安装、推送或发布。 +Tab 已改为共享 AppKit NSSegmentedControl(tabs role + capsule 样式),避免 SwiftUI 的 body / toolbar 语义造成不同外观。仅覆盖 tint 的试验未采用。已通过 7 项相关回归及新增 TabPickerChecks,后者验证原生控件双向绑定、三语即时更新和选择保留;目录共 213 项。实际 CUA 检查了 640pt 双列、监控页签来回切换、设置中的常规 / 关于切换及两种宿主的胶囊外观。最终 Debug 构建通过,1.1(8)普通 Release 测试包构建、签名 / 权限 / ZIP 解压复核通过;当时第二阶段仍为方案,现已按文末记录实施。已清理本轮临时副本、构建、脚本、日志和随机容器。测试前记录的 /Applications/kymo.app(PID 50403)及其 SMARTService(PID 50406)保留,未安装、推送或发布。 ## 用户修订:顶部页签与底部刷新间隔 -按用户后续指示,将刷新间隔移至公共底栏最右侧,运行时间位于其左侧,设备信息在左侧按需截断。640pt 下顶部从 64pt 双行收为 32pt 单行,底栏由 18pt 增至 26pt 容纳输入与步进器,资源区净增加 24pt;14 核常规概览可完整显示。核心 / 风扇更多或屏幕更矮时仍按实际内容滚动。卡片高度与独立双列尚未实施,640×800pt 上限保持。 +按用户后续指示,将刷新间隔移至公共底栏最右侧,运行时间位于其左侧,设备信息在左侧按需截断。640pt 下顶部从 64pt 双行收为 32pt 单行,底栏由 18pt 增至 26pt 容纳输入与步进器,资源区净增加 24pt;14 核常规概览可完整显示。核心 / 风扇更多或屏幕更矮时仍按实际内容滚动。该版本尚未实施卡片高度与独立双列,640×800pt 上限保持。 本次 Debug / Release 构建通过;PanelLayoutChecks、TabPickerChecks、SamplingIntervalChecks、PanelWindowChecks 四项回归与 213 项三语目录校验通过。CUA 实际确认 640×800pt 下顶部品牌 / Tab / 操作组单行、底栏右侧刷新输入及六卡完整显示,并验证 2.0→3.0 秒编辑、跨页保留、步进至 3.1 秒。1.1(9)测试包签名 / 权限 / ZIP 解压复核通过。已清理本轮临时文件与随机容器,仅退出本轮测试副本;已有 /Applications/kymo.app(PID 54024)和 SMARTService(PID 54034)保留。未安装、推送或发布。 + +## 第二阶段实施(1.1(10),已完成) + +继续保留顶部 Tab、底部右侧刷新间隔。布局由 MenuBar 的纯几何预算计算,App 只装配首选高度回调,MenuPanelController 继续独占窗口尺寸与定位,Core 采样逻辑不变。UI 组件压缩图表和分隔间距,保持固定尺寸卡片子宿主;不通过逐次内容测量反向协商窗口。 + +- [x] 每卡独立高度与固定列顺序:常规 CPU 204 / GPU 164 / 内存 228pt;电池 170 / 存储 170 / 网络 208pt,最终按实际渲染校正。 +- [x] 趋势绘图区 58→48pt;去除 CPU Spacer,内存百分比移至标题,存储双列文本,网络移除重复地址标题。 +- [x] 两列总高取较大值加公共栏;常规预算 640×706pt,按真实屏幕限制。进程页沿用相同外框,不因切页跳动。 +- [x] 核心槽位先按静态硬件拓扑预算;高核心数增加可读行数并允许滚动,不把数值挤进固定三行。风扇已发现槽位在本次打开中保留;无风扇确认只引起一次结构调整。 +- [x] 回归实际双列、图表提示、三语、冷启动 / 刷新 / 切页 / 重开尺寸稳定、小屏滚动、按页采样需求和资源卸载;构建与本地测试包验证。 +- [x] 记录结果和限制,清理隔离副本与构建,分批提交,不推送。开始时工作区与暂存区干净,已有应用 PID 55382 / XPC PID 55384 保留。 + +### 实际布局结果 + +本机 Apple M4 Pro、14 核、两个风扇,常规外框由 640×800pt 缩至 **640×706pt**,高度减少 94pt(约 11.75%)。左右卡片顺序不变,只有列顶对齐,较短列剩余空间位于卡片外;矮窗口下两列共用一个纵向滚动区。 + +| 卡片 | 上版行对齐后的显示高度 | 本版独立高度 | +| --- | ---: | ---: | +| CPU | 220 | 204 | +| GPU | 204 | 164 | +| 内存 | 260 | 228 | +| 电池 | 220 | 170 | +| 存储 | 204 | 170 | +| 网络 | 260 | 208 | + +本版左列 612pt、右列 564pt,公共栏和间隔共 94pt。未取得风扇信息时预留一行,确认无风扇时 GPU 预算为 124pt、窗口预算为 666pt;这是纯几何边界验证,未用真实无风扇机器验收。高核心数扩大可读行数,窗口最高 800pt 后滚动,不挤压百分比文字。 + +### 验证与限制 + +- Debug 构建和 1.1(10)普通 Release 打包通过;主程序 / XPC 签名、权限及 ZIP 解压复核通过。没有 XCTest Target,使用独立检查程序。 +- 9 项受影响检查通过:PanelLayoutChecks、CPUCoreGridChecks、PanelWindowChecks、NativeContentHostChecks、TabPickerChecks、PanelCurveChecks、DetailDemandChecks、NativeMetricDrawingChecks、LanguageScopeChecks;213 项三语目录校验通过。 +- 实际 CUA 检查:中文深色和英文浅色 640×706pt,各卡片内容与核心数字可达;概览 → 进程 → 概览三次局部截图均为 1280×1412 像素(Retina 2×),没有切页变高。多次采样中外框保持相同尺寸。 +- 640×600pt 强制矮视口中,原生 Scroll Down 动作将滚动条从 0 推至 1,底部内存分类 / 压力及网络地址可达;顶部 Tab 和底部刷新输入固定。长英文标签或长地址在有滚动条时仍可省略显示,完整地址可复制 / 查看提示,不缩小字体硬塞。 +- 实测发现并修正:窄卡片英文地址需要去掉多余 Spacer;存储入口合并为可点击的 Local volumes;详情弹层显式继承应用 locale,英文弹层已核对。 +- 原生图层的悬浮几何 / 缓存 / 缺失值回归通过;实际坐标点击 / 拖动未触发图表悬浮提示,因此真实鼠标悬浮路径仍未确认。真实多屏、实际高核心数机器及主观观感仍待用户验收。 +- Core 采样及两页需求策略未修改,DetailDemandChecks 验证概览不枚举进程、进程页切换和基础历史连续。未重新测量功率或长期资源预算,不能把外框减少约 12% 解释成功耗同幅降低。 + +收尾:已清理本轮隔离构建、诊断 app、局部截图相关临时数据、脚本、日志和随机偏好容器;保留最终 1.1(10)ZIP 与 SHA-256。仅退出本轮临时路径下的测试进程,未操作测试前已有的 /Applications/kymo.app(PID 55382)及其 XPC(PID 55384)。未安装到 Applications、未推送或发布。 diff --git a/docs/free-test-distribution.md b/docs/free-test-distribution.md index 6b0453f..dd7e467 100644 --- a/docs/free-test-distribution.md +++ b/docs/free-test-distribution.md @@ -2,7 +2,7 @@ ## 适用范围 -当前产物:Kymo 1.1(build 9),macOS 27.0 及以上、Apple silicon arm64。Intel 或较低系统不在该产物支持范围。软件使用 ad-hoc 本地签名,未经过 Apple 公证,不是 Developer ID 官方分发包;下载后的系统提示取决于接收方安全策略。 +当前产物:Kymo 1.1(build 10),macOS 27.0 及以上、Apple silicon arm64。Intel 或较低系统不在该产物支持范围。软件使用 ad-hoc 本地签名,未经过 Apple 公证,不是 Developer ID 官方分发包;下载后的系统提示取决于接收方安全策略。 ## 构建与校验 @@ -10,10 +10,10 @@ python3 tools/package_release.py ``` -默认输出:`dist/kymo-1.1-9-arm64-adhoc.zip` 和同名 `.sha256`。首次打包前会通过签名、Hardened Runtime、权限和包内容检查,ZIP 解压后再次检查。再次构建不覆盖已存在同名产物,可用 `--output` 另选目录。校验下载文件: +默认输出:`dist/kymo-1.1-10-arm64-adhoc.zip` 和同名 `.sha256`。首次打包前会通过签名、Hardened Runtime、权限和包内容检查,ZIP 解压后再次检查。再次构建不覆盖已存在同名产物,可用 `--output` 另选目录。校验下载文件: ```bash -shasum -a 256 -c kymo-1.1-9-arm64-adhoc.zip.sha256 +shasum -a 256 -c kymo-1.1-10-arm64-adhoc.zip.sha256 ``` SHA-256 用于核对文件是否与发布者给出的文件一致,不等同于 Apple 身份认证;校验值应从可信渠道获取。 diff --git a/docs/testing.md b/docs/testing.md index 27cbfa0..f1ef18c 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -345,4 +345,6 @@ DetailDemandChecks 验证概览零进程枚举、切页时旧同步任务不回 显式诊断构建(DEBUG 或 KYMO_AUDIT)可设置 KYMO_RESOURCE_AUDIT=1、KYMO_AUDIT_INTERACTIVE=1 打开固定面板供实际交互,可加 KYMO_AUDIT_SIZE=760x600 检查实际小 viewport;KYMO_AUDIT_PAGE=processes 选择资源循环中的进程页;KYMO_AUDIT_QUICK=1 使用 3 秒初始隐藏、每轮 30 秒展开 / 5 秒关闭,不执行暂停段。普通 Release 不包含驱动实现。此类诊断驱动不能替代实际输入事件,也不能证明长期性能预算。 -TabPickerChecks 使用实际原生 Tab 检查双向选择绑定、三语标签原地更新及选择保留。640pt 面板与后续高度建议见[收窄方案](compact-panel-refinement-plan.md);本轮仅改变宽度和 Tab,不复用上一轮资源数据宣称进一步节能。 +TabPickerChecks 使用实际原生 Tab 检查双向选择绑定、三语标签原地更新及选择保留。640pt 面板与后续高度建议见[收窄方案](compact-panel-refinement-plan.md);卡片高度阶段新增独立列预算、动态窗口高度、0–128 核可读行数及小屏滚动回归;不复用上一轮资源数据宣称进一步节能。 + +卡片高度阶段的 PanelLayoutChecks 验证左 / 右卡片独立、常规 706pt 高度、无风扇收缩、高核心数 / 屏幕上限及滚动;PanelWindowChecks 验证控制器响应首选高度、重复预算不重设窗口与实际 contentLayoutRect;CPUCoreGridChecks 检查不再把高核心数挤进三行。实际设备只代表本机,纯几何检查不替代真实高核心数 / 多显示器验收。 diff --git a/kymo.xcodeproj/project.pbxproj b/kymo.xcodeproj/project.pbxproj index e68217c..8772861 100644 --- a/kymo.xcodeproj/project.pbxproj +++ b/kymo.xcodeproj/project.pbxproj @@ -425,7 +425,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 9; + CURRENT_PROJECT_VERSION = 10; DEAD_CODE_STRIPPING = YES; ENABLE_APP_SANDBOX = YES; ENABLE_OUTGOING_NETWORK_CONNECTIONS = YES; @@ -458,7 +458,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 9; + CURRENT_PROJECT_VERSION = 10; DEAD_CODE_STRIPPING = YES; ENABLE_APP_SANDBOX = YES; ENABLE_HARDENED_RUNTIME = YES; diff --git a/kymo/App/kymoApp.swift b/kymo/App/kymoApp.swift index 5c6f462..2933054 100644 --- a/kymo/App/kymoApp.swift +++ b/kymo/App/kymoApp.swift @@ -63,6 +63,8 @@ import AppKit presentation: panel, onOpenSettings: { [weak self] in self?.menuBar?.hide() settings.environment.openSettings() + }, onPreferredHeight: { [weak self] height in + self?.menuBar?.setPreferredContentHeight(height) }) } } diff --git a/kymo/Features/MenuBar/CPUCoreGrid.swift b/kymo/Features/MenuBar/CPUCoreGrid.swift index 6f7d703..1bf2c53 100644 --- a/kymo/Features/MenuBar/CPUCoreGrid.swift +++ b/kymo/Features/MenuBar/CPUCoreGrid.swift @@ -1,6 +1,6 @@ import SwiftUI -/// Keep cores in two balanced rows when they fit, otherwise use at most three. +/// Keep two balanced rows when possible; add rows to preserve readable core values. struct CPUCoreGrid: View { let values: [Double] let kinds: [Int: CPUCoreTopology.Kind] @@ -66,7 +66,7 @@ struct CPUCoreGrid: View { } } .frame(height: 15 + CGFloat(maxRows(groups: groups)) * 22 + CGFloat(max(0, maxRows(groups: groups) - 1)) * 4) - .padding(.vertical, 4) + .padding(.vertical, 1) } // Match the content width so row reservation agrees with placement. @@ -102,10 +102,9 @@ struct CPUCoreGridLayout: Layout { static func rowCounts(count: Int, width: CGFloat) -> [Int] { guard count > 0 else { return [] } guard count > 1 else { return [1] } - let twoColumns = (count + 1) / 2 - let availableForCells = width - CGFloat(twoColumns - 1) * columnSpacing - let twoRowCellWidth = availableForCells / CGFloat(twoColumns) - let rows = count > 2 && twoRowCellWidth < minimumTwoRowCellWidth ? 3 : 2 + let usableWidth = width.isFinite ? max(0, width) : 0 + let capacity = max(1, Int(min(CGFloat(count), (usableWidth + columnSpacing) / (minimumTwoRowCellWidth + columnSpacing)))) + let rows = max(2, (count + capacity - 1) / capacity) let quotient = count / rows, remainder = count % rows return (0.. Void private var showingStatusMenu = false private var isHiding = false + private var preferredContentHeight = PanelLayout.defaultHeight init(installStatusItem: Bool = true, visibility: @escaping (Bool) -> Void, pageChanged: @escaping (PanelPage) -> Void = { _ in }, @@ -168,9 +169,22 @@ enum PanelPage: Hashable { case overview, processes } visibilityObservation = nil } + func setPreferredContentHeight(_ height: CGFloat) { + guard height.isFinite, height > 0 else { return } + let height = min(PanelLayout.maximumHeight, max(360, height)) + guard preferredContentHeight != height else { return } + preferredContentHeight = height +#if DEBUG || KYMO_AUDIT + // An explicit diagnostic viewport must not be overridden by automatic sizing. + if ProcessInfo.processInfo.environment["KYMO_AUDIT_INTERACTIVE"] == "1", + ProcessInfo.processInfo.environment["KYMO_AUDIT_SIZE"] != nil { return } +#endif + if presentation.isOpen { place() } + } + private func place() { guard let screen = statusItem?.button?.window?.screen ?? panel.screen ?? NSScreen.main else { return } - let size = PanelLayout.contentSize(visible: screen.visibleFrame) + let size = PanelLayout.contentSize(visible: screen.visibleFrame, preferredHeight: preferredContentHeight) let initial = CGRect(x: screen.visibleFrame.midX - size.width / 2, y: screen.visibleFrame.maxY - size.height - 16, width: size.width, height: size.height) panel.setFrame(PanelLayout.centeredFrame(initial, visible: screen.visibleFrame), display: panel.isVisible) diff --git a/kymo/Features/MenuBar/MenuPanelView+Network.swift b/kymo/Features/MenuBar/MenuPanelView+Network.swift index 805a17a..267afc8 100644 --- a/kymo/Features/MenuBar/MenuPanelView+Network.swift +++ b/kymo/Features/MenuBar/MenuPanelView+Network.swift @@ -24,8 +24,8 @@ extension MenuPanelView { symbol: "arrow.up", color: Color("SeriesUpload")) Divider().frame(height: 32) VStack(alignment: .leading, spacing: 4) { - HStack { - Text("network.status").foregroundStyle(.secondary) + HStack(spacing: 4) { + Circle().fill(networkStatusColor).frame(width: 5, height: 5) Picker("panel.interface", selection: $selectedInterface) { Text("network.all").tag("") ForEach(snapshot.network ?? [], id: \.identity) { item in @@ -33,33 +33,29 @@ extension MenuPanelView { } }.labelsHidden().controlSize(.mini).fixedSize() } - HStack(spacing: 4) { - Circle().fill(networkStatusColor).frame(width: 5, height: 5) - Text(networkStatusLabel) - } + Text(networkStatusLabel).help(Text(networkStatusLabel)) }.frame(maxWidth: .infinity, alignment: .leading) }.font(PanelStyle.label).lineLimit(1) CardSeparator() - VStack(alignment: .leading, spacing: 5) { - Text("network.addresses").font(PanelStyle.section) - HStack(spacing: 8) { - networkAddress("network.public", address: publicIPAddress) - Divider().frame(height: 15) - networkAddress( - "network.local", - address: addressInterface?.addresses.first(where: { !$0.contains(":") }) ?? addressInterface?.addresses.first) - } + HStack(spacing: 8) { + networkAddress("network.public", address: publicIPAddress) + Divider().frame(height: 15) + networkAddress( + "network.local", + address: addressInterface?.addresses.first(where: { !$0.contains(":") }) ?? addressInterface?.addresses.first) }.font(PanelStyle.label) .modifier(CardInset()) + .accessibilityElement(children: .contain) + .accessibilityLabel(Text("network.addresses")) } .modifier(PanelPublicIPRefresh(metrics: metrics, address: $publicIPAddress)) } func networkAddress(_ title: LocalizedStringKey, address: String?) -> some View { - HStack(spacing: 4) { + HStack(spacing: 3) { Text(title).foregroundStyle(.secondary) Text(verbatim: address ?? "--").font(PanelStyle.value).monospacedDigit().textSelection(.enabled) .help(Text(verbatim: address ?? "--")) - Spacer(minLength: 0) + .frame(maxWidth: .infinity, alignment: .leading) if let address { Button { NSPasteboard.general.clearContents() diff --git a/kymo/Features/MenuBar/MenuPanelView+ResourceCards.swift b/kymo/Features/MenuBar/MenuPanelView+ResourceCards.swift index 44dc4ed..62c31a3 100644 --- a/kymo/Features/MenuBar/MenuPanelView+ResourceCards.swift +++ b/kymo/Features/MenuBar/MenuPanelView+ResourceCards.swift @@ -34,7 +34,6 @@ extension MenuPanelView { boundaryDates: chartBoundaries, intervals: chartIntervals) CardSeparator() if let cpu = snapshot.cpu { - Spacer(minLength: 0) CPUCoreGrid( values: cpu.cores, kinds: CPUCoreTopology.cores, interval: chartInterval, availableWidth: cardContentWidth) @@ -57,18 +56,24 @@ extension MenuPanelView { color: Color("MetricGPU"), secondColor: Color("MetricCPU"), thirdColor: Color("SeriesSystem"), firstLabel: "gpu.totalUtilization", secondLabel: "gpu.renderer", thirdLabel: "gpu.tiler", expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: chartIntervals) - CardSeparator() let fans = displayedFans if !fans.isEmpty { - LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 10), count: min(2, fans.count)), spacing: 5) { + CardSeparator() + LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 10), count: min(2, fans.count)), spacing: 4) { ForEach(fans) { fan in FanSpeedIndicator( title: fans.count == 2 ? (fan.id == 0 ? Text("gpu.fanLeft") : Text("gpu.fanRight")) : Text("gpu.fanNumber \(fan.id + 1)"), rpm: fan.rpm) + .frame(height: 16) } } .modifier(CardInset()) + } else if snapshot.fans == nil { + CardSeparator() + Text("metric.waiting").font(PanelStyle.label) + .frame(maxWidth: .infinity, alignment: .leading).frame(height: 16) + .modifier(CardInset()) } } } @@ -78,7 +83,8 @@ extension MenuPanelView { title: "metric.memory", symbol: "memorychip", color: Color("MemoryApplication"), value: snapshot.memory.map { String(format: "%.1f / %.0f GiB", Double($0.used) / 1_073_741_824, Double($0.total) / 1_073_741_824) - } ?? "--" + } ?? "--", + status: snapshot.memory.map { MetricFormat.percent($0.usage) } ) { PanelTrendChart( dates: samples.map(\.date), @@ -134,6 +140,7 @@ extension MenuPanelView { Text("panel.apfsScope").font(.system(size: 9)).foregroundStyle(.secondary) } }.padding(12).frame(width: 330) + .environment(\.locale, locale) } } @@ -163,7 +170,7 @@ extension MenuPanelView { batteryDetails(battery) } else { Text(snapshot.batteryState == .absent ? "panel.noBattery" : "panel.batteryFailed").foregroundStyle(.secondary) - .frame(maxWidth: .infinity, maxHeight: .infinity) + .font(PanelStyle.label).frame(maxWidth: .infinity).frame(height: 32) } } } @@ -199,7 +206,7 @@ extension MenuPanelView { .lineLimit(1) .frame(height: 32) - }.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading) + }.frame(maxWidth: .infinity, alignment: .topLeading) } } diff --git a/kymo/Features/MenuBar/MenuPanelView.swift b/kymo/Features/MenuBar/MenuPanelView.swift index 0da808a..ddc8f3b 100644 --- a/kymo/Features/MenuBar/MenuPanelView.swift +++ b/kymo/Features/MenuBar/MenuPanelView.swift @@ -8,6 +8,7 @@ struct MenuPanelView: View { let settingsPresentation: SettingsPresentation var presentation = PanelPresentation() var onOpenSettings: () -> Void = {} + var onPreferredHeight: (CGFloat) -> Void = { _ in } @Environment(\.locale) var locale @State private var panelSize = PanelLayout.contentSize(visible: NSScreen.main?.visibleFrame ?? CGRect(x: 0, y: 0, width: 1000, height: 760)) @State var selectedInterface = "" @@ -30,13 +31,15 @@ struct MenuPanelView: View { } var cardContentWidth: CGFloat { max(0, (measuredCardWidth ?? PanelLayout.cardWidth(size: panelSize)) - 20) } var columns: Int { PanelLayout.columns(width: panelSize.width) } - private var rowHeights: [CGFloat] { - let groups = CPUCoreGrid.groups(count: snapshot.cpu?.cores.count ?? 0, kinds: CPUCoreTopology.cores) - let widths = CPUCoreGrid.groupWidths(groups: groups, width: max(0, (measuredCardWidth ?? PanelLayout.cardWidth(size: panelSize)) - 20)) + private var cardHeights: [PanelCard: CGFloat] { + let coreCount = max(CPUCoreTopology.cores.count, ProcessInfo.processInfo.processorCount, snapshot.cpu?.cores.count ?? 0) + let groups = CPUCoreGrid.groups(count: coreCount, kinds: CPUCoreTopology.cores) + let widths = CPUCoreGrid.groupWidths(groups: groups, width: cardContentWidth) let coreRows = zip(groups, widths).map { CPUCoreGridLayout.rowCounts(count: $0.0.count, width: $0.1).count }.max() ?? 0 - return PanelLayout.rowHeights(columns: columns, coreRows: coreRows, - fanCount: max(reservedFanCount, snapshot.fans?.count ?? 0)) + let fanCount = reservedFanCount > 0 ? max(reservedFanCount, snapshot.fans?.count ?? 0) : snapshot.fans?.count + return PanelLayout.cardHeights(coreRows: coreRows, fanCount: fanCount) } + private var preferredHeight: CGFloat { PanelLayout.preferredHeight(width: panelSize.width, heights: cardHeights) } var network: [NetworkInterfaceMetrics] { (snapshot.network ?? []).filter { selectedInterface.isEmpty ? $0.isIncludedInTotal : $0.identity == selectedInterface } } @@ -49,11 +52,11 @@ struct MenuPanelView: View { VStack(spacing: PanelStyle.gap) { if PanelResourceAudit.omitted != "header" { header } if presentation.page == .overview { - if PanelLayout.needsResourceScroll(size: panelSize, rows: rowHeights) { - ScrollView { resourceRows } + if PanelLayout.needsResourceScroll(size: panelSize, heights: cardHeights) { + ScrollView { resourceColumns } .frame(maxWidth: .infinity, maxHeight: .infinity) } else { - resourceRows + resourceColumns .frame(maxHeight: .infinity, alignment: .top) } } else if presentation.isOpen && PanelResourceAudit.omitted != "processes" { @@ -67,6 +70,12 @@ struct MenuPanelView: View { .background(PanelWindowObserver { size in if panelSize != size { panelSize = size } }.frame(width: 0, height: 0)) + .task(id: preferredHeight) { + // Resize only for structural changes, outside the current layout pass. + await Task.yield() + guard !Task.isCancelled else { return } + onPreferredHeight(preferredHeight) + } .onAppear { reservedFanCount = snapshot.fans?.count ?? 0 } @@ -82,35 +91,36 @@ struct MenuPanelView: View { .modifier(AppearanceStyle(preferences: preferences)) } - private var resourceRows: some View { - VStack(spacing: PanelStyle.gap) { - ForEach(rowHeights.indices, id: \.self) { row in - HStack(spacing: PanelStyle.gap) { - ForEach(0.. some View { + @ViewBuilder private func resourceCard(_ card: PanelCard) -> some View { if PanelResourceAudit.omitted == "resources" { Color.clear } else { - switch index { - case 0: cpuCard - case 1: batteryCard - case 2: gpuCard - case 3: diskCard - case 4: memoryCard - case 5: networkCard - default: EmptyView() + switch card { + case .cpu: cpuCard + case .battery: batteryCard + case .gpu: gpuCard + case .storage: diskCard + case .memory: memoryCard + case .network: networkCard } } } diff --git a/kymo/Features/MenuBar/PanelLayout.swift b/kymo/Features/MenuBar/PanelLayout.swift index fcc6ed9..1a027f2 100644 --- a/kymo/Features/MenuBar/PanelLayout.swift +++ b/kymo/Features/MenuBar/PanelLayout.swift @@ -1,36 +1,61 @@ import Foundation import CoreGraphics +nonisolated enum PanelCard: Int, CaseIterable { + case cpu, battery, gpu, storage, memory, network +} + nonisolated enum PanelLayout { - static let baseCardHeight: CGFloat = 204 static let footerHeight: CGFloat = 26 + static let maximumHeight: CGFloat = 800 static func headerHeight(width: CGFloat) -> CGFloat { width >= 560 ? 32 : 64 } static func columns(width: CGFloat) -> Int { width >= 560 ? 2 : 1 } static func cardWidth(size: CGSize) -> CGFloat { let count = columns(width: size.width) return max(0, (size.width - 20 - CGFloat(count - 1) * 8) / CGFloat(count)) } - /// Physical order: CPU/battery, GPU/storage, memory/network. - static func rowHeights(columns: Int, coreRows: Int, fanCount: Int) -> [CGFloat] { - let cpu: CGFloat = 220 + CGFloat(max(0, coreRows - 2)) * 26 - let gpu = baseCardHeight + CGFloat(max(0, (fanCount + 1) / 2 - 1)) * 26 - let heights = [cpu, baseCardHeight, gpu, baseCardHeight, 260, 260] - let count = max(1, min(2, columns)) - return stride(from: 0, to: heights.count, by: count).map { - heights[$0.. CGFloat { - rows.reduce(0, +) + CGFloat(max(0, rows.count - 1)) * 8 - } - static func needsResourceScroll(size: CGSize, rows: [CGFloat]) -> Bool { - // Outer padding, common toolbar/footer, and two gaps. Process page is separate. - resourceHeight(rows: rows) > size.height - 20 - headerHeight(width: size.width) - footerHeight - 16 + + /// Preserve location and order; never rebalance columns when values change. + static func cardColumns(columns: Int) -> [[PanelCard]] { + columns > 1 ? [[.cpu, .gpu, .memory], [.battery, .storage, .network]] : [PanelCard.allCases] } - static func contentSize(visible: CGRect, chrome: CGSize = .zero) -> CGSize { + /// Fixed content rows with a 48pt plot. Nil fans reserve a discovery row. + static func cardHeights(coreRows: Int, fanCount: Int?) -> [PanelCard: CGFloat] { + let fanRows = fanCount.map { (max(0, $0) + 1) / 2 } ?? 1 + return [.cpu: 152 + CGFloat(max(1, coreRows)) * 26, + .gpu: fanRows == 0 ? 124 : 144 + CGFloat(fanRows) * 20, + .memory: 228, .battery: 170, .storage: 170, .network: 208] + } + + static func columnHeights(columns: Int, heights: [PanelCard: CGFloat]) -> [CGFloat] { + cardColumns(columns: columns).map { cards in + cards.reduce(0) { $0 + (heights[$1] ?? 0) } + CGFloat(max(0, cards.count - 1)) * 8 + } + } + + static func resourceHeight(columns: Int, heights: [PanelCard: CGFloat]) -> CGFloat { + columnHeights(columns: columns, heights: heights).max() ?? 0 + } + + static func preferredHeight(width: CGFloat, heights: [PanelCard: CGFloat]) -> CGFloat { + min(maximumHeight, resourceHeight(columns: columns(width: width), heights: heights) + + 20 + headerHeight(width: width) + footerHeight + 16) + } + + static var defaultHeight: CGFloat { + preferredHeight(width: 640, heights: cardHeights(coreRows: 2, fanCount: nil)) + } + + static func needsResourceScroll(size: CGSize, heights: [PanelCard: CGFloat]) -> Bool { + resourceHeight(columns: columns(width: size.width), heights: heights) + > size.height - 20 - headerHeight(width: size.width) - footerHeight - 16 + } + + static func contentSize(visible: CGRect, chrome: CGSize = .zero, preferredHeight: CGFloat? = nil) -> CGSize { CGSize(width: max(1, min(640, visible.width - 32 - max(0, chrome.width))), - height: max(1, min(800, visible.height - 32 - max(0, chrome.height)))) + height: max(1, min(maximumHeight, preferredHeight ?? defaultHeight, + visible.height - 32 - max(0, chrome.height)))) } static func centeredFrame(_ frame: CGRect, visible: CGRect) -> CGRect { var result = constrainedFrame(frame, visible: visible) diff --git a/kymo/Features/MenuBar/PanelWindowObserver.swift b/kymo/Features/MenuBar/PanelWindowObserver.swift index a1b8572..011ab52 100644 --- a/kymo/Features/MenuBar/PanelWindowObserver.swift +++ b/kymo/Features/MenuBar/PanelWindowObserver.swift @@ -32,7 +32,7 @@ struct PanelWindowObserver: NSViewRepresentable { let frame = (window.screen ?? NSScreen.main)?.visibleFrame ?? NSRect(x: 0, y: 0, width: 1000, height: 760) let chrome = CGSize(width: max(0, window.frame.width - window.contentLayoutRect.width), height: max(0, window.frame.height - window.contentLayoutRect.height)) - let maximum = PanelLayout.contentSize(visible: frame, chrome: chrome) + let maximum = PanelLayout.contentSize(visible: frame, chrome: chrome, preferredHeight: PanelLayout.maximumHeight) let size = CGSize(width: min(maximum.width, window.contentLayoutRect.width), height: min(maximum.height, window.contentLayoutRect.height)) DispatchQueue.main.async { [weak self, weak window] in diff --git a/kymo/Features/MenuBar/StorageDetailsView.swift b/kymo/Features/MenuBar/StorageDetailsView.swift index e265312..4767c78 100644 --- a/kymo/Features/MenuBar/StorageDetailsView.swift +++ b/kymo/Features/MenuBar/StorageDetailsView.swift @@ -8,29 +8,35 @@ struct StorageDetailsView: View { var body: some View { VStack(alignment: .leading, spacing: 4) { CardSeparator() - HStack(alignment: .top, spacing: 8) { - CardField(title: "memory.available") { - MetricText(value: MetricFormat.bytes(disk?.available)) + HStack(spacing: 8) { + VStack(spacing: 4) { + field("memory.available", value: MetricFormat.bytes(disk?.available)) + field("disk.powerOnHours", value: health?.powerOnHours.map { "\($0) h" } ?? "--") } Divider().frame(height: 32) - CardField(title: "disk.remainingLife") { - MetricText(value: MetricFormat.percent(health?.remainingLife)) - } - Divider().frame(height: 32) - CardField(title: "disk.powerOnHours") { - MetricText(value: health?.powerOnHours.map { "\($0) h" } ?? "--") - } - Divider().frame(height: 32) - CardField(title: "disk.localVolumes") { + VStack(spacing: 4) { + field("disk.remainingLife", value: MetricFormat.percent(health?.remainingLife)) Button(action: showVolumes) { - HStack(spacing: 2) { - Text("disk.viewDetails") + HStack(spacing: 3) { + Text("disk.localVolumes") + Spacer(minLength: 3) Image(systemName: "chevron.right").font(.system(size: 8)) - } - }.buttonStyle(.plain) + }.contentShape(.rect) + } + .buttonStyle(.plain).help(Text("disk.viewDetails")) + .frame(height: 14) } }.font(PanelStyle.label).lineLimit(1) } } + private func field(_ title: LocalizedStringKey, value: String) -> some View { + HStack(spacing: 3) { + Text(title).foregroundStyle(.secondary).help(Text(title)) + Spacer(minLength: 3) + MetricText(value: value).font(PanelStyle.value) + } + .frame(height: 14) + .frame(maxWidth: .infinity) + } } diff --git a/kymo/UI/Components/PanelStyle.swift b/kymo/UI/Components/PanelStyle.swift index 67b5ac7..0a47e5a 100644 --- a/kymo/UI/Components/PanelStyle.swift +++ b/kymo/UI/Components/PanelStyle.swift @@ -10,13 +10,13 @@ enum PanelStyle { static let padding: CGFloat = 10 static let gap: CGFloat = 8 static let titleHeight: CGFloat = 20 - static let plotHeight: CGFloat = 58 + static let plotHeight: CGFloat = 48 } struct CardSeparator: View { var body: some View { Rectangle().fill(.primary.opacity(0.08)).frame(height: 1) - .padding(.vertical, 4) + .padding(.vertical, 2) .accessibilityHidden(true) } } diff --git a/kymoTests/CPUCoreGridChecks.swift b/kymoTests/CPUCoreGridChecks.swift index 4f01cd9..c0ab621 100644 --- a/kymoTests/CPUCoreGridChecks.swift +++ b/kymoTests/CPUCoreGridChecks.swift @@ -5,9 +5,12 @@ import SwiftUI for count in 0...128 { for width in [120.0, 280.0, 430.0, 800.0] { let rows = CPUCoreGridLayout.rowCounts(count: count, width: width) - precondition(rows.reduce(0, +) == count && rows.count <= 3) + precondition(rows.reduce(0, +) == count) if let first = rows.first, let last = rows.last { precondition(last > 0 && first - last <= 1) + let columns = rows.max()! + let cellWidth = (width - Double(columns - 1) * 6) / Double(columns) + precondition(cellWidth >= 16, "Core text must fit a readable cell instead of being forced into three rows") } } } @@ -25,10 +28,13 @@ import SwiftUI precondition(widths.reduce(0, +) <= width + 0.001) for (group, groupWidth) in zip(groups, widths) { let rows = CPUCoreGridLayout.rowCounts(count: group.count, width: groupWidth) - precondition(rows.count <= 3 && rows.reduce(0, +) == group.count) + precondition(rows.reduce(0, +) == group.count) } } } + for width in [CGFloat.nan, .infinity, -.infinity, 0] { + precondition(CPUCoreGridLayout.rowCounts(count: 128, width: width).reduce(0, +) == 128) + } precondition(CPUCoreGrid.groups(count: 3, kinds: [0: .efficiency]).count == 2) print("PASS: balanced core rows at multiple widths and counts") } diff --git a/kymoTests/PanelLayoutChecks.swift b/kymoTests/PanelLayoutChecks.swift index 0824666..b8533e0 100644 --- a/kymoTests/PanelLayoutChecks.swift +++ b/kymoTests/PanelLayoutChecks.swift @@ -14,26 +14,39 @@ import CoreGraphics precondition(visible.insetBy(dx: 16, dy: 16).contains(centered)) } } + let compact = PanelLayout.cardHeights(coreRows: 2, fanCount: 2) + precondition(PanelLayout.cardColumns(columns: 2) == [[.cpu, .gpu, .memory], [.battery, .storage, .network]]) + precondition(PanelLayout.cardColumns(columns: 1).first == PanelCard.allCases) for width: CGFloat in [480, 559, 560, 600, 640, 960] { let size = CGSize(width: width, height: 820) let columns = PanelLayout.columns(width: width) let cardWidth = PanelLayout.cardWidth(size: size) precondition(abs(CGFloat(columns) * cardWidth + CGFloat(columns - 1) * 8 - (width - 20)) < 0.001) - let rows = PanelLayout.rowHeights(columns: columns, coreRows: 3, fanCount: 6) - let requirements: [CGFloat] = [246, 204, 256, 204, 260, 260] - for index in requirements.indices { - precondition(rows[index / columns] >= requirements[index]) - } - precondition(rows.count == (6 + columns - 1) / columns) - precondition(PanelLayout.needsResourceScroll(size: CGSize(width: width, height: 600), rows: rows)) - precondition(!PanelLayout.needsResourceScroll(size: CGSize(width: width, height: 2400), rows: rows)) + let cards = PanelLayout.cardColumns(columns: columns).flatMap { $0 } + precondition(cards.count == 6 && Set(cards) == Set(PanelCard.allCases)) + precondition(PanelLayout.needsResourceScroll(size: CGSize(width: width, height: 500), heights: compact)) + precondition(!PanelLayout.needsResourceScroll(size: CGSize(width: width, height: 2400), heights: compact)) } - precondition(PanelLayout.rowHeights(columns: 2, coreRows: 2, fanCount: 0) == [220, 204, 260]) - precondition(PanelLayout.columns(width: 960) == 2 && PanelLayout.columns(width: 559) == 1 && PanelLayout.columns(width: 640) == 2) - precondition(!PanelLayout.needsResourceScroll(size: CGSize(width: 960, height: 800), rows: [220, 204, 260])) - precondition(!PanelLayout.needsResourceScroll(size: CGSize(width: 640, height: 800), rows: [220, 204, 260]), - "Moving the interval to the footer must let the standard two-column overview fit") - precondition(PanelLayout.needsResourceScroll(size: CGSize(width: 640, height: 760), rows: [220, 204, 260])) + precondition(PanelLayout.columnHeights(columns: 2, heights: compact) == [612, 564]) + precondition(PanelLayout.preferredHeight(width: 640, heights: compact) == 706) + precondition(!PanelLayout.needsResourceScroll(size: CGSize(width: 640, height: 706), heights: compact)) + precondition(PanelLayout.needsResourceScroll(size: CGSize(width: 640, height: 680), heights: compact)) + precondition(PanelLayout.needsResourceScroll(size: CGSize(width: 480, height: 800), heights: compact)) + precondition(PanelLayout.columns(width: 640) == 2 && PanelLayout.columns(width: 559) == 1) + let tallerCPU = PanelLayout.cardHeights(coreRows: 6, fanCount: 2) + precondition(tallerCPU[.cpu]! > compact[.cpu]! && tallerCPU[.battery] == compact[.battery], + "A taller CPU card must not stretch the opposite battery card") + let moreFans = PanelLayout.cardHeights(coreRows: 2, fanCount: 6) + precondition(moreFans[.gpu]! > compact[.gpu]! && moreFans[.storage] == compact[.storage]) + let noFans = PanelLayout.cardHeights(coreRows: 2, fanCount: 0) + precondition(noFans[.gpu] == 124 && PanelLayout.preferredHeight(width: 640, heights: noFans) < 706) + precondition(PanelLayout.cardHeights(coreRows: 2, fanCount: nil) == compact, + "Discovery placeholders must reserve the ordinary fan row") + let manyCores = PanelLayout.cardHeights(coreRows: 30, fanCount: 10) + precondition(PanelLayout.preferredHeight(width: 640, heights: manyCores) == 800) + precondition(PanelLayout.needsResourceScroll(size: CGSize(width: 640, height: 800), heights: manyCores)) + let requested = PanelLayout.contentSize(visible: CGRect(x: 0, y: 0, width: 1512, height: 900), preferredHeight: 732) + precondition(requested.height == 732, "A hardware-driven height above the default must be preserved") let input: [ProcessMetrics] = (0..<2000).map { (index: Int) -> ProcessMetrics in let id = ProcessIdentity(pid: Int32(index + 1), seconds: 1, microseconds: 0) let path: String? = index == 42 ? "/test/needle" : nil @@ -61,6 +74,6 @@ import CoreGraphics } let pidSorted = ProcessTableProjection.rows(input, query: "", sorting: [ProcessSort(key: .pid)], order: []) precondition(pidSorted.first?.id.pid == 2000) - print("PASS: physical-row heights, column breakpoints, width conservation, resource scrolling, visible-frame bounds/chrome/negative origins, 2000-row CPU/footprint projection, frozen order, path search and empty results") + print("PASS: independent columns, hardware-driven heights, scroll and screen limits, column breakpoints, width conservation, resource scrolling, visible-frame bounds/chrome/negative origins, 2000-row CPU/footprint projection, frozen order, path search and empty results") } } diff --git a/kymoTests/PanelWindowChecks.swift b/kymoTests/PanelWindowChecks.swift index e735ac6..99dcb01 100644 --- a/kymoTests/PanelWindowChecks.swift +++ b/kymoTests/PanelWindowChecks.swift @@ -22,6 +22,17 @@ import SwiftUI try? await Task.sleep(for: .milliseconds(150)) precondition(controller.panel.isVisible && visible) precondition(controller.panel.firstResponder === controller.panel, "Opening must not focus the interval editor") + let initialSize = controller.panel.contentLayoutRect.size + controller.setPreferredContentHeight(initialSize.height - 24) + let resizeDeadline = ContinuousClock.now.advanced(by: .seconds(2)) + while observedSize.height != initialSize.height - 24 && ContinuousClock.now < resizeDeadline { try? await Task.sleep(for: .milliseconds(20)) } + precondition(observedSize.height == initialSize.height - 24) + let stableFrame = controller.panel.frame + for _ in 0..<10 { controller.setPreferredContentHeight(initialSize.height - 24) } + controller.setPreferredContentHeight(.nan) + precondition(controller.panel.frame == stableFrame, "Unchanged or invalid budgets must not resize the panel") + controller.setPreferredContentHeight(initialSize.height) + try? await Task.sleep(for: .milliseconds(100)) let originalSize = controller.panel.contentLayoutRect.size let compact = CGSize(width: min(760, originalSize.width), height: min(600, originalSize.height)) controller.panel.setContentSize(compact)