feat(settings): 默认启用短动效并提供独立减弱动画选项

This commit is contained in:
2026-11-04 11:53:17 +08:00
parent 40a7a55edf
commit f18f6652ff
23 changed files with 443 additions and 34 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ Kymo 是 macOS 菜单栏资源监控工具。菜单栏常驻品牌图标,点
- 网络:接口切换、收发速率与累计字节、路径状态、本地和公网 IP 及复制。
- 进程:PID、名称、路径、CPU、RSS 和线程数;支持搜索、列排序及复制。
面板支持固定显示、保持唤醒、暂停 / 恢复采样。面板刷新默认 2 秒;默认隐藏停止采样,可显式开启后台趋势并配置间隔(新配置 30 秒)。设置窗口提供系统 / 浅色 / 深色外观、简体中文 / 繁體中文 / English 和关于信息。
面板支持固定显示、保持唤醒、暂停 / 恢复采样。默认采用短时视觉过渡,可在设置开启“减弱动画”;后台记录独立控制。面板刷新默认 2 秒;默认隐藏停止采样,可显式开启后台趋势并配置间隔(新配置 30 秒)。设置窗口提供系统 / 浅色 / 深色外观、简体中文 / 繁體中文 / English 和关于信息。
部分硬件指标依赖机型、驱动与权限,缺失值显示为 `--` 或对应状态。GPU 不提供逐核占用;耗电进程显示系统归属的 CPU 能量区间平均功率,注明可读覆盖范围,不代表完整应用总耗电。指标口径和限制见[监控指标](docs/monitoring.md)。
+1 -1
View File
@@ -10,7 +10,7 @@
| [测试与验证](testing.md) | 独立检查程序、执行方式和人工验收边界 |
| [极致轻量化与进程能耗方案](extreme-efficiency-plan.md) | 实施中:性能预算、逻辑浪费审查、真实能量列表、包体积收敛及分阶段验收 |
首批实施证据见[轻量化实施记录](efficiency-first-batch.md);第二批见[能量列表与纯文字对照记录](efficiency-second-batch.md)。第三批见[原生绘制与进程表记录](efficiency-third-batch.md)。包体积已收敛,真实 CPU 能量列表已实现;内存与长期性能预算仍待通过。
首批实施证据见[轻量化实施记录](efficiency-first-batch.md);第二批见[能量列表与纯文字对照记录](efficiency-second-batch.md)。第三批见[原生绘制与进程表记录](efficiency-third-batch.md);第四批见[动效与效率排查](motion-and-efficiency-plan.md)。包体积已收敛,真实 CPU 能量列表已实现;内存与长期性能预算仍待通过。
2026-11-03 依据当前源码重新整理;同日补充极致轻量化与进程能耗实施方案。此前清理的旧阶段计划、设计概念图和路线图可通过 Git 查询。主题文档描述当前实现,方案中的目标不代表已实现,也不以代码已实现代替运行验收。
+4 -4
View File
@@ -54,7 +54,7 @@ SMARTService(XPC)──→ 温度 / 风扇 / SMART 客户端 ──→ 慢
## XPC 与系统边界
主应用启用 App Sandbox,并声明网络客户端权限以访问公网地址 HTTPS 服务;嵌入的 `SMARTService.xpc` 未启用 App Sandbox,启用 Hardened Runtime。它是按需启动的只读辅助服务,不是 root 守护进程,也不执行 SMC 写操作。
主应用启用 App Sandbox,并声明网络客户端权限以访问公网地址 HTTPS 服务;嵌入的 `SMARTService.xpc` 未启用 App Sandbox,启用 Hardened Runtime。它是按需启动的只读辅助服务,不是 root 守护进程,也不执行 SMC 写操作。本机 CLI adhoc 构建的签名 flags 为 adhoc,Xcode 对此会禁用 Hardened Runtime;工程配置启用不等于本次产物已完成正式开发者签名 / 公证验证。
客户端按包内服务的实际指定签名设置连接要求;服务端要求同 UID,并按所在主应用的实际指定签名校验调用方。温度 / 风扇请求超时 2 秒,SMART 请求超时 15 秒;中断、错误、超时与正常响应统一通过一次性 continuation 完成并关闭连接,完成或取消立即取消超时 DispatchSource;请求支持 Task 取消,包括取消先于安装 continuation 的竞态。包内服务指定签名在客户端进程内只读取一次;每条连接仍设置验证要求。
@@ -68,13 +68,13 @@ CPU / GPU / 风扇合并为一次只读 XPC 请求,按到期类别选择读取
面板和资源卡片使用颜色资产中的不透明背景,顶部操作组使用低透明度静态胶囊背景;不再以全窗口液态玻璃概念图作为实现依据。品牌图标与颜色以 Assets 为运行时来源。
固定 frame 的面板宿主关闭 NSHostingView 自动尺寸协商。趋势图的坐标、图例、悬浮与业务投影继续由 SwiftUI 管理;曲线 / 网格 / 悬浮标记与百分比圆环分别由 UI 层的 NativePanelCurve、NativeMetricRing 使用 Core Graphics 绘制,输入、尺寸或外观变化时才失效,不引入绘制计时器。保留既有 PanelCurveGeometry 的真实时间、缺失值与断点规则。
固定 frame 的面板宿主关闭 NSHostingView 自动尺寸协商。趋势图的坐标、图例、悬浮与业务投影继续由 SwiftUI 管理;曲线 / 网格 / 悬浮标记与百分比圆环分别由 UI 层的 NativePanelCurve、NativeMetricRing 使用 Core Graphics 绘制,静态输入、尺寸或外观变化时失效;默认短过渡由 MetricMotion 向原生 layer 添加有限 CATransition(250 ms),应用不建立逐帧计时器,使用 kCATransition 固定键,结束或取消时移除;每次仅安排一个可取消的 250 ms 清理截止,避免 AppKit backing layer 保留已结束对象,不逐帧更新几何。保留既有 PanelCurveGeometry 的真实时间、缺失值与断点规则。
进程表使用 MenuBar 的 NativeProcessTable(view-based NSTableView),继续消费 ProcessTableProjection 的搜索 / 排序 / 冻结投影。仅创建可见单元格,行数改变时增删尾行,刷新时原地修改可见文本与图像;选择以完整 ProcessIdentity 同步,用户选择 / 排序延后到委托回调之外写回 SwiftUI。原生 Esc 转发至原有分层退出逻辑,右键菜单保留复制能力。共享 ProcessIconCache 将 NSWorkspace 原图绘制为 30×30 像素、15pt 的单一位图,不保留原图;最多 128 项 / 1 MiB 解码像素,30 秒过期、LRU 淘汰、内存压力清空,不启动轮询。其预算不代表系统图标服务内部缓存已受控。
资源显示默认采用静态数字、曲线和进度条;风扇不创建 TimelineView。移除曲线追加过渡任务,保持原有缺失值、断点和悬浮语义。此措施不代表面板内存预算已通过;剩余峰值与 CPU 未达标情况见[第三批记录](efficiency-third-batch.md)。
外观偏好保存独立的 reduceMotion(默认 false),设置提供减弱动画;MenuPanelView 根据手动 / 系统减弱动态效果、实际可见、暂停和睡眠计算并注入 UI 动效策略。默认数字交叉淡入、进度条短过渡、原生曲线连续追加与圆环整值淡入;首次挂载直接显示,真实断点不插值。减弱动画使用静态数字 / 曲线 / 进度条。原生控件在策略禁用或离开窗口时取消过渡;风扇没有持续旋转或 TimelineView。后台记录仍只由 SamplingPreferences 控制,动效偏好不改变采样间隔和历史。此措施不代表面板内存预算已通过;剩余峰值与 CPU 未达标情况见[第三批记录](efficiency-third-batch.md)和[动效与第四批排查](motion-and-efficiency-plan.md)。
`PanelResourceAudit` 与纯文字对照渲染器仅在 Debug 或显式 `KYMO_AUDIT` 编译条件下包含实现;普通 Release 不包含诊断驱动与文字列表实现。测试构建还需设置 `KYMO_RESOURCE_AUDIT=1` 才驱动真实面板测试生命周期,App 只装配调用。正常启动不创建测试任务;该入口不是鼠标 / AX 交互验证。诊断日志仍需 `KYMO_DIAGNOSTICS=1` 显式开启;审计标记附带原生图区数量 / 尺寸、悬浮状态和指针是否在面板内,窗口编号只在可见时读取。
`PanelResourceAudit` 与纯文字对照渲染器仅在 Debug 或显式 `KYMO_AUDIT` 编译条件下包含实现;普通 Release 不包含诊断驱动与文字列表实现。测试构建还需设置 `KYMO_RESOURCE_AUDIT=1` 才驱动真实面板测试生命周期,App 只装配调用。正常启动不创建测试任务;该入口不是鼠标 / AX 交互验证。诊断日志仍需 `KYMO_DIAGNOSTICS=1` 显式开启;实际启用动效的曲线数量以 animatedPlots 记录;审计标记附带原生图区数量 / 尺寸、悬浮状态和指针是否在面板内,窗口编号只在可见时读取。
外部 `system_profiler` / `diskutil` 报告共用 Core 的 `BoundedProcess`(同时编入 XPC Target)。utility 队列阻塞于输出 / 取消 / 退出事件,累计保留输出不超过 256 KiB,最多多读 1 字节判断溢出;10 秒截止、输出超限或调用 Task 取消时 SIGKILL 本轮直接子进程并等待回收。子进程关闭 stdout 后不退出也受截止约束。取消管道唤醒 poll,无周期检查计时器;不杀进程组或其他进程。此取消能力不代表 XPC 连接断开已传播到服务内部 Task,暂停后已启动慢报告的上层取消仍需完善。
+5 -5
View File
@@ -2,7 +2,7 @@
日期:2026-11-03。源码基线:`8333349e93c627b8b1df3802e0d3adac32610472`。
状态:实施中,已完成首批调度 / XPC / 静态显示 / 包体积改动,详见[首批实施记录](efficiency-first-batch.md)。以下设计仍含未实施部分;真实 CPU 能量列表已实现,预算未全部通过;能量与文字对照见[第二批记录](efficiency-second-batch.md),最新绘制 / 表格定位见[第三批记录](efficiency-third-batch.md)。
状态:实施中,已完成首批调度 / XPC / 静态显示 / 包体积改动,详见[首批实施记录](efficiency-first-batch.md)。以下设计仍含未实施部分;真实 CPU 能量列表已实现,预算未全部通过;能量与文字对照见[第二批记录](efficiency-second-batch.md),绘制 / 表格定位见[第三批记录](efficiency-third-batch.md),默认动效与独立后台策略见[第四批记录](motion-and-efficiency-plan.md)。
## 1. 背景与目标
@@ -288,12 +288,12 @@ python3 tools/check.py --configuration Release
| 阶段 | 当前状态 | 证据 / 未完成 |
| --- | --- | --- |
| 方案 | 实施中 | 按首批至第三批记录推进,性能预算保持原值 |
| 方案 | 实施中 | 按首批至第四批记录推进,性能预算保持原值 |
| P0 | 进行中 | 新 Release 复现、字形分配栈、组件隔离与真实面板三轮;仍缺受控 Debug / 完整触发链 |
| P1 | 部分完成 | 批量 XPC / 服务共享 / 独立退避 / 取消超时 / 隐藏需求 / 公网暂停;遮挡、睡眠、息屏、需求代次与有界子进程已补;出口键和慢报告上层取消未完成 |
| P2 | 部分完成 | 静态展示、按域发布、路径缓存;第三批以原生曲线 / 圆环 / 虚拟表格、受限缩略图缓存与静态工具条修正独立绘制路径;完整三轮证据见第三批,内存峰值 / 回落与 CPU 预算尚未全部通过 |
| P3 | 功能已实现,验收未完成 | 真实 CPU 能量、签名 XPC、部分覆盖与边界检查;跨硬件、巨大集合、公平性及额外 CPU 预算待验 |
| P4 | 本轮包体积目标达标 | 第三批普通签名 arm64 app 2,032,456 B / ZIP 1,062,783 B,排除诊断实现;较第二批增加 16,288 B,继续收敛,通用架构 / 公证发行流程待验 |
| P2 | 部分完成 | 默认短过渡 / 可减弱动画、按域发布、路径缓存;第三批以原生曲线 / 圆环 / 虚拟表格、受限缩略图缓存与静态工具条修正独立绘制路径;完整三轮证据见第三批,内存峰值 / 回落与 CPU 预算尚未全部通过 |
| P3 | 功能已实现,验收未完成 | 真实 CPU 能量、签名 XPC、部分覆盖与边界检查;跨硬件、巨大集合、公平性及额外 CPU 预算待验;进程 CPU 列的 Mach 时基错误已另修正 |
| P4 | 本轮包体积目标达标 | 第四批普通签名 arm64 app 2,053,744 B / ZIP 1,072,440 B,排除诊断实现;较第三批增加 21,288 B,继续收敛,通用架构 / 公证发行流程待验 |
| P5 | 未完成 | 短时面板和自动检查不替代 CPU / W / 100 次 / 8 小时与多硬件验收 |
每阶段更新本表及 L01–L16 的结论,记录提交、实测数值、未达标项和原因;架构 / 指标 / 测试事实分别同步主题文档。最终以完整功能、相同条件、关闭诊断的 Release 验收,不以“改完代码”或“编译通过”结束。方案完成后将稳定规则归入主题文档,过程记录保留到问题可审计为止。
+97
View File
@@ -0,0 +1,97 @@
# 动效选项与第四批效率排查
2026-11-04,起点 `065c536`。用户确认:默认保留高视觉体验,设置增加减弱动画;后台记录独立控制;继续排查峰值和 CPU。当前工作区两份字符串目录已有修改,保留原内容,仅提交本轮新增键。
## 目标与范围
Core 的外观偏好保存独立减弱动画值;Settings 提供三语开关;MenuBar 根据实际可见 / 暂停 / 睡眠和系统减弱动态效果传入 UI 动效策略。采样偏好、后台记录、历史 60 点上限及真实能量口径保持独立。UI 继续使用原生曲线 / 圆环 / 虚拟表格和有界图标,避免把内存修复变成仅低资源模式有效。
## 设计
默认减弱动画关闭:数字、进度和曲线 / 圆环有短时过渡。原生曲线 / 圆环由 Core Animation 执行约 0.25 秒的有限交叉淡入,应用不建立逐帧计时器,目标不变不添加过渡,过渡结束回收;每次原生过渡仅安排一次可取消的 250 ms 清理截止,不逐帧唤醒;隐藏、卸载、暂停、息屏、系统睡眠、手动或系统减弱动态效果关闭过渡;原生 layer 过渡立即取消,已提交的短合成过渡至多持续 250 ms。首次挂载直接显示目标,无入场补播;曲线仅在真实连续追加时淡入最终画面,不跨缺失、暂停或长空档添加过渡,不保留额外历史点。不启用持续风扇旋转或常驻帧循环。
高体验保留短过渡,静态工具条继续使用现有背景;玻璃绘制分配问题仍属于需要修复的共有问题,不通过恢复已知高开销路径实现动画。
后台记录使用原有独立开关和后台间隔,默认仍关闭;不因切换动效修改任何采样设置。设置说明明确隐藏停止时会保留空档、开启后台后数据粒度由后台间隔决定。暂停 / 睡眠的真实空档继续保留。
## 阶段与验证
1. 偏好、策略、三语设置与局部短过渡;检查默认 / 持久化、系统优先、暂停 / 隐藏停止、与后台设置互不干扰。
2. Debug / 普通 Release 构建,受影响检查与完整 GUI / 网络回归;原生位图、连续追加 / 断点、卸载取消、过渡完成后无计时源。
3. 同一签名 Release 诊断包顺序比较默认动效和减弱动效,前台 2 秒、相同后台策略及候选覆盖,主程序 / XPC 分列;对重开瞬时分配和活跃 CPU 栈另用工具探查,工具附加数字不当作性能样本。
4. 汇总证据、包大小、未达标项,更新架构 / 测试 / 总方案,清理本轮副本与临时产物,中文提交,不推送。
风险:短过渡仍有额外开销;采样 500 ms 下不得堆积过渡。不得以默认高体验掩盖内存 / CPU 未达预算。实际鼠标 / AX / 局部截图能力逐项实测,客观检查不代替完整视觉和主观手感验收。进程 CPU 百分比、RSS 和 phys_footprint 分开报告。历史数值载荷很小(全局 60 点 17,280 B,每接口 60 点 2,880 B),优先排查重复投影 / 绘制和瞬时分配,不先砍历史点。
## 进度
动效与独立后台控制已实现并验证;CPU 单位错误已修正。内存 / CPU / 功耗预算未完成,实测与剩余项见下。
### 实施说明
- 已接入独立 `appearance.reduceMotion`(默认 false);设置三语开关与后台记录说明分开。系统减弱动态效果 / 实际不可见 / 暂停 / 睡眠使 UI 动效策略关闭,不改 SamplingPreferences。
- 原生曲线和圆环使用有限的 Core Animation / 250 ms 过渡,不逐帧重建几何,不增加历史点。首次直接显示、空档不补动画、卸载取消;数字使用短交叉淡入,进度条短过渡,静态分支不安装数字 transition。
- 新增 MotionPreferencesChecks,原生位图检查扩展过渡完成 / 策略切换 / 空档 / 卸载取消。测试命令行 UserDefaults 的参数域会以字符串表示布尔覆盖,因此仅参数域使用 Foundation 的布尔解释,不写持久域;持久域仍严格识别 Bool。
- 第一版使用系统数字滚动的动效试验出现明显资源上升,未把它当作低资源模式;继续验证整值交叉淡入与原生曲线的成本。模式审计新增 animatedPlots,避免仅按启动参数假定 UI 策略已经生效。
- 第一版每控件 30 Hz 计时器的默认动效首轮约 11.19% 主进程 CPU / 74.60 次每秒 interrupt wakeups,虽淡入数字后稳定足迹约 70.91 MiB,仍不可接受;已全部撤掉应用逐帧计时器,改用原生 layer 的有限 CATransition。此处数值是失败试验,不是最终模式结果。
- 窗口开合另由控制器在 show / hide 时应用用户与系统策略:减弱时禁用 AppKit 窗口过渡,默认交给系统默认动画。审计构建仍由 App 注入关闭窗口开合动画,避免干扰数字 / 图表对照;正式运行不受审计入口影响。
### CPU 口径修正
受控程序 CLOCK_PROCESS_CPUTIME_ID 实耗 0.200000 秒;PROC_PIDTASKINFO 原始计数直接按 ns 仅为 0.004800 秒,rusage 乘本机 125/3 timebase 为 0.200015 秒。确认产品 ProcessMonitor 也误将 task absolute CPU 时间当 ns,导致本机进程表 CPU 少报约 41.67 倍。现改为先整数差分,再按缓存的 mach_timebase_info 转换;零 / 失败 / 身份规则保留。所有进程同一比例转换,不改变能量排名口径;修复不代表程序实际 CPU 消耗增加。新增实际采样 / 受控 CPU 时钟回归,原合成边界显式指定 ns 单位。
前述三轮独立采集器一直正确换算 rusage,因此其 CPU 证据仍有效。最终两个模式的实测在本修正前完成;修正只改变表格 CPU 数值换算,不调整采样 / 动画频率。
## 同构建模式对照
M4 Pro / 48 GiB / macOS 27.2,arm64 签名 KYMO_AUDIT Release,前台 2 秒、后台记录关闭、全部常规资源与候选 / 真实能量保留。每组冷启动隐藏 10 秒,三轮展开 30 / 关闭 30 秒,首轮暂停 10 秒;主程序和 XPC 分开 libproc 累计 CPU(单核 100%),展开 10–30 秒计算。顺序执行且不并行构建或 GUI 检查。AppKit 窗口开合关闭以隔离内容动效,不能当成正式无诊断 Release 长期验收。鼠标由用户正常使用,不能声称全程静止;第二轮减弱组记录过一次图表悬浮,其他标记为 0。
| 模式 / 轮次 | 展开 10–30 秒足迹中位数 MiB | 关闭 30 秒 MiB | 累计峰值 MiB | 主 CPU % | XPC CPU % | 主 interrupt wakeups/s |
| --- | ---: | ---: | ---: | ---: | ---: | ---: |
| 减弱 1 | 67.56 | 58.38 | 72.70 | 3.503 | 0.220 | 10.44 |
| 减弱 2 | 66.78 | 61.77 | 189.63 | 3.014 | 0.191 | 3.25 |
| 减弱 3 | 72.86 | 67.36 | 194.20 | 2.776 | 0.175 | 9.45 |
| 默认 1 | 72.56 | 61.81 | 78.02 | 7.204 | 0.197 | 27.62 |
| 默认 2 | 69.15 | 63.64 | 191.83 | 7.426 | 0.203 | 27.62 |
| 默认 3 | 69.88 | 63.85 | 194.99 | 7.318 | 0.221 | 28.16 |
原生图区在默认组展开实际 enabled 为 6,减弱组为 0;暂停 10 秒、关闭均为 0。两组每轮关闭后宿主弱引用均已释放。两种模式稳定足迹接近,默认动效 CPU 仍明显高于减弱组,所有内存 / CPU / W 预算继续标记未通过,不用提供开关代替继续优化。失败的数字滚动首轮实际 CPU 约 32.65%、累计峰值 256.78 MiB,未采用;改整值淡入 / 撤 CPU 帧计时器避免该回退,但不构成全局达标。
## 最终构建与剩余验证
普通 arm64 Release(不含审计)文件逻辑大小 2,053,744 B,文件分配块合计 2,109,440 B,同格式 ditto ZIP 1,072,440 B;主程序 1,266,816 B、Assets.car 495,784 B、XPC 141,296 B。主程序 / XPC 严格签名通过,没有源码、文档和脚本混入。较第三批逻辑大小增加 21,288 B,本轮继续保持体积目标,但没有进一步缩包。
Debug、普通 Release、KYMO_AUDIT Release 构建通过,只有系统 AppIntents 元数据提示。35 项完整 Swift 检查、211 项三语目录、沙盒权限与实际 HTTPS 200 全部通过。自己的面板内容位图已检查,六张卡片、每核圆环、真实 CPU 能量、进程表与工具条完整显示;这是自己的 NSHostingView 渲染,不等同于 OS 局部截图。
回归发现 AppKit backing layer 对 CATransition 使用固定 `transition` 键,自定义键不能查询 / 取消;已改用 kCATransition。同时在本机独立窗口中观察到完成后的过渡对象仍可被查询,故每个过渡增加一个可取消、可合并的单次截止,确保在 250 ms 后主动移除、停止后不保留截止源;不恢复逐帧 CPU 计时器。原生图形实际窗口的开始 / 完成 / 减弱 / 卸载与窗口系统动效策略检查现已通过。三轮表在截止补强和 CPU 列单位修正前完成,不能将它作为补强后完整重复验收,最终短测另列。
### 最终代码短测
补强动画回收和修正 CPU 列后,同一签名诊断包每模式冷启动,展开 30 秒、暂停 10 秒(仅这一轮,无三轮重复):
| 模式 | 展开 10–30 秒足迹中位 MiB | 首轮累计峰值 MiB | 主 CPU % | XPC CPU % | 主 interrupt wakeups/s |
| --- | ---: | ---: | ---: | ---: | ---: |
| 减弱 | 71.17 | 76.86 | 3.166 | 0.221 | 11.05 |
| 默认 | 71.83 | 78.36 | 7.966 | 0.203 | 29.14 |
此短测核对最终改动,没有覆盖第二次打开,不能替换上面的三轮峰值证据或长期验收;鼠标正常使用,环境工作负载未固定。默认仍有约 8% 主 CPU,减弱约 3%,都未达到原预算。窗口外观 / 主观手感由用户验收。
### 分配与 CPU 栈
本机 `man malloc` 明确:MallocStackLogging=1 默认是 lite,只保存当前分配,无历史;NoCompact 不应被当作已经启用 full 的证明。第一次实际工具返回不能取得 high water,随后显式改成 `MallocStackLogging=full`,并将目录设为本应用沙盒 Data/tmp 下本轮独占的预建子目录,成功取得 full 高水位历史(未修改沙盒或工程安全配置)。
full 探针中物理足迹峰值 384.75 MiB,当前约 259 MiB;工具本身的 Performance Tool Data 约 192.9 MiB,不计入正常模式结果。已记录的 heap + VM 请求量高水位约 76 MB,当前约 74.1 MB,累计约 785.2 MB / 361 万次操作;图形 backing store 路径约 9.8 MB。不能将这个“请求量高水位”当成 phys_footprint,也不能据此排除分配器空闲页 / 碎片、未覆盖的图形记账或其他瞬时资源。尚未得到完整解释正常模式重开约 125 MiB 增量的归因链。
活跃栈可见布局 / CA 提交、原生曲线 CG 绘制及 SwiftUI→NSColor 颜色桥接等开销;没有据此认定单一框架为全部原因。默认动效另采样 5 秒,用于调用链定位,不采用附加工具时的 CPU / 足迹作性能结论。下一步优先同步记录瞬时高峰的 VM 类型与布局创建阶段,再逐项对照重复颜色 / 几何投影、文本与进度条的更新成本;不通过砍历史点或放宽预算收尾。
### 实际界面验证
本轮原生 UI 读取在面板已展开时成功,过去的启动阶段超时不代表全局权限不可用。为避免改变用户偏好,复制本轮应用并仅更换唯一验证 Bundle ID、重签且保留同样 sandbox entitlement;普通和验证包均为本机 adhoc 签名。验证副本默认减弱动画 off、后台 off;通过实际 AX 点击分别打开 / 关闭减弱动画,后台开关保持原状态;打开后台后将间隔用键盘改为 5.0 秒,再开启减弱动画,后台仍 on / 5.0。
实际 Cmd+W 关闭设置、Cmd+, 重新打开成功,状态保持。局部 App 设置截图确认三段设置和间隔控件未被裁切。该独立容器持久值最终为 reduceMotion=true、backgroundEnabled=true、backgroundMilliseconds=5000,用户应用偏好未更改。第三轮面板隐藏 1–30 秒期间实际发布 5 个资源样本,间隔 5.00–5.29 秒,展开时记录 animatedPlots=0,验证后台记录与减弱动画独立。后来审计自动退出,最后一次额外操作因实例不再活动而未执行,不计为通过项。
未验证:本轮真实状态栏图标左 / 右键、面板真实 Esc、多显示器 / 刘海、真实系统睡眠 / 息屏、100 次与 8 小时、WindowServer 增量与实际整机功耗 W。设置按钮点击、实际设置键盘开关、单窗口截图与组件测试分别记录,不相互替代。既有 Xcode 调试实例保留,需重新运行才能载入本次代码。
CPU 单位修正独立提交 `40a7a55`。本轮临时文件 / 构建 / 独占日志目录 / 验证容器在汇总后清理,仅退出本轮精确路径的副本。原两份字符串目录修改保持原样,提交仅增加本任务三条三语设置键。
+11 -1
View File
@@ -50,7 +50,7 @@ xcodebuild -project kymo.xcodeproj -scheme kymo -configuration Debug build
swiftc -parse-as-library -module-cache-path /private/tmp/kymo-core-grid-cache \
kymo/Features/MenuBar/CPUCoreGrid.swift kymo/Core/Services/CPUCoreTopology.swift \
kymo/Core/Extensions/MetricFormat.swift kymo/UI/Components/MetricProgressBar.swift \
kymo/UI/Components/NativeMetricRing.swift \
kymo/UI/Components/NativeMetricRing.swift kymo/UI/Components/MetricMotion.swift \
kymoTests/CPUCoreGridChecks.swift -o /private/tmp/kymo-core-grid-checks
/private/tmp/kymo-core-grid-checks
```
@@ -302,6 +302,16 @@ Release 配置由各 Target 在签名前 strip,保留包外 dSYM;测量必
本轮组件隔离、完整三轮、CPU 与未解决项见[第三批记录](efficiency-third-batch.md)。正式面板局部截图与实际鼠标 / 键盘输入需单独确认;组件像素检查不等同完整面板视觉验收。
## 动效与后台独立控制
当前统一入口共 35 项 Swift 检查。`MotionPreferencesChecks` 验证默认高体验、布尔持久化 / 非法持久类型、命令行参数域覆盖、减弱动画与后台记录 / 间隔互不影响,以及系统减弱 / 可见 / 暂停 / 睡眠策略。`NativeMetricDrawingChecks` 增加真实窗口中的连续追加短过渡、结束撤销、策略关闭、空档不动画和控件卸载取消;组件动效状态不代表完整产品每个帧已截图验收。
同一显式 KYMO_AUDIT Release 顺序运行,使用启动参数 `-appearance.reduceMotion YES` / `NO` 比较;参数域不写入用户偏好,审计的 animatedPlots 核对模式实际生效。后台控制单独固定,不能将动画 / 采样同时改变后称作动效收益。结果与分配 / CPU 排查见[本轮记录](motion-and-efficiency-plan.md)。
## 进程 CPU 实际时钟
`ProcessCPULiveChecks` 使用实际 ProcessMonitor 对本检查程序采样,再执行约 200 ms CPU 工作,与独立 CLOCK_PROCESS_CPUTIME_ID 对照,防止把 Mach CPU tick 当纳秒而在 Apple Silicon 上少报;包含零差分与非法 timebase。不能用纯合成纳秒计数替代此检查。
自己的面板内容位图可用 `KYMO_AUDIT_CAPTURE=1` 在 open1.10 时经 stdout 返回 audit.capture 的 PNG;仅 Debug / KYMO_AUDIT 编入,实现只绘制自身宿主、限制面积,不读取桌面。该操作会增加内存和 CPU,必须单独运行,不纳入资源基线;原始图含本应用展示的进程 / 网络信息,验收后清理。
本轮已实测原生应用 AX 读取、设置按钮点击、隔离副本的动效 / 后台开关、间隔编辑、Cmd+W / Cmd+, 与 App 局部设置截图;精确范围及未验证项见第四批记录。full 分配历史需按本机 `man malloc` 显式设置 MallocStackLogging=full,并提供应用自身可写的既有目录;不能将 lite 的当前分配当成峰值历史。
+3 -1
View File
@@ -49,7 +49,9 @@ import AppKit
menuBar = MenuPanelController(visibility: { [metrics] in metrics.setPanelVisible($0) },
menuTitle: { [language] key in
AppLocalization.string("status." + key, locale: language.locale, table: "StatusItem")
}, openSettings: { [weak self] in self?.settingsCommand() }) { [self] panel in
}, openSettings: { [weak self] in self?.settingsCommand() }, reducedMotion: { [appearance] in
appearance.reduceMotion || PanelResourceAudit.enabled
}) { [self] panel in
if PanelResourceAudit.omitted == "text" {
TextMonitoringAuditView(metrics: self.metrics, appearance: self.appearance)
} else if PanelResourceAudit.omitted == "all" {
@@ -1,5 +1,6 @@
import Foundation
import Observation
import CoreFoundation
nonisolated enum AppAppearance: String, CaseIterable, Identifiable {
case system, light, dark
@@ -11,8 +12,26 @@ final class AppearancePreferences {
@ObservationIgnored private let defaults: UserDefaults
var appearance: AppAppearance { didSet { defaults.set(appearance.rawValue, forKey: "appearance") } }
var reduceMotion: Bool {
didSet { if reduceMotion != oldValue { defaults.set(reduceMotion, forKey: "appearance.reduceMotion") } }
}
init(defaults: UserDefaults = .standard) {
self.defaults = defaults
let value = defaults.object(forKey: "appearance.reduceMotion") as? NSNumber
if defaults.volatileDomain(forName: UserDefaults.argumentDomain)["appearance.reduceMotion"] != nil {
// Foundation represents launch overrides as strings; do not persist them.
reduceMotion = defaults.bool(forKey: "appearance.reduceMotion")
} else {
reduceMotion = value.map { CFGetTypeID($0) == CFBooleanGetTypeID() && $0.boolValue } ?? false
}
appearance = AppAppearance(rawValue: defaults.string(forKey: "appearance") ?? "") ?? .system
}
}
/// Motion changes presentation only; sampling preferences are deliberately absent.
nonisolated enum MetricMotionPolicy {
static func enabled(reduced: Bool, systemReduced: Bool, visible: Bool, paused: Bool, sleeping: Bool) -> Bool {
!reduced && !systemReduced && visible && !paused && !sleeping
}
}
+2 -1
View File
@@ -21,7 +21,7 @@ nonisolated enum SamplingDiagnostics {
try? FileHandle.standardOutput.write(contentsOf: data + Data([10]))
}
static func record(_ snapshot: MetricsSnapshot, event: String = "sample", hiddenHostAlive: Bool? = nil, windowNumber: Int? = nil, hoveredPlots: Int? = nil, nativePlots: Int? = nil, pointerInsidePanel: Bool? = nil, plotBounds: [[Double]]? = nil) {
static func record(_ snapshot: MetricsSnapshot, event: String = "sample", hiddenHostAlive: Bool? = nil, windowNumber: Int? = nil, hoveredPlots: Int? = nil, nativePlots: Int? = nil, pointerInsidePanel: Bool? = nil, plotBounds: [[Double]]? = nil, animatedPlots: Int? = nil) {
guard enabled else { return }
var payload: [String: Any] = [
"event": event, "timestamp": snapshot.date.timeIntervalSince1970,
@@ -36,6 +36,7 @@ nonisolated enum SamplingDiagnostics {
payload["nativePlots"] = nativePlots
payload["pointerInsidePanel"] = pointerInsidePanel
payload["plotBounds"] = plotBounds
payload["animatedPlots"] = animatedPlots
payload["cpu"] = snapshot.cpu?.usage
payload["cores"] = snapshot.cpu?.cores.count
payload["cpuTemperature"] = snapshot.cpuTemperature
@@ -24,16 +24,19 @@ import Observation
private let visibility: (Bool) -> Void
private let menuTitle: (String) -> String
private let openSettings: () -> Void
private let reducedMotion: () -> Bool
private var showingStatusMenu = false
private var isHiding = false
init<Content: View>(installStatusItem: Bool = true, visibility: @escaping (Bool) -> Void,
menuTitle: @escaping (String) -> String = { $0 },
openSettings: @escaping () -> Void = {},
reducedMotion: @escaping () -> Bool = { false },
@ViewBuilder content: @escaping (PanelPresentation) -> Content) {
self.visibility = visibility
self.menuTitle = menuTitle
self.openSettings = openSettings
self.reducedMotion = reducedMotion
self.content = {
let host = NSHostingView(rootView: content($0))
// The controller owns the fixed panel frame; content must not negotiate window limits.
@@ -112,7 +115,12 @@ import Observation
return window.convertToScreen(button.convert(button.bounds, to: nil)).contains(screenPoint)
}
private func applyWindowMotion() {
panel.animationBehavior = reducedMotion() || NSWorkspace.shared.accessibilityDisplayShouldReduceMotion ? .none : .default
}
func show() {
applyWindowMotion()
guard !panel.isVisible else { panel.makeKeyAndOrderFront(nil); return }
place()
presentation.isOpen = true
@@ -136,6 +144,7 @@ import Observation
isHiding = true
defer { isHiding = false }
presentation.isOpen = false
applyWindowMotion()
panel.orderOut(nil)
#if DEBUG || KYMO_AUDIT
if let content = panel.contentView { lastHiddenContent = content }
@@ -75,6 +75,9 @@ struct MenuPanelView: View {
}
.background(Color("PanelBackground"), in: .rect(cornerRadius: 18))
.clipShape(.rect(cornerRadius: 18))
.environment(\.metricAnimationsEnabled, MetricMotionPolicy.enabled(
reduced: preferences.reduceMotion, systemReduced: reduceMotion, visible: metrics.isPanelVisible,
paused: metrics.isPaused, sleeping: metrics.isSystemSleeping || metrics.isDisplaySleeping))
.modifier(AppearanceStyle(preferences: preferences))
}
+15 -1
View File
@@ -30,7 +30,10 @@ import AppKit
windowNumber: controller.panel.isVisible ? controller.panel.windowNumber : nil,
hoveredPlots: views.filter { $0.input?.hoveredIndex != nil }.count, nativePlots: views.count,
pointerInsidePanel: controller.panel.isVisible && controller.panel.frame.contains(NSEvent.mouseLocation),
plotBounds: views.map { [Double($0.bounds.width), Double($0.bounds.height)] })
plotBounds: views.map { [Double($0.bounds.width), Double($0.bounds.height)] },
animatedPlots: views.filter { $0.input?.animates == true }.count)
if event == "open1.10", ProcessInfo.processInfo.environment["KYMO_AUDIT_CAPTURE"] == "1",
let content = controller.panel.contentView { capture(content) }
}
func wait(_ seconds: Int) async { try? await Task.sleep(for: .seconds(seconds)) }
// Pin the test window so unrelated focus changes cannot invalidate a measurement.
@@ -59,6 +62,17 @@ import AppKit
NSApp.terminate(nil)
}
}
/// Captures only our own hosted panel, never the desktop. Excluded from normal Release.
private static func capture(_ content: NSView) {
guard content.bounds.width > 0, content.bounds.height > 0,
content.bounds.width * content.bounds.height <= 1_100_000,
let bitmap = content.bitmapImageRepForCachingDisplay(in: content.bounds) else { return }
content.cacheDisplay(in: content.bounds, to: bitmap)
guard let png = bitmap.representation(using: .png, properties: [:]),
let data = try? JSONSerialization.data(withJSONObject: ["event": "audit.capture", "png": png.base64EncodedString()]) else { return }
try? FileHandle.standardOutput.write(contentsOf: data + Data([10]))
}
/// Uses real connection lifecycle but injects local callbacks; peer auth is tested separately by RPCs.
private static func checkRequestCompletion() async {
for _ in 0..<20 {
@@ -62,12 +62,16 @@ struct AppearanceSettingsView: View {
.tint(.primary)
}
}
Section {
Toggle("motion.reduce", isOn: $preferences.reduceMotion)
Text("motion.help").font(.callout).foregroundStyle(.secondary)
}
Section {
Toggle("sampling.backgroundEnabled", isOn: $sampling.backgroundEnabled)
LabeledContent("sampling.background") {
IntervalControl(milliseconds: $sampling.backgroundMilliseconds)
}.disabled(!sampling.backgroundEnabled)
Text("sampling.backgroundHelp").font(.callout).foregroundStyle(.secondary)
Text("sampling.recordingHelp").font(.callout).foregroundStyle(.secondary)
}
}
.formStyle(.grouped)
+69
View File
@@ -4375,6 +4375,75 @@
}
}
}
},
"motion.reduce" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Reduce animations"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "减弱动画"
}
},
"zh-Hant" : {
"stringUnit" : {
"state" : "translated",
"value" : "減弱動畫"
}
}
}
},
"motion.help" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Use static numbers and charts to reduce drawing work. Background recording is controlled separately. The system Reduce Motion setting takes priority."
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "使用静态数字和曲线以减少绘制。后台记录独立控制,系统“减弱动态效果”优先。"
}
},
"zh-Hant" : {
"stringUnit" : {
"state" : "translated",
"value" : "使用靜態數字和曲線以減少繪製。背景記錄獨立控制,系統「減弱動態效果」優先。"
}
}
}
},
"sampling.recordingHelp" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "When off, hiding the panel stops recording and leaves gaps in charts. When on, recording follows the background interval. Pausing or system sleep stops recording."
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "关闭时,隐藏面板停止记录,图表保留空档。开启后按后台间隔记录;暂停或系统睡眠期间不记录。"
}
},
"zh-Hant" : {
"stringUnit" : {
"state" : "translated",
"value" : "關閉時,隱藏面板停止記錄,圖表保留空檔。開啟後按背景間隔記錄;暫停或系統睡眠期間不記錄。"
}
}
}
}
},
"version" : "1.0"
+31 -5
View File
@@ -8,6 +8,7 @@ struct NativePanelCurve: NSViewRepresentable {
let scales: [Double]
let maximumGap: TimeInterval
var hoveredIndex: Int? = nil
@Environment(\.metricAnimationsEnabled) private var animates
func sizeThatFits(_ proposal: ProposedViewSize, nsView: PlotView, context: Context) -> CGSize? {
// Owners supply explicit geometry; do not query AppKit's intrinsic layout on every update.
@@ -17,7 +18,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))
view.configure(Input(frame: frame, colors: colors, scales: scales, maximumGap: maximumGap, hoveredIndex: hoveredIndex, animates: animates))
}
struct Input: Equatable {
@@ -26,10 +27,14 @@ struct NativePanelCurve: NSViewRepresentable {
let scales: [Double]
let maximumGap: TimeInterval
var hoveredIndex: Int? = nil
var animates = false
}
final class PlotView: NSView {
private(set) var input: Input?
private(set) var drawingFrame: PanelCurveFrame?
private let motion = MetricMotion()
var isAnimating: Bool { motion.isRunning }
override var isFlipped: Bool { true }
override func hitTest(_ point: NSPoint) -> NSView? { nil }
@@ -43,9 +48,30 @@ struct NativePanelCurve: NSViewRepresentable {
func configure(_ value: Input) {
guard input != value else { return }
let previous = input
let changedFrame = previous?.frame != value.frame
input = value
// Keep hover updates from restarting an existing transition.
drawingFrame = value.frame
if !value.animates { motion.stop() }
else if changedFrame {
motion.stop()
if window != nil, let previous, let end = value.frame.dates.last,
!value.frame.boundaryDates.contains(end),
PanelCurveGeometry.isAppend(from: previous.frame.dates, to: value.frame.dates,
maximumGap: value.maximumGap) {
motion.start(on: layer)
}
}
needsDisplay = true
}
private func settle() {
motion.stop(); drawingFrame = input?.frame
}
override func viewDidMoveToWindow() {
super.viewDidMoveToWindow()
if window == nil { settle() }
}
override func setFrameSize(_ newSize: NSSize) {
let changed = frame.size != newSize
super.setFrameSize(newSize)
@@ -71,15 +97,15 @@ struct NativePanelCurve: NSViewRepresentable {
context.move(to: CGPoint(x: 0, y: y)); context.addLine(to: CGPoint(x: bounds.width, y: y))
}
context.strokePath()
guard let input, let first = input.frame.dates.first, let last = input.frame.dates.last,
guard let input, let frame = drawingFrame, let first = input.frame.dates.first, let last = input.frame.dates.last,
!input.colors.isEmpty, !input.scales.isEmpty else { return }
let domain = PanelCurveFrame.domain(previousBegin: nil, previousEnd: nil, begin: first, end: last, progress: 1)
for index in input.frame.series.indices {
for index in frame.series.indices {
let tint = NSColor(input.colors[min(index, input.colors.count - 1)])
let proposedScale = input.scales[min(index, input.scales.count - 1)]
let scale = proposedScale.isFinite && proposedScale > 0 ? proposedScale : 1
let runs = PanelCurveGeometry.runs(dates: input.frame.dates, values: input.frame.series[index],
maximumGap: input.maximumGap, boundaryDates: input.frame.boundaryDates, intervals: input.frame.intervals)
let runs = PanelCurveGeometry.runs(dates: frame.dates, values: frame.series[index],
maximumGap: input.maximumGap, boundaryDates: frame.boundaryDates, intervals: frame.intervals)
context.setFillColor(tint.cgColor)
context.setStrokeColor(tint.cgColor)
context.setLineWidth(1.5)
+9 -3
View File
@@ -1,12 +1,18 @@
import SwiftUI
/// Static numbers avoid per-sample glyph rasterization and transition caches.
/// Short numeric transitions follow the owner-supplied motion policy.
struct AnimatedMetricText: View {
let value: String
@Environment(\.metricAnimationsEnabled) private var animates
var body: some View {
Text(verbatim: value)
.monospacedDigit()
if animates {
Text(verbatim: value).monospacedDigit()
.contentTransition(.opacity)
.animation(.easeInOut(duration: MetricMotion.duration), value: value)
} else {
Text(verbatim: value).monospacedDigit()
}
}
}
+47
View File
@@ -0,0 +1,47 @@
import SwiftUI
import QuartzCore
private struct MetricAnimationsKey: EnvironmentKey {
static let defaultValue = false
}
extension EnvironmentValues {
/// The owner supplies actual visibility and user/system motion policy.
var metricAnimationsEnabled: Bool {
get { self[MetricAnimationsKey.self] }
set { self[MetricAnimationsKey.self] = newValue }
}
}
/// A finite compositor transition; native controls never create per-frame CPU timers.
@MainActor final class MetricMotion {
static let duration: TimeInterval = 0.25
private weak var layer: CALayer?
private var deadline: DispatchSourceTimer?
// Core Animation stores every CATransition under this reserved key.
private static let key = kCATransition
var isRunning: Bool { layer?.animation(forKey: Self.key) != nil }
func start(on layer: CALayer?) {
stop()
guard let layer else { return }
self.layer = layer
let transition = CATransition()
transition.type = .fade
transition.duration = Self.duration
transition.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
transition.isRemovedOnCompletion = true
layer.add(transition, forKey: Self.key)
// AppKit backing layers can retain a finished transition; enforce a finite lifetime.
// One coalescible cleanup deadline, never a per-frame CPU callback.
let deadline = DispatchSource.makeTimerSource(queue: .main)
deadline.schedule(deadline: .now() + Self.duration, leeway: .milliseconds(10))
deadline.setEventHandler { [weak self] in MainActor.assumeIsolated { self?.stop() } }
self.deadline = deadline
deadline.resume()
}
func stop() {
deadline?.cancel(); deadline = nil
layer?.removeAnimation(forKey: Self.key); layer = nil
}
deinit { deadline?.cancel() }
}
@@ -4,6 +4,7 @@ import SwiftUI
struct MetricProgressBar: View {
let value: Double
let color: Color
@Environment(\.metricAnimationsEnabled) private var animates
private var fraction: Double { value.isFinite ? min(1, max(0, value)) : 0 }
@@ -15,6 +16,8 @@ struct MetricProgressBar: View {
}
.frame(width: proxy.size.width, height: proxy.size.height)
.clipShape(Capsule())
.animation(animates ? .easeInOut(duration: MetricMotion.duration) : nil, value: fraction)
.transaction { if !animates { $0.disablesAnimations = true } }
}
}
}
+22 -4
View File
@@ -8,6 +8,7 @@ struct NativeMetricRing: NSViewRepresentable {
let lineWidth: CGFloat
let trackOpacity: Double
let inset: CGFloat
@Environment(\.metricAnimationsEnabled) private var animates
func sizeThatFits(_ proposal: ProposedViewSize, nsView: RingView, context: Context) -> CGSize? {
// Owners supply explicit geometry; do not query AppKit's intrinsic layout on every update.
@@ -18,7 +19,7 @@ struct NativeMetricRing: NSViewRepresentable {
func makeNSView(context: Context) -> RingView { RingView() }
func updateNSView(_ view: RingView, context: Context) {
view.configure(Input(value: value.isFinite ? min(1, max(0, value)) : 0, color: color,
lineWidth: lineWidth, trackOpacity: trackOpacity, inset: inset))
lineWidth: lineWidth, trackOpacity: trackOpacity, inset: inset, animates: animates))
}
struct Input: Equatable {
let value: Double
@@ -26,9 +27,13 @@ struct NativeMetricRing: NSViewRepresentable {
let lineWidth: CGFloat
let trackOpacity: Double
let inset: CGFloat
var animates = false
}
final class RingView: NSView {
private(set) var input: Input?
private(set) var displayedValue = 0.0
private let motion = MetricMotion()
var isAnimating: Bool { motion.isRunning }
override var isFlipped: Bool { true }
override func hitTest(_ point: NSPoint) -> NSView? { nil }
init() {
@@ -39,7 +44,20 @@ struct NativeMetricRing: NSViewRepresentable {
required init?(coder: NSCoder) { nil }
func configure(_ value: Input) {
guard value != input else { return }
input = value; needsDisplay = true
let previous = input
input = value
displayedValue = value.value
if !value.animates { motion.stop() }
else if previous?.value != value.value {
motion.stop()
if previous != nil, window != nil { motion.start(on: layer) }
}
needsDisplay = true
}
private func settle() { motion.stop(); displayedValue = input?.value ?? 0; needsDisplay = true }
override func viewDidMoveToWindow() {
super.viewDidMoveToWindow()
if window == nil { settle() }
}
override func setFrameSize(_ newSize: NSSize) {
let changed = newSize != frame.size
@@ -59,10 +77,10 @@ struct NativeMetricRing: NSViewRepresentable {
context.setLineWidth(input.lineWidth); context.setLineCap(.round)
context.setStrokeColor(tint.withAlphaComponent(input.trackOpacity).cgColor)
context.strokeEllipse(in: CGRect(x: center.x - radius, y: center.y - radius, width: radius * 2, height: radius * 2))
guard input.value > 0 else { return }
guard displayedValue > 0 else { return }
context.setStrokeColor(tint.cgColor)
context.addArc(center: center, radius: radius, startAngle: -.pi / 2,
endAngle: -.pi / 2 + 2 * .pi * input.value, clockwise: false)
endAngle: -.pi / 2 + 2 * .pi * displayedValue, clockwise: false)
context.strokePath()
}
}
+41
View File
@@ -0,0 +1,41 @@
import Foundation
@main struct MotionPreferencesChecks {
@MainActor static func main() {
let suite = "kymo.motion." + UUID().uuidString
let defaults = UserDefaults(suiteName: suite)!
defer { defaults.removePersistentDomain(forName: suite) }
let sampling = SamplingPreferences(defaults: defaults)
let appearance = AppearancePreferences(defaults: defaults)
precondition(!appearance.reduceMotion && !sampling.backgroundEnabled)
let interval = sampling.backgroundMilliseconds
appearance.reduceMotion = true
precondition(AppearancePreferences(defaults: defaults).reduceMotion)
precondition(!sampling.backgroundEnabled && sampling.backgroundMilliseconds == interval)
sampling.backgroundEnabled = true; sampling.backgroundMilliseconds = 5_000
appearance.reduceMotion = false
precondition(sampling.backgroundEnabled && sampling.backgroundMilliseconds == 5_000)
precondition(!AppearancePreferences(defaults: defaults).reduceMotion)
for value in ["YES" as Any, 1 as Any] {
defaults.set(value, forKey: "appearance.reduceMotion")
precondition(!AppearancePreferences(defaults: defaults).reduceMotion, "Invalid persisted types must retain the default")
}
let previousArguments = defaults.volatileDomain(forName: UserDefaults.argumentDomain)
defaults.setVolatileDomain(["appearance.reduceMotion": "YES"], forName: UserDefaults.argumentDomain)
precondition(AppearancePreferences(defaults: defaults).reduceMotion, "Launch overrides must be honored without writing persistent settings")
defaults.setVolatileDomain(previousArguments, forName: UserDefaults.argumentDomain)
for reduced in [false, true] {
for system in [false, true] {
for visible in [false, true] {
for paused in [false, true] {
for sleeping in [false, true] {
let value = MetricMotionPolicy.enabled(reduced: reduced, systemReduced: system, visible: visible, paused: paused, sleeping: sleeping)
precondition(value == (!reduced && !system && visible && !paused && !sleeping))
}
}
}
}
}
print("PASS: default high-motion preference, persistence/type safety, independent background controls and system/visibility/pause/sleep policy")
}
}
+35 -1
View File
@@ -7,6 +7,7 @@ import SwiftUI
Task { @MainActor in
let window = NSWindow(contentRect: NSRect(x: 40, y: 40, width: 300, height: 140), styleMask: [.borderless], backing: .buffered, defer: false)
window.isReleasedWhenClosed = false
window.level = .floating
let root = NSView(frame: NSRect(x: 0, y: 0, width: 300, height: 140))
window.contentView = root
let plot = NativePanelCurve.PlotView(); plot.frame = NSRect(x: 0, y: 0, width: 280, height: 60)
@@ -41,8 +42,41 @@ import SwiftUI
ring.configure(NativeMetricRing.Input(value: 1, color: .red, lineWidth: 3, trackOpacity: 0.17, inset: 2))
let full = redPixels(bitmap(ring), opaque: true)
precondition(quarter > 0 && full > quarter * 2, "Ring fraction must change the rendered arc")
// Actual native compositor transitions finish and remove their animation objects.
var moving = continuous
let extendedDates = dates + [Date(timeIntervalSinceReferenceDate: 8)]
moving = NativePanelCurve.Input(frame: PanelCurveFrame(dates: extendedDates, series: [[0.8,0.8,0.8,0.8,0.5]],
intervals: [2,2,2,2,2], boundaryDates: []), colors: [.red], scales: [1], maximumGap: 5, animates: true)
plot.configure(continuous); plot.configure(moving)
precondition(plot.isAnimating)
try? await Task.sleep(for: .milliseconds(400))
precondition(!plot.isAnimating && plot.drawingFrame == moving.frame)
var appended = moving
appended = NativePanelCurve.Input(frame: PanelCurveFrame(dates: extendedDates + [Date(timeIntervalSinceReferenceDate: 10)],
series: [[0.8,0.8,0.8,0.8,0.5,0.2]], intervals: [2,2,2,2,2,2], boundaryDates: []), colors: [.red], scales: [1], maximumGap: 5, animates: true)
plot.configure(appended); precondition(plot.isAnimating)
appended.animates = false; plot.configure(appended)
precondition(!plot.isAnimating && plot.drawingFrame == appended.frame)
let beforeGap = appended
appended = NativePanelCurve.Input(frame: PanelCurveFrame(dates: appended.frame.dates + [Date(timeIntervalSinceReferenceDate: 30)],
series: [[0.8,0.8,0.8,0.8,0.5,0.2,0.7]], intervals: [2,2,2,2,2,2,2], boundaryDates: []), colors: [.red], scales: [1], maximumGap: 5, animates: true)
plot.configure(appended); precondition(!plot.isAnimating, "Do not animate across real gaps")
plot.configure(moving)
var attached = beforeGap; attached.animates = true
plot.configure(attached); precondition(plot.isAnimating)
plot.removeFromSuperview(); precondition(!plot.isAnimating)
ring.configure(NativeMetricRing.Input(value: 0, color: .red, lineWidth: 3, trackOpacity: 0.17, inset: 2, animates: true))
precondition(ring.isAnimating)
try? await Task.sleep(for: .milliseconds(400))
precondition(!ring.isAnimating && ring.displayedValue == 0)
ring.configure(NativeMetricRing.Input(value: 0.8, color: .red, lineWidth: 3, trackOpacity: 0.17, inset: 2, animates: true))
precondition(ring.isAnimating)
ring.configure(NativeMetricRing.Input(value: 0.8, color: .red, lineWidth: 3, trackOpacity: 0.17, inset: 2))
precondition(!ring.isAnimating && ring.displayedValue == 0.8)
ring.configure(NativeMetricRing.Input(value: 0.2, color: .red, lineWidth: 3, trackOpacity: 0.17, inset: 2, animates: true))
ring.removeFromSuperview(); precondition(!ring.isAnimating && ring.displayedValue == 0.2)
window.orderOut(nil); window.close()
print("PASS: native curve pixels, real gaps, missing series, hover, appearance, duplicate-input invalidation and zero/quarter/full ring pixels")
print("PASS: native curve pixels, real gaps, missing series, hover, appearance, duplicate-input invalidation zero/quarter/full ring pixels and finite transitions/gap/policy/unmount cancellation")
fflush(stdout); NSApp.terminate(nil)
}
NSApp.run()
+7 -2
View File
@@ -8,14 +8,16 @@ import SwiftUI
Task { @MainActor in
var visible = false
var settingsRequests = 0
var reducedMotion = true
let controller = MenuPanelController(installStatusItem: false, visibility: { visible = $0 },
openSettings: { settingsRequests += 1 }) { _ in
openSettings: { settingsRequests += 1 }, reducedMotion: { reducedMotion }) { _ in
IntervalControl(milliseconds: .constant(1000))
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
precondition(!controller.presentation.isPinned)
precondition(controller.statusMenu().items.map(\.title) == ["open", "settings", "", "quit"])
controller.show()
precondition(controller.panel.animationBehavior == .none)
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")
@@ -73,10 +75,13 @@ import SwiftUI
precondition(controller.panel.level == .normal)
controller.dismissForOutsideInteraction()
precondition(!controller.panel.isVisible)
reducedMotion = false
controller.show()
precondition(controller.panel.animationBehavior == (NSWorkspace.shared.accessibilityDisplayShouldReduceMotion ? .none : .default))
controller.presentation.isPinned = true
controller.shutdown()
precondition(!controller.presentation.isPinned && !visible)
print("PASS: real NSPanel visibility/centering/key eligibility, outside-dismiss policy, floating pin, explicit close/reopen, unpin and shutdown reset")
print("PASS: real NSPanel visibility/centering/key eligibility, outside-dismiss policy, floating pin, explicit close/reopen, unpin, window motion policy and shutdown reset")
NSApp.terminate(nil)
}
NSApp.run()
+4 -3
View File
@@ -24,13 +24,14 @@ CHECKS.update({
"SensorScheduleChecks": ["kymo/Core/Services/SensorSchedule.swift"],
"TrendScrollChecks": CORE + ["kymo/UI/Charts/TrendScroll.swift"],
"CPUCoreGridChecks": ["kymo/Features/MenuBar/CPUCoreGrid.swift", "kymo/Core/Services/CPUCoreTopology.swift",
"kymo/Core/Extensions/MetricFormat.swift", "kymo/UI/Components/MetricProgressBar.swift", "kymo/UI/Components/NativeMetricRing.swift"],
"kymo/Core/Extensions/MetricFormat.swift", "kymo/UI/Components/MetricProgressBar.swift", "kymo/UI/Components/NativeMetricRing.swift", "kymo/UI/Components/MetricMotion.swift"],
"CPUTemperatureChecks": ["kymo/Core/Monitors/CPUTemperatureMonitor.swift"],
"DiskHealthChecks": ["kymo/Core/Models/DiskHealthMetrics.swift", "kymo/Core/Monitors/DiskHealthReport.swift"],
"PublicIPAddressChecks": ["kymo/Core/Services/PublicIPAddressService.swift"],
"NativeMetricDrawingChecks": ["kymo/UI/Charts/NativePanelCurve.swift", "kymo/UI/Charts/PanelCurveFrame.swift",
"kymo/UI/Charts/PanelCurveGeometry.swift", "kymo/UI/Components/NativeMetricRing.swift"],
"kymo/UI/Charts/PanelCurveGeometry.swift", "kymo/UI/Components/NativeMetricRing.swift", "kymo/UI/Components/MetricMotion.swift"],
"ProcessCPULiveChecks": ["kymo/Core/Models/ProcessMetrics.swift", "kymo/Core/Monitors/ProcessMonitor.swift"],
"MotionPreferencesChecks": ["kymo/Core/Services/AppearancePreferences.swift", "kymo/Core/Services/SamplingPreferences.swift"],
"NetworkAddressChecks": ["kymo/Core/Monitors/NetworkMonitor.swift"],
"ProcessIconCacheChecks": ["kymo/Features/MenuBar/ProcessIconCache.swift"],
"NativeProcessTableChecks": ["kymo/Core/Models/ProcessMetrics.swift", "kymo/Features/MenuBar/ProcessTableProjection.swift",
@@ -42,7 +43,7 @@ CHECKS.update({
"kymo/Features/MenuBar/ProcessTableProjection.swift"],
"PanelCurveChecks": ["kymo/UI/Charts/PanelCurveGeometry.swift", "kymo/UI/Charts/PanelCurveFrame.swift"],
"FanChecks": ["kymo/Core/Models/FanMetrics.swift", "kymo/Core/Monitors/CPUTemperatureMonitor.swift",
"kymo/UI/Components/FanSpeedIndicator.swift", "kymo/UI/Components/AnimatedMetricText.swift"],
"kymo/UI/Components/FanSpeedIndicator.swift", "kymo/UI/Components/AnimatedMetricText.swift", "kymo/UI/Components/MetricMotion.swift"],
"KeepAwakeChecks": ["kymo/Core/Services/KeepAwakeService.swift"],
"LocalizationChecks": ["kymo/Core/Services/LanguagePreferences.swift", "kymo/UI/Components/AppLocalization.swift"],
"CodeIdentityChecks": ["kymo/Core/Services/CodeIdentity.swift"],