perf(ui): 移除监控动效并精简原生图表绘制
This commit is contained in:
+4
-4
@@ -13,14 +13,14 @@
|
||||
|
||||
### 性能
|
||||
|
||||
- 资源卡片使用独立原生宿主,缩小数字动画和局部状态更新影响的呈现范围;保留系统数字滚动、平滑曲线和圆环插值。
|
||||
- 常规采样允许系统合并定时唤醒,原生动画共用一次性收尾调度;暂停、隐藏和卸载仍立即取消。
|
||||
- 保留现有彩色卡片和原生自绘图表,数字、曲线、圆环、进度条统一随采样静态更新;移除滚动、插值、渐变填充、模糊材质和装饰阴影。
|
||||
- 常规采样允许系统合并定时唤醒;静态呈现删除动画调度与过渡状态,保留暂停、隐藏和卸载生命周期。
|
||||
- 复用网络计数读取缓冲,保持 64 位计数、地址格式和接口变化时的差分基线规则。
|
||||
|
||||
### 验证
|
||||
|
||||
- 新增卡片宿主的真实窗口检查,覆盖数字动画中间帧、环境继承、状态保留、尺寸和卸载;扩展动画重定向与连续网络读取检查。
|
||||
- 本地测试包版本为 1.1(2);资源对照条件、结果与剩余验收见 `docs/v1.1-efficiency-plan.md`。
|
||||
- 真实窗口检查覆盖静态文字 / 图表更新、环境继承、状态保留、尺寸、无动画 / 渐变层和卸载;保留连续网络读取与实际采样检查。
|
||||
- 本地测试包版本为 1.1(3);移除减弱动画开关,旧偏好不影响静态呈现。改造、资源对照与剩余验收见 `docs/static-presentation-plan.md`。
|
||||
|
||||
## [0.1.0] - 2026-10-29
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ Kymo 是 macOS 菜单栏资源监控工具。菜单栏常驻品牌图标,点
|
||||
- 网络:接口切换、收发速率与累计字节、路径状态、本地和公网 IP 及复制。
|
||||
- 进程:PID、名称、路径、CPU、内存 footprint 和线程数;支持搜索、列排序及复制。
|
||||
|
||||
面板支持固定显示、保持唤醒、暂停 / 恢复采样。默认保留数字滚动、曲线平滑移动和圆环连续变化,可在设置开启“减弱动画”;后台记录独立控制。面板刷新默认 2 秒;默认隐藏停止采样,可显式开启后台趋势并配置间隔(新配置 30 秒)。设置窗口提供系统 / 浅色 / 深色外观、简体中文 / 繁體中文 / English 和关于信息。
|
||||
面板支持固定显示、保持唤醒、暂停 / 恢复采样。保留彩色卡片,数字、曲线、圆环和进度条随采样直接更新,不播放应用自定义动画或背景模糊特效;后台记录独立控制。面板刷新默认 2 秒;默认隐藏停止采样,可显式开启后台趋势并配置间隔(新配置 30 秒)。设置窗口提供系统 / 浅色 / 深色外观、简体中文 / 繁體中文 / English 和关于信息。
|
||||
|
||||
部分硬件指标依赖机型、驱动与权限,缺失值显示为 `--` 或对应状态。GPU 不提供逐核占用;耗电进程显示系统归属的 CPU 能量区间平均功率,注明可读覆盖范围,不代表完整应用总耗电。指标口径和限制见[监控指标](docs/monitoring.md)。
|
||||
|
||||
|
||||
@@ -8,6 +8,6 @@
|
||||
<key>CFBundleName</key><string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key><string>XPC!</string>
|
||||
<key>CFBundleShortVersionString</key><string>1.1</string>
|
||||
<key>CFBundleVersion</key><string>2</string>
|
||||
<key>CFBundleVersion</key><string>3</string>
|
||||
<key>XPCService</key><dict><key>ServiceType</key><string>Application</string></dict>
|
||||
</dict></plist>
|
||||
|
||||
+2
-1
@@ -10,7 +10,8 @@
|
||||
| [测试与验证](testing.md) | 独立检查程序、执行方式和人工验收边界 |
|
||||
| [极致轻量化与进程能耗方案](extreme-efficiency-plan.md) | 实施中:性能预算、逻辑浪费审查、真实能量列表、包体积收敛及分阶段验收 |
|
||||
| [同类开源工具 CPU 与功耗调研](open-source-efficiency-research.md) | Stats、MenuMeters、eul、macmon 的源码机制、与 Kymo 的差异及待验证优化方向 |
|
||||
| [1.1 低开销实施计划](v1.1-efficiency-plan.md) | 保留默认动效的卡片宿主隔离、唤醒合并、缓冲复用与本轮验证 |
|
||||
| [1.1 初版实施记录](v1.1-efficiency-plan.md) | 历史:保留动效的卡片宿主隔离、唤醒合并与缓冲复用 |
|
||||
| [静态呈现与轻量图表](static-presentation-plan.md) | 当前:保留卡片配色,移除动效与特效,原生静态图表与验证 |
|
||||
|
||||
首批实施证据见[轻量化实施记录](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 能量列表已实现;内存与长期性能预算仍待通过。
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
入口为 `kymoApp.main()`,由 `NSApplication` 与 `ApplicationLifecycle` 驱动,当前不使用 `MenuBarExtra`。应用以 accessory 模式启动,通过 `NSHostingSceneRepresentation` 注册 Settings 场景。
|
||||
|
||||
`MenuPanelController` 拥有模板品牌状态项和无边框、可成为 key 的非激活 `MonitoringPanel`。左键切换面板;右键菜单提供打开 / 隐藏、设置和退出。窗口按状态项所在屏幕可见区域定位,水平居中、顶部预留 16pt;最大内容尺寸 1240 × 820pt,并按屏幕缩小。卡片随宽度采用 1 / 2 / 3 列,资源区空间不足时滚动,进程区保留最小高度。
|
||||
`MenuPanelController` 拥有模板品牌状态项和无边框、可成为 key 的非激活 `MonitoringPanel`。左键切换面板;右键菜单提供打开 / 隐藏、设置和退出。面板不播放开关窗动画、不添加装饰阴影。窗口按状态项所在屏幕可见区域定位,水平居中、顶部预留 16pt;最大内容尺寸 1240 × 820pt,并按屏幕缩小。卡片随宽度采用 1 / 2 / 3 列,资源区空间不足时滚动,进程区保留最小高度。
|
||||
|
||||
固定按钮切换普通 / floating 层级。未固定时外部交互或应用失活可收起,固定时仍可通过状态项或显式关闭收起。进程表的 Esc 依次处理搜索、选中和搜索焦点,随后关闭窗口。隐藏面板时先卸载内容视图、关闭底层窗口资源(保留控制器拥有的窗口对象供重开),并停止监听外部鼠标事件;仅显式启用后台趋势时保留常规采样。
|
||||
|
||||
@@ -68,13 +68,13 @@ CPU / GPU / 风扇合并为一次只读 XPC 请求,按到期类别选择读取
|
||||
|
||||
面板和资源卡片使用颜色资产中的不透明背景,顶部操作组使用低透明度静态胶囊背景;不再以全窗口液态玻璃概念图作为实现依据。品牌图标与颜色以 Assets 为运行时来源。
|
||||
|
||||
固定 frame 的面板宿主关闭 NSHostingView 自动尺寸协商。每张 ResourceCard 通过 UI 层 NativeContentHost 获得独立、固定尺寸的 NSHostingView,数字动画和局部状态更新在卡片宿主内处理;父层仍负责列数、卡片尺寸和窗口布局。完整 SwiftUI 环境注入子宿主,保留字体、前景样式、语言、外观与动效策略;更新沿用原有挂载身份,卸载时清空子宿主内容。坐标、图例、悬浮偏好与提示层都保留在同一卡片宿主内,不跨原生边界传递锚点。趋势图的业务投影继续由 Features 管理;曲线 / 网格 / 悬浮标记与百分比圆环分别由 UI 层 NativePanelCurve、NativeMetricRing 绘制。保留 PanelCurveGeometry 的真实时间、缺失值与断点规则。
|
||||
固定 frame 的面板宿主关闭 NSHostingView 自动尺寸协商。每张 ResourceCard 通过 UI 层 NativeContentHost 获得独立、固定尺寸的 NSHostingView,局部数据和状态更新在卡片宿主内处理;父层仍负责列数、卡片尺寸和窗口布局。完整 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 淘汰、内存压力清空,不启动轮询。其预算不代表系统图标服务内部缓存已受控。
|
||||
|
||||
外观偏好保存独立的 reduceMotion(默认 false),设置提供减弱动画;MenuPanelView 根据手动 / 系统减弱动态效果、实际可见、暂停和睡眠计算并注入 UI 动效策略。默认数字沿用原系统 numericText 滚动 / 模糊与 0.35 秒无回弹 spring;曲线按原时间域公式预计算 61 个横向变换关键帧,由 Core Animation 做 0.35 秒 easeInOut 移动;网格与悬浮层独立,路径仅在数据 / 几何改变时构建。满 60 点保留一个出界点,渐变覆盖出界区。圆环由 CAShapeLayer.strokeEnd 做 0.35 秒 easeInOut 弧长插值,中断从 presentation 值继续。有限属性动画共用一个一次性收尾定时器,弱引用注册、按到期时间清理并合并邻近截止;所有动画结束 / 取消后不保留周期定时器。替换动画更新自身截止,旧截止不会停止新动画;清理聚合窗口不改变 0.35 秒运动时长。不使用 opacity 替代,不设逐帧 CPU 定时器。数字相同值由 Equatable 子视图跳过重复求值;首次挂载直接显示,真实断点不插值。减弱动画使用静态数字 / 曲线 / 进度条。原生控件在策略禁用或离开窗口时取消过渡;风扇没有持续旋转或 TimelineView。后台记录仍只由 SamplingPreferences 控制,动效偏好不改变采样间隔和历史。历史失败记录见[第三批记录](efficiency-third-batch.md)和[动效与第四批排查](motion-and-efficiency-plan.md),恢复原动效后的对照见[保留动效的优化记录](motion-preservation-plan.md),1.1 改动与本轮验收见[1.1 计划](v1.1-efficiency-plan.md)。
|
||||
资源监控统一采用静态呈现:MetricText 直接显示最新字符串,圆环和进度条直接使用最终比例;趋势图保留 Core Graphics 贝塞尔路径、网格、真实时间、缺失值断点和悬浮标记,只在数据 / 几何 / 外观变化时更新,不生成过渡帧、移动变换或逐帧任务。曲线不再绘制面积渐变或遮罩;空的尾部序列不创建图层。CATransaction 禁止原生图层隐式动画,面板与设置的 SwiftUI transaction 禁止应用自定义插值。旧 MetricMotion、共享收尾定时器和滚动几何已删除。设置移除减弱动画开关,AppearancePreferences 只管理外观;旧 appearance.reduceMotion 键忽略但不清除,不影响外观、语言和采样偏好。后台记录继续只由 SamplingPreferences 控制。悬浮提示和旧详情窗使用不透明颜色背景,无 NSVisualEffectView、入场缩放 / 淡入及装饰阴影。此决定替代此前保留原动效的方案;历史数据见[1.1 初版记录](v1.1-efficiency-plan.md),当前实现与验收见[静态呈现计划](static-presentation-plan.md)。
|
||||
|
||||
`PanelResourceAudit` 与纯文字对照渲染器仅在 Debug 或显式 `KYMO_AUDIT` 编译条件下包含实现;普通 Release 不包含诊断驱动与文字列表实现。测试构建还需设置 `KYMO_RESOURCE_AUDIT=1` 才驱动真实面板测试生命周期,App 只装配调用。正常启动不创建测试任务;该入口不是鼠标 / AX 交互验证。诊断日志仍需 `KYMO_DIAGNOSTICS=1` 显式开启;实际启用动效的曲线数量以 animatedPlots 记录;审计标记附带原生图区数量 / 尺寸、悬浮状态和指针是否在面板内,窗口编号只在可见时读取。
|
||||
`PanelResourceAudit` 与纯文字对照渲染器仅在 Debug 或显式 `KYMO_AUDIT` 编译条件下包含实现;普通 Release 不包含诊断驱动与文字列表实现。测试构建还需设置 `KYMO_RESOURCE_AUDIT=1` 才驱动真实面板测试生命周期,App 只装配调用。正常启动不创建测试任务;该入口不是鼠标 / AX 交互验证。诊断日志仍需 `KYMO_DIAGNOSTICS=1` 显式开启;静态版保留兼容字段 animatedPlots 并固定为 0;审计标记附带原生图区数量 / 尺寸、悬浮状态和指针是否在面板内,窗口编号只在可见时读取。
|
||||
|
||||
外部 `system_profiler` / `diskutil` 报告共用 Core 的 `BoundedProcess`(同时编入 XPC Target)。utility 队列阻塞于输出 / 取消 / 退出事件,累计保留输出不超过 256 KiB,最多多读 1 字节判断溢出;10 秒截止、输出超限或调用 Task 取消时 SIGKILL 本轮直接子进程并等待回收。子进程关闭 stdout 后不退出也受截止约束。取消管道唤醒 poll,无周期检查计时器;不杀进程组或其他进程。此取消能力不代表 XPC 连接断开已传播到服务内部 Task,暂停后已启动慢报告的上层取消仍需完善。
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
## 适用范围
|
||||
|
||||
当前产物:Kymo 1.1(build 2),macOS 27.0 及以上、Apple silicon arm64。Intel 或较低系统不在该产物支持范围。软件使用 ad-hoc 本地签名,未经过 Apple 公证,不是 Developer ID 官方分发包;下载后的系统提示取决于接收方安全策略。
|
||||
当前产物:Kymo 1.1(build 3),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-2-arm64-adhoc.zip` 和同名 `.sha256`。首次打包前会通过签名、Hardened Runtime、权限和包内容检查,ZIP 解压后再次检查。再次构建不覆盖已存在同名产物,可用 `--output` 另选目录。校验下载文件:
|
||||
默认输出:`dist/kymo-1.1-3-arm64-adhoc.zip` 和同名 `.sha256`。首次打包前会通过签名、Hardened Runtime、权限和包内容检查,ZIP 解压后再次检查。再次构建不覆盖已存在同名产物,可用 `--output` 另选目录。校验下载文件:
|
||||
|
||||
```bash
|
||||
shasum -a 256 -c kymo-1.1-2-arm64-adhoc.zip.sha256
|
||||
shasum -a 256 -c kymo-1.1-3-arm64-adhoc.zip.sha256
|
||||
```
|
||||
|
||||
SHA-256 用于核对文件是否与发布者给出的文件一致,不等同于 Apple 身份认证;校验值应从可信渠道获取。
|
||||
@@ -28,4 +28,4 @@ SHA-256 用于核对文件是否与发布者给出的文件一致,不等同于
|
||||
|
||||
## 本地数据
|
||||
|
||||
保留外观、语言、减弱动画及采样设置;Debug / Release 通常共用 bundle ID 对应偏好。趋势和图标仅缓存于内存。公网查询使用禁用缓存 / Cookie / 凭据持久化的临时会话;macOS 管理的容器元数据、日志和崩溃报告不属于零写盘保证。旧版 HTTP 缓存已在本机退出旧进程后单独清理,这不代表其他安装机器上的旧数据已自动清理。
|
||||
保留外观、语言及采样设置;旧减弱动画键不再使用但不会被主动清除;Debug / Release 通常共用 bundle ID 对应偏好。趋势和图标仅缓存于内存。公网查询使用禁用缓存 / Cookie / 凭据持久化的临时会话;macOS 管理的容器元数据、日志和崩溃报告不属于零写盘保证。旧版 HTTP 缓存已在本机退出旧进程后单独清理,这不代表其他安装机器上的旧数据已自动清理。
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# 保持原动效的实现优化
|
||||
|
||||
后续静态呈现已按用户新要求替代本文的默认动效策略,当前实现见[静态呈现计划](static-presentation-plan.md)。本文保留原实施和测量记录。
|
||||
|
||||
2026-11-04,起点 f18f665。用户明确禁止用渐隐渐现替换原视觉效果。视觉基线取 8333349 的实际实现:数字系统 numericText + 0.35 秒无回弹 spring;曲线真实时间域的 0.35 秒 easeInOut 平滑移动;圆环从顶部顺时针、圆头、0.35 秒 easeInOut 连续伸缩。减弱模式保持静态,后台控制独立。
|
||||
|
||||
## 范围与设计
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
调研日期:2026-11-07。范围是 macOS 菜单栏监控工具 Stats、MenuMeters、eul,以及可借鉴采集实现的 Apple Silicon 命令行工具 macmon。本轮只增加调研文档,不修改采样、动效或应用架构。
|
||||
|
||||
后续改造与验证记录见 [1.1 低开销实施计划](v1.1-efficiency-plan.md);本文保留调研时的版本和判断边界。
|
||||
后续改造与验证记录见 [1.1 初版实施记录](v1.1-efficiency-plan.md)和[静态呈现计划](static-presentation-plan.md);本文保留调研时的版本和判断边界,原动效要求已由用户后续的静态方案替代。
|
||||
|
||||
最值得借鉴的机制是:按实际消费者决定是否采集和绘制、局部更新原生控件、复用采集状态、给周期任务调度容差,以及让两次数据更新之间真正空闲。Kymo 已实现其中多项;当前更值得优先核查的是数字动画与视图更新传播,而不是再次全面替换采集 API。
|
||||
|
||||
@@ -80,7 +80,7 @@ CPU / RAM Top 任务由“功能启用、对应菜单模块启用、菜单打开
|
||||
| 动画收尾 | 每个原生动画对象安排单次清理定时器,容差 10ms | 多对象可形成同一时段的收尾回调,合并收益尚未测量 |
|
||||
| 稳定元数据与缓冲 | 进程路径已缓存;网络每轮仍枚举并格式化地址,计数缓冲每轮分配 | 可考虑事件失效缓存和缓冲复用,预期优先级低于动效 |
|
||||
|
||||
源码入口:[MetricsStore](../kymo/Core/Services/MetricsStore.swift)、[SystemSampler](../kymo/Core/Monitors/SystemSampler.swift)、[AnimatedMetricText](../kymo/UI/Components/AnimatedMetricText.swift)、[NativePanelCurve](../kymo/UI/Charts/NativePanelCurve.swift)、[MetricMotion](../kymo/UI/Components/MetricMotion.swift)、[MenuPanelView](../kymo/Features/MenuBar/MenuPanelView.swift)、[NetworkMonitor](../kymo/Core/Monitors/NetworkMonitor.swift)、[CPUTemperatureMonitor](../kymo/Core/Monitors/CPUTemperatureMonitor.swift)。
|
||||
源码入口:[MetricsStore](../kymo/Core/Services/MetricsStore.swift)、[SystemSampler](../kymo/Core/Monitors/SystemSampler.swift)、[NativePanelCurve](../kymo/UI/Charts/NativePanelCurve.swift)、[MenuPanelView](../kymo/Features/MenuBar/MenuPanelView.swift)、[NetworkMonitor](../kymo/Core/Monitors/NetworkMonitor.swift)、[CPUTemperatureMonitor](../kymo/Core/Monitors/CPUTemperatureMonitor.swift)。当时的 `AnimatedMetricText` 与 `MetricMotion` 已在静态改造中删除,历史实现以 `6304489` 为准。
|
||||
|
||||
### 已有实测提供的线索
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
## 实施顺序
|
||||
|
||||
1. [x] 检查工作区、调用链和已有测试;开始时工作区干净,未发现已有 kymo / SMARTService 进程。
|
||||
2. [ ] 移除应用自定义动效、特效和无消费者的动画实现;更新真实行为检查。
|
||||
3. [ ] 构建并比较现有原生图表静态实现、静态卡片宿主开销;仅保留有价值的结构,不降低数据与功能覆盖。
|
||||
4. [ ] Debug / Release、相关和完整回归、实际面板与可用 UI 工具验证;同机 Release 前后对照,更新架构、测试与分发文档。
|
||||
5. [ ] 提交并交付 1.1(3)测试 ZIP;清理仅本轮创建的进程、临时源码、脚本、采样和构建。
|
||||
2. [x] 移除应用自定义动效、特效和无消费者的动画实现;更新真实行为检查。
|
||||
3. [x] 构建并比较现有原生图表静态实现、静态卡片宿主开销;仅保留有价值的结构,不降低数据与功能覆盖。
|
||||
4. [x] Debug / Release、相关和完整回归、实际面板与可用 UI 工具验证;同机 Release 前后对照,更新架构、测试与分发文档。外部 UI 读取受阻,具体边界见下。
|
||||
5. [x] 交付 1.1(3)测试 ZIP,相关代码随本记录一并提交;清理仅本轮创建的进程、临时源码、脚本、采样和构建。
|
||||
|
||||
## 验证与风险
|
||||
|
||||
@@ -33,4 +33,44 @@
|
||||
|
||||
## 结果记录
|
||||
|
||||
实施与验证完成后在此补充最终保留的绘制 / 宿主方案、测量条件、证据和剩余风险。
|
||||
以下记录最终保留的绘制 / 宿主方案、测量条件、证据和剩余风险。
|
||||
|
||||
### 绘制与宿主的取舍
|
||||
|
||||
保留现有 Core Graphics / CAShapeLayer 自绘路线,曲线仅保留线条和缺失数据的独立点;圆环直接设置终值。删除数字 transition / spring、曲线关键帧与出界过渡点、渐变 / 遮罩、共享动画收尾定时器、小图滚动状态和详情入场任务。空尾序列不创建图层,相同采样输入与悬浮更新复用已构建的路径。
|
||||
|
||||
同机单轮探索,配置前台 2 秒、后台关闭、全部后端:旧 1.1 CPU 约 9.514%,静态保留卡片宿主约 2.451%,静态移除宿主约 2.685%;后两者足迹中位数约 56.27 / 55.56 MiB。未证明移除宿主有实际净收益,保留已有固定尺寸宿主、环境传递与卸载机制,不将单轮微小差异当成稳定结论。主趋势图不换库、不另建绘制引擎。
|
||||
|
||||
相关检查已通过:静态曲线 / 圆环像素与立即稳定、无动画 / 渐变 / 遮罩、悬浮不重建路径、系列增长配色、满历史;静态文字稳定、宿主环境和卸载;旧动效偏好保留、外观与采样独立;时间域 / 数据断点;不透明配色;无开关窗动画 / 阴影与窗口生命周期;采样暂停 / 隐藏 / 睡眠和恢复。完整 Release 回归结果见下。
|
||||
|
||||
### 三轮 Release 资源对照
|
||||
|
||||
本机 Apple M4 Pro、48 GiB、macOS 27.2(26B123)。旧版为 `5787193`,静态版为本次工作区;各自由隔离源码构建 ad-hoc Hardened Runtime Release,显式编入 `KYMO_AUDIT`,使用同一随机测试 bundle ID 的空偏好域,不操作正式应用偏好。完整后端、全部六张卡片和进程表,前台配置 2 秒、后台关闭。测试启动顺序为旧 / 静态 / 移除宿主探索 / 静态 / 旧 / 旧 / 静态,期间不运行构建或 GUI 检查;移除宿主探索不计入正式三轮。
|
||||
|
||||
每轮先隐藏 3 秒、固定并展开 30 秒,以展开后 10–30 秒为统计窗,再关闭 5 秒。外部每 200ms 读取 `proc_pid_rusage` v6,CPU 时间按 `mach_timebase_info` 换算,单核为 100%;CPU 归属功率为 `ri_energy_nj` 区间差分 / 单调时长,足迹为 `ri_phys_footprint` 区间中位数,中断唤醒使用 `ri_interrupt_wkups`。XPC 按该副本的完整可执行路径识别并分列。没有捕图或省略采样,6 个图区尺寸一致,动画图数旧版 6 / 静态 0,悬浮图数均为 0;采样实到间隔中位数约 2.13–2.17 秒,枚举约 900–902 个进程、可读约 531–533 个。
|
||||
|
||||
| 面板展开,主进程 | 旧版第 1 / 2 / 3 轮 | 静态第 1 / 2 / 3 轮 | 三轮中位数旧 → 静态 |
|
||||
| --- | --- | --- | --- |
|
||||
| CPU | 9.514 / 10.271 / 11.680% | 2.451 / 1.934 / 2.337% | 10.271 → 2.337%(约 -77%) |
|
||||
| CPU 归属平均功率 | 0.12934 / 0.12866 / 0.10510 W | 0.03184 / 0.03987 / 0.02776 W | 0.12866 → 0.03184 W |
|
||||
| 中断唤醒 | 38.70 / 36.71 / 37.62 次/秒 | 3.39 / 3.88 / 3.59 次/秒 | 37.62 → 3.59 次/秒 |
|
||||
| 物理足迹 | 61.99 / 61.47 / 59.52 MiB | 56.27 / 58.06 / 54.22 MiB | 61.47 → 56.27 MiB |
|
||||
| 生命周期峰值足迹 | 63.92 / 63.47 / 63.14 MiB | 59.20 / 60.05 / 56.44 MiB | 63.47 → 59.20 MiB |
|
||||
|
||||
同一统计窗的 XPC 三轮中位数:CPU 0.473 → 0.442%,CPU 归属功率 0.00830 → 0.00842 W,足迹 5.02 → 5.17 MiB,中断唤醒均约 0.10 次/秒。后端未显示同等级降幅,主要收益位于主程序呈现。隐藏后第 1–5 秒主进程 CPU 三轮中位数 0.014 → 0.011%,足迹 53.91 → 50.14 MiB;该短窗只能核对停采和短时状态。
|
||||
|
||||
外部应用和系统负载未冻结,能量读取覆盖状态为 waiting / partial;不把温度、整机 GPU 活动或整个 WindowServer 归因给 Kymo。上述为进程 CPU 归属能量和短时资源测量,未测整机瓦数、电池续航、10 分钟稳态或长时泄漏,仍未证明原性能方案的长期预算全部达标。
|
||||
|
||||
### 构建、回归与实际面板
|
||||
|
||||
- 必需 Debug 构建通过;普通 Release 使用 `python3 tools/package_release.py` 构建,未编入 `DEBUG` / `KYMO_AUDIT`。
|
||||
- 从新 ZIP 解压的正式产物运行 `python3 tools/check.py --app <解压后的 kymo.app 绝对路径> --gui --services --network`:36 项 Swift 检查、209 项三语言文案与格式、宿主权限检查全部通过。包含真实 NSPanel、卡片宿主、静态图层像素、语言 / 设置窗口生命周期、进程表、实际采样、Hardened Runtime 沙盒宿主认证 XPC、footprint / CPU 能量 / 传感器 RPC,以及生产 HTTPS 与无持久网络文件检查。
|
||||
- 独立于资源测量,审计副本返回仅自身面板的 2480 × 1640 位图。已查看浅色完整面板:六张彩色圆角卡片、曲线 / 坐标 / 图例、圆环、进度条、顶部操作及进程表布局完整,曲线无面积渐变;不据单帧证明动态或输入行为。浅深色语义资产、图表在深色下绘制及三语言环境由检查程序另外覆盖。
|
||||
- 本轮 Computer Use 通过测试副本完整路径选择应用时约 5 秒读取超时;应用清单无此副本条目。未将其判断为缺失系统授权,未操作其他应用。菜单栏 AX 点击、坐标点击、工具截图、键盘关闭路径均未验证;应用自身位图和程序内窗口检查不能替代这些外部输入路径。
|
||||
- 待用户体验验收:从菜单栏打开 / 关闭,移动鼠标读取曲线提示,固定并重开,切换浅色 / 深色;确认数字、曲线和圆环直接更新。真实多显示器 / 刘海屏、原生菜单和 popover 的系统反馈、长期资源及整机功耗仍未验证。
|
||||
|
||||
### 分发与清理
|
||||
|
||||
本地产物 `dist/kymo-1.1-3-arm64-adhoc.zip`,1,062,822 字节,SHA-256 `1078583cbd2e34dfc366ae2f76103ccc9ad1f0ce91101560cb66b6324a0c4608`。原包 / 解压包签名、Hardened Runtime、精确 entitlements、包内容和最终 SHA-256 校验通过。仅 arm64,最低 macOS 27.0,ad-hoc 签名、未公证;其他机器默认 Gatekeeper 下的启动未验。
|
||||
|
||||
保留旧 build 2 和新 build 3。未安装到 Applications、未推送、未发布。仅清理本轮随机 bundle ID 创建的测试容器及临时根目录中的进程、隔离源码、构建、测量日志和自身面板图片;正式应用偏好与用户进程不在清理范围。
|
||||
|
||||
+15
-18
@@ -2,7 +2,7 @@
|
||||
|
||||
## 当前测试形态
|
||||
|
||||
1.1 新增 `NativeContentHostChecks`(`--gui`):在真实窗口检查系统数字滚动的中间帧、父级颜色 / 语言 / 动效环境继承、更新不重新挂载、固定尺寸和卸载。`NativeMetricDrawingChecks` 另覆盖多个动画合并收尾时的取消及重新定向,不把旧截止应用到新动画;`NetworkAddressChecks` 连续读取 30 轮,核对缓冲复用后的有效速率和地址格式。
|
||||
静态版检查覆盖:`NativeContentHostChecks`(`--gui`)验证数字更新后立即稳定、父级字体 / 颜色 / 语言继承、挂载身份、有限尺寸和卸载;`NativeMetricDrawingChecks` 验证曲线 / 圆环像素、直接更新、无动画 / 渐变 / 遮罩、悬浮不重建路径及满 60 点历史。`AppearancePreferencesChecks` 验证外观持久化、采样独立和旧动效键不被误改。`NetworkAddressChecks` 连续读取 30 轮,核对有效速率和地址格式。
|
||||
|
||||
`kymoTests/` 包含可独立编译的 Swift 检查程序和 Python 字符串检查,工程未创建 XCTest / UI 测试 Target;`kymoUITests/` 目前仅占位。以下命令在仓库根目录执行,每次只编译一个检查入口。需要实际应用包的命令必须传入本轮构建产物的绝对路径。
|
||||
|
||||
@@ -52,7 +52,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/MetricMotion.swift \
|
||||
kymo/UI/Components/NativeMetricRing.swift \
|
||||
kymoTests/CPUCoreGridChecks.swift -o /private/tmp/kymo-core-grid-checks
|
||||
/private/tmp/kymo-core-grid-checks
|
||||
```
|
||||
@@ -96,17 +96,16 @@ swiftc -module-cache-path /private/tmp/kymo-check-cache \
|
||||
/private/tmp/kymo-presentation-checks
|
||||
```
|
||||
|
||||
## 趋势滚动边界检查
|
||||
## 静态趋势边界检查
|
||||
|
||||
```bash
|
||||
swiftc -module-cache-path /private/tmp/kymo-check-cache \
|
||||
kymo/Core/Models/*.swift kymo/Core/Monitors/*.swift \
|
||||
kymo/Core/Services/*.swift kymo/Core/Extensions/*.swift kymo/UI/Charts/TrendScroll.swift \
|
||||
kymoTests/TrendScrollChecks.swift -o /private/tmp/kymo-trend-checks
|
||||
/private/tmp/kymo-trend-checks
|
||||
swiftc -parse-as-library -module-cache-path /private/tmp/kymo-chart-cache \
|
||||
kymo/UI/Charts/PanelCurveGeometry.swift kymo/UI/Charts/PanelCurveFrame.swift \
|
||||
kymoTests/PanelCurveChecks.swift -o /private/tmp/kymo-curve-checks
|
||||
/private/tmp/kymo-curve-checks
|
||||
```
|
||||
|
||||
覆盖追加识别、缺失值、未满及满 60 点时的起止位置;不证明实际动画手感。
|
||||
覆盖真实时间域、满 60 点历史、缺失值与非有限值、长采样周期、暂停断点和不规则时间戳;图层像素与无动画状态由 GUI 检查另验。
|
||||
|
||||
## 多语言行为检查
|
||||
|
||||
@@ -237,7 +236,7 @@ swiftc kymo/Core/Models/*.swift kymo/Core/Monitors/*.swift \
|
||||
|
||||
```bash
|
||||
swiftc 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/MetricText.swift \
|
||||
kymoTests/FanChecks.swift -o /private/tmp/kymo-fan-checks
|
||||
/private/tmp/kymo-fan-checks
|
||||
```
|
||||
@@ -304,11 +303,11 @@ Release 配置由各 Target 在签名前 strip,保留包外 dSYM;测量必
|
||||
|
||||
本轮组件隔离、完整三轮、CPU 与未解决项见[第三批记录](efficiency-third-batch.md)。正式面板局部截图与实际鼠标 / 键盘输入需单独确认;组件像素检查不等同完整面板视觉验收。
|
||||
|
||||
## 动效与后台独立控制
|
||||
## 静态呈现与后台记录
|
||||
|
||||
当前统一入口共 36 项 Swift 检查。`MotionPreferencesChecks` 验证默认高体验、布尔持久化 / 非法持久类型、命令行参数域覆盖、减弱动画与后台记录 / 间隔互不影响,以及系统减弱 / 可见 / 暂停 / 睡眠策略。`NativeMetricDrawingChecks` 增加真实窗口中的连续追加短过渡、结束撤销、策略关闭、空档不动画和控件卸载取消;组件动效状态不代表完整产品每个帧已截图验收。
|
||||
界面统一静态刷新,不再提供减弱动画开关,也不再接受该旧偏好改变呈现。`AppearancePreferencesChecks` 检查旧键保持原值、外观与后台记录互不影响;`SamplingIntervalChecks` 继续覆盖暂停、隐藏、睡眠、恢复和历史断点。
|
||||
|
||||
同一显式 KYMO_AUDIT Release 顺序运行,使用启动参数 `-appearance.reduceMotion YES` / `NO` 比较;参数域不写入用户偏好,审计的 animatedPlots 核对模式实际生效。后台控制单独固定,不能将动画 / 采样同时改变后称作动效收益。结果与分配 / CPU 排查见[本轮记录](motion-and-efficiency-plan.md)。
|
||||
此前保留动效和命令行减弱模式的实验属于历史,见[动效排查](motion-and-efficiency-plan.md)与[保留动效记录](motion-preservation-plan.md)。本次以相同采样配置比较旧 1.1 和静态版,不通过同时停采获取虚假动效收益。当前测量与工具能力以[静态呈现计划](static-presentation-plan.md)的本轮记录为准。
|
||||
|
||||
## 进程 CPU 实际时钟
|
||||
|
||||
@@ -316,13 +315,11 @@ Release 配置由各 Target 在签名前 strip,保留包外 dSYM;测量必
|
||||
|
||||
自己的面板内容位图可用 `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 的当前分配当成峰值历史。
|
||||
历史第四批的 AX / 截图结果不代表当前工具可用;每轮重新核查并记录具体受阻路径。full 分配历史需按本机 `man malloc` 显式设置 MallocStackLogging=full;不能将 lite 的当前分配当成峰值历史。
|
||||
|
||||
## 保留原动效的回归
|
||||
## 历史动效回归
|
||||
|
||||
当前默认数字沿用原 numericText + spring;曲线和圆环分别验证 transform 关键帧与 strokeEnd 中间值,明确禁止用 CATransition 淡入替代。NativeMetricDrawingChecks 检查网格不动、动画期间及悬浮不重建路径、满 60 点的出界渐变、真实断点、禁用与卸载取消。PanelCurveChecks 对增长 / 满历史 / 非均匀时间戳的中间横坐标逐项核对原时间域公式。图层位图检查不能替代滚动模糊和动态观感验收。
|
||||
|
||||
相同后端、2 秒刷新、后台关闭的三轮 Release 对照与未达标项见[保留动效的优化记录](motion-preservation-plan.md)。记录主进程与 XPC 的实际 CPU 时间,使用 Mach timebase 换算;CPU 百分比以单核为 100%,不以自有列表的瞬时值替代区间测量。未测实际瓦数或长时能耗。
|
||||
原 numericText、曲线关键帧和圆环插值检查已随静态方案移除,不能再作为当前产品行为。旧三轮 Release 对照与当时未达标项保留在[历史记录](motion-preservation-plan.md);当前结论见[静态呈现计划](static-presentation-plan.md)。
|
||||
|
||||
## 进程内存口径回归
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# 1.1 低开销实施计划
|
||||
|
||||
后续静态呈现已按用户新要求替代本文的默认动效策略,当前实现见[静态呈现计划](static-presentation-plan.md)。本文保留原实施和测量记录。
|
||||
|
||||
2026-11-07。基于[同类开源工具调研](open-source-efficiency-research.md),继续使用 Swift / SwiftUI / AppKit;默认保留数字滚动、曲线平滑移动和圆环连续变化,后台趋势与动效控制独立。版本目标为 1.1,不包含推送、发布或技术栈迁移。
|
||||
|
||||
## 背景与目标
|
||||
|
||||
@@ -425,7 +425,7 @@
|
||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
CURRENT_PROJECT_VERSION = 2;
|
||||
CURRENT_PROJECT_VERSION = 3;
|
||||
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 = 2;
|
||||
CURRENT_PROJECT_VERSION = 3;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
ENABLE_APP_SANDBOX = YES;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
|
||||
@@ -49,9 +49,7 @@ 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() }, reducedMotion: { [appearance] in
|
||||
appearance.reduceMotion || PanelResourceAudit.enabled
|
||||
}) { [self] panel in
|
||||
}, openSettings: { [weak self] in self?.settingsCommand() }) { [self] panel in
|
||||
if PanelResourceAudit.omitted == "text" {
|
||||
TextMonitoringAuditView(metrics: self.metrics, appearance: self.appearance)
|
||||
} else if PanelResourceAudit.omitted == "all" {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"red": "0.990",
|
||||
"green": "0.990",
|
||||
"blue": "0.995",
|
||||
"alpha": "0.970"
|
||||
"alpha": "1.000"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -20,7 +20,7 @@
|
||||
"red": "0.130",
|
||||
"green": "0.150",
|
||||
"blue": "0.180",
|
||||
"alpha": "0.970"
|
||||
"alpha": "1.000"
|
||||
}
|
||||
},
|
||||
"appearances": [
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import Foundation
|
||||
import Observation
|
||||
import CoreFoundation
|
||||
|
||||
nonisolated enum AppAppearance: String, CaseIterable, Identifiable {
|
||||
case system, light, dark
|
||||
@@ -12,26 +11,8 @@ 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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ struct GPUStatisticsView: View {
|
||||
HStack(spacing: 4) {
|
||||
Text(title).foregroundStyle(.secondary)
|
||||
Spacer(minLength: 0)
|
||||
AnimatedMetricText(value: MetricFormat.bytes(bytes)).font(PanelStyle.value)
|
||||
MetricText(value: MetricFormat.bytes(bytes)).font(PanelStyle.value)
|
||||
}.font(PanelStyle.label).lineLimit(1)
|
||||
MetricProgressBar(value: bytes.map { Double($0) / reference } ?? 0, color: color)
|
||||
.frame(height: 3)
|
||||
|
||||
@@ -22,11 +22,11 @@ struct MemoryDetailsView: View {
|
||||
CardField(title: "memory.pressure") { pressure }
|
||||
Divider().frame(height: 32)
|
||||
CardField(title: "memory.cached") {
|
||||
AnimatedMetricText(value: MetricFormat.memory(memory.cached))
|
||||
MetricText(value: MetricFormat.memory(memory.cached))
|
||||
}
|
||||
Divider().frame(height: 32)
|
||||
CardField(title: "memory.swap") {
|
||||
AnimatedMetricText(value: MetricFormat.memory(memory.swapUsed))
|
||||
MetricText(value: MetricFormat.memory(memory.swapUsed))
|
||||
}
|
||||
}.font(PanelStyle.label).lineLimit(1)
|
||||
}
|
||||
|
||||
@@ -24,19 +24,16 @@ 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.
|
||||
@@ -48,7 +45,8 @@ import Observation
|
||||
panel.isReleasedWhenClosed = false
|
||||
panel.isOpaque = false
|
||||
panel.backgroundColor = .clear
|
||||
panel.hasShadow = true
|
||||
panel.hasShadow = false
|
||||
panel.animationBehavior = .none
|
||||
panel.hidesOnDeactivate = false
|
||||
panel.collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary]
|
||||
panel.dismiss = { [weak self] in self?.hide() }
|
||||
@@ -115,12 +113,7 @@ 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
|
||||
@@ -144,7 +137,6 @@ 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 }
|
||||
|
||||
@@ -74,7 +74,7 @@ extension MenuPanelView {
|
||||
CardField(title: title) {
|
||||
HStack(spacing: 3) {
|
||||
Image(systemName: symbol).foregroundStyle(color)
|
||||
AnimatedMetricText(value: value)
|
||||
MetricText(value: value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ extension MenuPanelView {
|
||||
HStack(alignment: .firstTextBaseline) {
|
||||
Text(key).font(PanelStyle.label).foregroundStyle(.secondary)
|
||||
Spacer(minLength: 6)
|
||||
AnimatedMetricText(value: value).font(PanelStyle.value)
|
||||
MetricText(value: value).font(PanelStyle.value)
|
||||
}.frame(height: 14)
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ extension MenuPanelView {
|
||||
HStack {
|
||||
Text("cpu.load.oneMinute", tableName: "CPUDetails").foregroundStyle(.secondary)
|
||||
Spacer(minLength: 3)
|
||||
AnimatedMetricText(
|
||||
MetricText(
|
||||
value: snapshot.load.first.map { "\(MetricFormat.decimal($0)) / \(snapshot.cpu?.cores.count ?? 0)" } ?? "--")
|
||||
}
|
||||
MetricProgressBar(
|
||||
@@ -60,7 +60,7 @@ extension MenuPanelView {
|
||||
Rectangle().fill(.primary.opacity(0.08)).frame(width: 1, height: 25)
|
||||
VStack(alignment: .leading, spacing: 3) {
|
||||
Text("panel.uptime").foregroundStyle(.secondary)
|
||||
AnimatedMetricText(value: String(format: "%.1f h", snapshot.uptime / 3600))
|
||||
MetricText(value: String(format: "%.1f h", snapshot.uptime / 3600))
|
||||
.fontWeight(.medium)
|
||||
}
|
||||
}.font(PanelStyle.label).lineLimit(1)
|
||||
@@ -109,7 +109,7 @@ extension MenuPanelView {
|
||||
HStack(spacing: 8) {
|
||||
Text(title).font(PanelStyle.label).frame(width: 100, alignment: .leading)
|
||||
MetricProgressBar(value: value ?? 0, color: color).frame(height: 5)
|
||||
AnimatedMetricText(value: MetricFormat.percent(value)).font(PanelStyle.value).frame(width: 30, alignment: .trailing)
|
||||
MetricText(value: MetricFormat.percent(value)).font(PanelStyle.value).frame(width: 30, alignment: .trailing)
|
||||
}.font(PanelStyle.label)
|
||||
}
|
||||
var memoryCard: some View {
|
||||
@@ -225,7 +225,7 @@ extension MenuPanelView {
|
||||
if battery.externalPower {
|
||||
Text("battery.timeNotApplicable").font(PanelStyle.value)
|
||||
} else if let minutes = battery.minutesRemaining {
|
||||
AnimatedMetricText(value: "\(minutes) min").font(PanelStyle.value)
|
||||
MetricText(value: "\(minutes) min").font(PanelStyle.value)
|
||||
} else {
|
||||
Text("battery.timeUnknown").font(PanelStyle.value)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ struct MenuPanelView: View {
|
||||
var presentation = PanelPresentation()
|
||||
var onOpenSettings: () -> Void = {}
|
||||
@Environment(\.locale) var locale
|
||||
@Environment(\.accessibilityReduceMotion) var reduceMotion
|
||||
@State private var panelSize = PanelLayout.contentSize(visible: NSScreen.main?.visibleFrame ?? CGRect(x: 0, y: 0, width: 1000, height: 760))
|
||||
@State var selectedInterface = ""
|
||||
@State var publicIPAddress: String?
|
||||
@@ -75,9 +74,7 @@ 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))
|
||||
.transaction { $0.animation = nil; $0.disablesAnimations = true }
|
||||
.modifier(AppearanceStyle(preferences: preferences))
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import AppKit
|
||||
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)] },
|
||||
animatedPlots: views.filter { $0.input?.animates == true }.count)
|
||||
animatedPlots: 0)
|
||||
if event == "open1.10", ProcessInfo.processInfo.environment["KYMO_AUDIT_CAPTURE"] == "1",
|
||||
let content = controller.panel.contentView { capture(content) }
|
||||
}
|
||||
|
||||
@@ -20,11 +20,11 @@ struct StorageDetailsView: View {
|
||||
CardSeparator()
|
||||
HStack(alignment: .top, spacing: 8) {
|
||||
CardField(title: "disk.remainingLife") {
|
||||
AnimatedMetricText(value: MetricFormat.percent(health?.remainingLife))
|
||||
MetricText(value: MetricFormat.percent(health?.remainingLife))
|
||||
}
|
||||
Divider().frame(height: 32)
|
||||
CardField(title: "disk.powerOnHours") {
|
||||
AnimatedMetricText(value: health?.powerOnHours.map { "\($0) h" } ?? "--")
|
||||
MetricText(value: health?.powerOnHours.map { "\($0) h" } ?? "--")
|
||||
}
|
||||
Divider().frame(height: 32)
|
||||
CardField(title: "disk.localVolumes") {
|
||||
|
||||
@@ -33,6 +33,7 @@ struct AppearanceSettingsView: View {
|
||||
.frame(width: 520)
|
||||
.frame(minHeight: 420, idealHeight: 460)
|
||||
.modifier(AppearanceStyle(preferences: preferences, refreshContentOnChange: true))
|
||||
.transaction { $0.animation = nil; $0.disablesAnimations = true }
|
||||
}
|
||||
|
||||
private var generalPage: some View {
|
||||
@@ -62,10 +63,6 @@ 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") {
|
||||
|
||||
@@ -4378,52 +4378,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"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" : {
|
||||
|
||||
@@ -4,54 +4,9 @@ struct MiniTrendChart: View {
|
||||
let values: [Double?]
|
||||
let color: Color
|
||||
|
||||
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
||||
@State private var displayed: [Double?] = []
|
||||
@State private var progress: CGFloat = 1
|
||||
@State private var scrolling = false
|
||||
|
||||
var body: some View {
|
||||
TrendCanvas(values: displayed, color: color, progress: progress, scrolling: scrolling)
|
||||
.clipped()
|
||||
.accessibilityHidden(true)
|
||||
.onAppear { displayed = values; scrolling = false; progress = 1 }
|
||||
.onChange(of: values) { old, new in
|
||||
var transaction = Transaction()
|
||||
transaction.disablesAnimations = true
|
||||
withTransaction(transaction) {
|
||||
scrolling = !reduceMotion && TrendScroll.isAppend(from: old, to: new)
|
||||
displayed = scrolling ? old + [new.last!] : new
|
||||
progress = scrolling ? 0 : 1
|
||||
}
|
||||
}
|
||||
.task(id: values) {
|
||||
guard scrolling, !reduceMotion else { return }
|
||||
// Commit the starting frame before requesting interpolation; no repeating timer.
|
||||
do { try await Task.sleep(for: .milliseconds(16)) } catch { return }
|
||||
guard !Task.isCancelled else { return }
|
||||
withAnimation(.easeInOut(duration: 0.35)) { progress = 1 }
|
||||
}
|
||||
.onChange(of: reduceMotion) { _, reduced in
|
||||
if reduced {
|
||||
var transaction = Transaction()
|
||||
transaction.disablesAnimations = true
|
||||
withTransaction(transaction) { displayed = values; scrolling = false; progress = 1 }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private struct TrendCanvas: View, Animatable {
|
||||
let values: [Double?]
|
||||
let color: Color
|
||||
var progress: CGFloat
|
||||
let scrolling: Bool
|
||||
var animatableData: CGFloat {
|
||||
get { progress }
|
||||
set { progress = newValue }
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Canvas { context, size in
|
||||
let values = Array(values.suffix(MetricHistory.capacity))
|
||||
guard values.count > 1 else { return }
|
||||
var path = Path()
|
||||
var run: [CGPoint] = []
|
||||
@@ -70,8 +25,7 @@ private struct TrendCanvas: View, Animatable {
|
||||
}
|
||||
for (index, value) in values.enumerated() {
|
||||
guard let value, value.isFinite else { appendRun(); continue }
|
||||
let x = size.width * TrendScroll.position(index: index, count: values.count,
|
||||
progress: progress, scrolling: scrolling)
|
||||
let x = size.width * CGFloat(index + MetricHistory.capacity - values.count) / CGFloat(MetricHistory.capacity - 1)
|
||||
run.append(CGPoint(x: x, y: 2 + (size.height - 4) * (1 - min(1, max(0, value)))))
|
||||
}
|
||||
appendRun()
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import AppKit
|
||||
import SwiftUI
|
||||
|
||||
/// Immutable paths plus compositor time-domain transforms preserve the original scrolling curve.
|
||||
/// Bounded static Core Graphics paths. No animation, gradient fill or per-frame work.
|
||||
struct NativePanelCurve: NSViewRepresentable {
|
||||
let frame: PanelCurveFrame
|
||||
let colors: [Color]
|
||||
let scales: [Double]
|
||||
let maximumGap: TimeInterval
|
||||
var hoveredIndex: Int? = nil
|
||||
@Environment(\.metricAnimationsEnabled) private var animates
|
||||
|
||||
func sizeThatFits(_ proposal: ProposedViewSize, nsView: PlotView, context: Context) -> CGSize? {
|
||||
CGSize(width: proposal.width.flatMap { $0.isFinite ? $0 : nil } ?? 10,
|
||||
@@ -17,7 +16,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, animates: animates))
|
||||
hoveredIndex: hoveredIndex))
|
||||
}
|
||||
struct Input: Equatable {
|
||||
let frame: PanelCurveFrame
|
||||
@@ -25,11 +24,9 @@ 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(set) var pathBuildCount = 0
|
||||
let grid = CAShapeLayer()
|
||||
let curves = CALayer()
|
||||
@@ -37,8 +34,6 @@ struct NativePanelCurve: NSViewRepresentable {
|
||||
private var hoverDots: [CAShapeLayer] = []
|
||||
private var seriesLayers: [SeriesLayer] = []
|
||||
private var palette: [NSColor] = []
|
||||
private let motion = MetricMotion()
|
||||
var isAnimating: Bool { motion.isRunning }
|
||||
override var isFlipped: Bool { true }
|
||||
override func hitTest(_ point: NSPoint) -> NSView? { nil }
|
||||
|
||||
@@ -59,43 +54,15 @@ struct NativePanelCurve: NSViewRepresentable {
|
||||
let old = input
|
||||
let frameChanged = old?.frame != value.frame
|
||||
input = value
|
||||
let animate = value.animates && !value.colors.isEmpty && !value.scales.isEmpty && window != nil && frameChanged && old.map {
|
||||
guard let end = value.frame.dates.last, !value.frame.boundaryDates.contains(end) else { return false }
|
||||
return PanelCurveGeometry.isAppend(from: $0.frame.dates, to: value.frame.dates, maximumGap: value.maximumGap)
|
||||
} == true
|
||||
CATransaction.begin(); CATransaction.setDisableActions(true)
|
||||
if frameChanged {
|
||||
motion.stop()
|
||||
drawingFrame = animate ? PanelCurveFrame.transition(from: old!.frame, to: value.frame) : value.frame
|
||||
} else if !value.animates {
|
||||
motion.stop(); drawingFrame = value.frame
|
||||
}
|
||||
curves.isHidden = value.colors.isEmpty || value.scales.isEmpty
|
||||
ensureLayers(value.frame.series.count)
|
||||
if old?.colors != value.colors { updatePalette() }
|
||||
if frameChanged || old?.scales != value.scales || old?.maximumGap != value.maximumGap || !value.animates && old?.animates == true {
|
||||
if old?.colors != value.colors || old?.frame.series.count != value.frame.series.count { updatePalette() }
|
||||
if frameChanged || old?.scales != value.scales || old?.maximumGap != value.maximumGap {
|
||||
rebuildPaths()
|
||||
}
|
||||
updateHover()
|
||||
CATransaction.commit()
|
||||
if animate, let old { startMovement(from: old.frame, to: value.frame) }
|
||||
}
|
||||
private func startMovement(from old: PanelCurveFrame, to next: PanelCurveFrame) {
|
||||
guard let a = old.dates.first, let b = old.dates.last,
|
||||
let c = next.dates.first, let d = next.dates.last else { return }
|
||||
let previous = PanelCurveFrame.domain(previousBegin: nil, previousEnd: nil, begin: a, end: b, progress: 1)
|
||||
let target = PanelCurveFrame.domain(previousBegin: nil, previousEnd: nil, begin: c, end: d, progress: 1)
|
||||
let animation = CAKeyframeAnimation(keyPath: "transform")
|
||||
animation.calculationMode = .linear
|
||||
animation.timingFunction = CAMediaTimingFunction(name: .linear)
|
||||
animation.keyTimes = (0...60).map { NSNumber(value: Double($0) / 60) }
|
||||
animation.values = (0...60).map { step in
|
||||
let p = MetricMotion.easeInOut(Double(step) / 60)
|
||||
let map = PanelCurveFrame.horizontalTransform(from: previous, to: target, progress: p, width: bounds.width)
|
||||
let transform = CGAffineTransform(a: map.scale, b: 0, c: 0, d: 1, tx: map.translation, ty: 0)
|
||||
return NSValue(caTransform3D: CATransform3DMakeAffineTransform(transform))
|
||||
}
|
||||
motion.start(on: curves, animation: animation)
|
||||
}
|
||||
private func ensureLayers(_ count: Int) {
|
||||
while seriesLayers.count < count {
|
||||
@@ -116,7 +83,6 @@ struct NativePanelCurve: NSViewRepresentable {
|
||||
for index in seriesLayers.indices {
|
||||
let color = palette[min(index, palette.count - 1)], series = seriesLayers[index]
|
||||
series.line.strokeColor = color.cgColor; series.points.fillColor = color.cgColor
|
||||
series.gradient.colors = [color.withAlphaComponent(0.20).cgColor, color.withAlphaComponent(0.01).cgColor]
|
||||
hoverDots[index].fillColor = color.cgColor
|
||||
}
|
||||
}
|
||||
@@ -137,25 +103,25 @@ struct NativePanelCurve: NSViewRepresentable {
|
||||
}
|
||||
private func rebuildPaths() {
|
||||
pathBuildCount += 1
|
||||
guard let input, let frame = drawingFrame, let first = input.frame.dates.first, let last = input.frame.dates.last,
|
||||
guard let input, let first = input.frame.dates.first, let last = input.frame.dates.last,
|
||||
!input.scales.isEmpty else {
|
||||
for series in seriesLayers { series.clear() }
|
||||
return
|
||||
}
|
||||
let domain = PanelCurveFrame.domain(previousBegin: nil, previousEnd: nil, begin: first, end: last, progress: 1)
|
||||
let domain = PanelCurveFrame.domain(begin: first, end: last)
|
||||
let frame = input.frame
|
||||
for index in frame.series.indices {
|
||||
let series = seriesLayers[index]
|
||||
let left = min(0, bounds.width * domain.position(frame.dates.first ?? first))
|
||||
series.resize(CGRect(x: left, y: 0, width: bounds.width - left, height: bounds.height))
|
||||
series.resize(bounds)
|
||||
let value = input.scales[min(index, input.scales.count - 1)]
|
||||
let scale = value.isFinite && value > 0 ? value : 1
|
||||
let runs = PanelCurveGeometry.runs(dates: frame.dates, values: frame.series[index], maximumGap: input.maximumGap,
|
||||
boundaryDates: frame.boundaryDates, intervals: frame.intervals)
|
||||
let line = CGMutablePath(), areas = CGMutablePath(), dots = CGMutablePath()
|
||||
let line = CGMutablePath(), dots = 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)))) }
|
||||
guard let start = points.first, let end = points.last else { continue }
|
||||
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
|
||||
}
|
||||
@@ -165,15 +131,9 @@ struct NativePanelCurve: NSViewRepresentable {
|
||||
segment.addCurve(to: b, control1: CGPoint(x: mid, y: a.y), control2: CGPoint(x: mid, y: b.y))
|
||||
}
|
||||
line.addPath(segment)
|
||||
segment.addLine(to: CGPoint(x: end.x, y: bounds.height))
|
||||
segment.addLine(to: CGPoint(x: start.x, y: bounds.height)); segment.closeSubpath()
|
||||
areas.addPath(segment)
|
||||
}
|
||||
var local = CGAffineTransform(translationX: -left, y: 0)
|
||||
series.line.path = line.copy(using: &local)
|
||||
series.mask.path = areas.copy(using: &local)
|
||||
series.points.path = dots.copy(using: &local)
|
||||
series.gradient.isHidden = areas.isEmpty
|
||||
series.line.path = line
|
||||
series.points.path = dots
|
||||
}
|
||||
}
|
||||
private func updateHover() {
|
||||
@@ -181,7 +141,7 @@ struct NativePanelCurve: NSViewRepresentable {
|
||||
hoverLine.path = nil
|
||||
guard let input, !input.colors.isEmpty, let index = input.hoveredIndex, input.frame.dates.indices.contains(index),
|
||||
let first = input.frame.dates.first, let last = input.frame.dates.last, last > first, !input.scales.isEmpty else { return }
|
||||
let domain = PanelCurveFrame.domain(previousBegin: nil, previousEnd: nil, begin: first, end: last, progress: 1)
|
||||
let domain = PanelCurveFrame.domain(begin: first, end: last)
|
||||
let x = bounds.width * domain.position(input.frame.dates[index])
|
||||
let path = CGMutablePath(); path.move(to: CGPoint(x: x, y: 0)); path.addLine(to: CGPoint(x: x, y: bounds.height)); hoverLine.path = path
|
||||
for series in input.frame.series.indices {
|
||||
@@ -196,14 +156,12 @@ struct NativePanelCurve: NSViewRepresentable {
|
||||
let changed = frame.size != size
|
||||
super.setFrameSize(size)
|
||||
if changed {
|
||||
motion.stop(); drawingFrame = input?.frame
|
||||
CATransaction.begin(); CATransaction.setDisableActions(true)
|
||||
updateGrid(); rebuildPaths(); updateHover(); CATransaction.commit()
|
||||
}
|
||||
}
|
||||
override func viewDidMoveToWindow() {
|
||||
super.viewDidMoveToWindow()
|
||||
if window == nil { motion.stop(); drawingFrame = input?.frame }
|
||||
CATransaction.begin(); CATransaction.setDisableActions(true)
|
||||
updatePalette(); CATransaction.commit()
|
||||
}
|
||||
@@ -213,21 +171,17 @@ struct NativePanelCurve: NSViewRepresentable {
|
||||
updatePalette(); CATransaction.commit()
|
||||
}
|
||||
private final class SeriesLayer {
|
||||
let root = CALayer(), line = CAShapeLayer(), mask = CAShapeLayer(), points = CAShapeLayer()
|
||||
let gradient = CAGradientLayer()
|
||||
let root = CALayer(), line = CAShapeLayer(), points = CAShapeLayer()
|
||||
init() {
|
||||
line.fillColor = nil; line.lineWidth = 1.5; line.lineCap = .round; line.lineJoin = .round
|
||||
mask.fillColor = NSColor.white.cgColor
|
||||
gradient.startPoint = CGPoint(x: 0.5, y: 0); gradient.endPoint = CGPoint(x: 0.5, y: 1)
|
||||
gradient.locations = [0, 1]; gradient.mask = mask
|
||||
root.addSublayer(gradient); root.addSublayer(line); root.addSublayer(points)
|
||||
root.addSublayer(line); root.addSublayer(points)
|
||||
}
|
||||
func resize(_ bounds: CGRect) {
|
||||
root.frame = bounds
|
||||
let local = CGRect(origin: .zero, size: bounds.size)
|
||||
gradient.frame = local; mask.frame = local; line.frame = local; points.frame = local
|
||||
line.frame = local; points.frame = local
|
||||
}
|
||||
func clear() { line.path = nil; mask.path = nil; points.path = nil }
|
||||
func clear() { line.path = nil; points.path = nil }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Foundation
|
||||
|
||||
/// A render frame may keep one outgoing point beyond the bounded 60-sample history.
|
||||
/// A static render frame follows the bounded sampling history without outgoing points.
|
||||
nonisolated struct PanelCurveFrame: Equatable {
|
||||
let dates: [Date]
|
||||
let series: [[Double?]]
|
||||
@@ -15,38 +15,7 @@ nonisolated struct PanelCurveFrame: Equatable {
|
||||
}
|
||||
}
|
||||
|
||||
static func domain(previousBegin: Date?, previousEnd: Date?, begin: Date, end: Date, progress: Double) -> Domain {
|
||||
let progress = min(1, max(0, progress))
|
||||
return Domain(begin: (previousBegin ?? begin).timeIntervalSinceReferenceDate * (1 - progress) + begin.timeIntervalSinceReferenceDate * progress,
|
||||
end: (previousEnd ?? end).timeIntervalSinceReferenceDate * (1 - progress) + end.timeIntervalSinceReferenceDate * progress)
|
||||
}
|
||||
|
||||
struct HorizontalTransform {
|
||||
let scale: Double
|
||||
let translation: Double
|
||||
}
|
||||
|
||||
/// Render paths once in the final domain, then map them into the original
|
||||
/// interpolated time domain. This preserves expansion as well as translation.
|
||||
static func horizontalTransform(from old: Domain, to target: Domain, progress: Double, width: Double) -> HorizontalTransform {
|
||||
let p = min(1, max(0, progress))
|
||||
let begin = old.begin * (1 - p) + target.begin * p
|
||||
let end = old.end * (1 - p) + target.end * p
|
||||
let span = end - begin, finalSpan = target.end - target.begin
|
||||
guard span.isFinite, span > 0, finalSpan.isFinite, finalSpan > 0, width.isFinite else { return HorizontalTransform(scale: 1, translation: 0) }
|
||||
return HorizontalTransform(scale: finalSpan / span, translation: (target.begin - begin) / span * width)
|
||||
}
|
||||
|
||||
static func transition(from old: Self, to new: Self) -> Self {
|
||||
guard old.dates.count > 1, old.dates.count == new.dates.count,
|
||||
Array(old.dates.dropFirst()) == Array(new.dates.dropLast()),
|
||||
let outgoing = old.dates.first else { return new }
|
||||
let series = new.series.enumerated().map { index, values -> [Double?] in
|
||||
let previous = index < old.series.count ? old.series[index] : []
|
||||
return previous.isEmpty && values.isEmpty ? [] : [previous.first ?? nil] + values
|
||||
}
|
||||
return Self(dates: [outgoing] + new.dates, series: series,
|
||||
intervals: [old.intervals.first ?? 2] + new.intervals,
|
||||
boundaryDates: new.boundaryDates.union(old.boundaryDates.intersection([outgoing])))
|
||||
static func domain(begin: Date, end: Date) -> Domain {
|
||||
Domain(begin: begin.timeIntervalSinceReferenceDate, end: end.timeIntervalSinceReferenceDate)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,13 +6,6 @@ nonisolated enum PanelCurveGeometry {
|
||||
let value: Double
|
||||
}
|
||||
|
||||
static func isAppend(from old: [Date], to new: [Date], maximumGap: TimeInterval = 5) -> Bool {
|
||||
guard old.count > 1, let previous = old.last, let next = new.last,
|
||||
next > previous, next.timeIntervalSince(previous) <= maximumGap else { return false }
|
||||
if new.count == old.count + 1 { return Array(new.dropLast()) == old }
|
||||
return new.count == old.count && Array(old.dropFirst()) == Array(new.dropLast())
|
||||
}
|
||||
|
||||
static func allowedGap(at index: Int, intervals: [TimeInterval], fallback: TimeInterval) -> TimeInterval {
|
||||
guard index > 0, index < intervals.count else { return fallback }
|
||||
let pair = [intervals[index - 1], intervals[index]].filter { $0.isFinite && $0 > 0 }
|
||||
|
||||
@@ -41,7 +41,9 @@ struct PanelTrendChart: View {
|
||||
@State private var hoverPoint: CGPoint?
|
||||
|
||||
private var inputFrame: PanelCurveFrame {
|
||||
PanelCurveFrame(dates: dates, series: [first, second, third, fourth],
|
||||
var series = [first, second, third, fourth]
|
||||
while series.last?.isEmpty == true { series.removeLast() }
|
||||
return PanelCurveFrame(dates: dates, series: series,
|
||||
intervals: intervals.count == dates.count ? intervals : Array(repeating: expectedInterval, count: dates.count),
|
||||
boundaryDates: boundaryDates)
|
||||
}
|
||||
@@ -98,9 +100,8 @@ struct PanelTrendChart: View {
|
||||
if !fourth.isEmpty { tooltipRow(fourthLabel, values: fourth, tint: fourthColor, index: index) }
|
||||
}
|
||||
.font(.system(size: 10)).padding(8)
|
||||
.background { TooltipMaterialBackground() }
|
||||
.background { TooltipBackground() }
|
||||
.overlay(RoundedRectangle(cornerRadius: 7).strokeBorder(.primary.opacity(0.2)))
|
||||
.shadow(color: .black.opacity(0.2), radius: 5, y: 2)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
import Foundation
|
||||
|
||||
/// Geometry for a single appended sample, including the outgoing point at full capacity.
|
||||
nonisolated enum TrendScroll {
|
||||
static func isAppend(from old: [Double?], to new: [Double?]) -> Bool {
|
||||
guard !old.isEmpty, !new.isEmpty else { return false }
|
||||
if old.count < MetricHistory.capacity {
|
||||
return new.count == old.count + 1 && Array(new.dropLast()) == old
|
||||
}
|
||||
return new.count == old.count && Array(old.dropFirst()) == Array(new.dropLast())
|
||||
}
|
||||
|
||||
static func position(index: Int, count: Int, progress: CGFloat, scrolling: Bool) -> CGFloat {
|
||||
let offset = MetricHistory.capacity - count
|
||||
let shift = scrolling ? 1 - min(1, max(0, progress)) : 0
|
||||
return (CGFloat(index + offset) + shift) / CGFloat(MetricHistory.capacity - 1)
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
import SwiftUI
|
||||
|
||||
/// Short numeric transitions follow the owner-supplied motion policy.
|
||||
struct AnimatedMetricText: View {
|
||||
let value: String
|
||||
@Environment(\.metricAnimationsEnabled) private var animates
|
||||
|
||||
var body: some View {
|
||||
if animates {
|
||||
RollingMetricText(value: value).equatable()
|
||||
} else {
|
||||
Text(verbatim: value).monospacedDigit()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Same numeric roll/blur and spring as the original implementation. Unchanged values
|
||||
/// do not rebuild this subtree when the surrounding resource snapshot changes.
|
||||
private struct RollingMetricText: View, Equatable {
|
||||
let value: String
|
||||
var body: some View {
|
||||
Text(verbatim: value).monospacedDigit()
|
||||
.contentTransition(.numericText())
|
||||
.animation(.spring(duration: 0.35, bounce: 0), value: value)
|
||||
}
|
||||
}
|
||||
|
||||
struct PanelCardBackground: ViewModifier {
|
||||
let radius: CGFloat
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
content.background(RoundedRectangle(cornerRadius: radius).fill(Color("PanelCard")))
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ struct FanSpeedIndicator: View {
|
||||
.frame(width: 14, height: 14).accessibilityHidden(true)
|
||||
title.foregroundStyle(.secondary)
|
||||
Spacer(minLength: 2)
|
||||
AnimatedMetricText(value: rpm.map { "\(Int($0.rounded())) RPM" } ?? "-- RPM")
|
||||
MetricText(value: rpm.map { "\(Int($0.rounded())) RPM" } ?? "-- RPM")
|
||||
.monospacedDigit().fontWeight(.medium)
|
||||
}
|
||||
.font(.system(size: 10)).lineLimit(1).minimumScaleFactor(0.7)
|
||||
|
||||
@@ -64,33 +64,20 @@ struct HoverDetailPresenter<Detail: View>: NSViewRepresentable {
|
||||
.padding(12)
|
||||
.frame(width: 280)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.modifier(DetailEntrance())
|
||||
.background(Color("PanelCard"), in: .rect(cornerRadius: 12))
|
||||
.overlay(RoundedRectangle(cornerRadius: 12).strokeBorder(.primary.opacity(0.14)))
|
||||
.onHover { [weak self] inside in self?.onHover(inside) })
|
||||
if panel == nil {
|
||||
let panel = DetailPanel(contentRect: .zero, styleMask: [.borderless, .nonactivatingPanel], backing: .buffered, defer: false)
|
||||
panel.isReleasedWhenClosed = false
|
||||
panel.isOpaque = false
|
||||
panel.backgroundColor = .clear
|
||||
panel.hasShadow = true
|
||||
panel.hasShadow = false
|
||||
panel.animationBehavior = .none
|
||||
panel.hidesOnDeactivate = false
|
||||
panel.level = parent.level
|
||||
let material = NSVisualEffectView()
|
||||
material.material = .menu
|
||||
material.blendingMode = .behindWindow
|
||||
material.state = .active
|
||||
material.wantsLayer = true
|
||||
material.layer?.cornerRadius = 12
|
||||
material.layer?.masksToBounds = true
|
||||
let host = NSHostingView(rootView: content)
|
||||
host.translatesAutoresizingMaskIntoConstraints = false
|
||||
material.addSubview(host)
|
||||
NSLayoutConstraint.activate([
|
||||
host.leadingAnchor.constraint(equalTo: material.leadingAnchor),
|
||||
host.trailingAnchor.constraint(equalTo: material.trailingAnchor),
|
||||
host.topAnchor.constraint(equalTo: material.topAnchor),
|
||||
host.bottomAnchor.constraint(equalTo: material.bottomAnchor)
|
||||
])
|
||||
panel.contentView = material
|
||||
panel.contentView = host
|
||||
self.panel = panel
|
||||
self.host = host
|
||||
parent.addChildWindow(panel, ordered: .above)
|
||||
@@ -124,28 +111,3 @@ struct HoverDetailPresenter<Detail: View>: NSViewRepresentable {
|
||||
override var canBecomeMain: Bool { false }
|
||||
}
|
||||
}
|
||||
|
||||
/// One entrance per mounted child panel; sampling updates retain the revealed state.
|
||||
private struct DetailEntrance: ViewModifier {
|
||||
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
||||
@State private var revealed = false
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
content
|
||||
.opacity(revealed || reduceMotion ? 1 : 0)
|
||||
.scaleEffect(revealed || reduceMotion ? 1 : 0.97)
|
||||
.task {
|
||||
guard !reduceMotion else { revealed = true; return }
|
||||
do { try await Task.sleep(for: .milliseconds(16)) } catch { return }
|
||||
guard !Task.isCancelled else { return }
|
||||
withAnimation(.spring(duration: 0.2, bounce: 0)) { revealed = true }
|
||||
}
|
||||
.onChange(of: reduceMotion) { _, reduced in
|
||||
if reduced {
|
||||
var transaction = Transaction()
|
||||
transaction.disablesAnimations = true
|
||||
withTransaction(transaction) { revealed = true }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
import SwiftUI
|
||||
import QuartzCore
|
||||
|
||||
private struct MetricAnimationsKey: EnvironmentKey {
|
||||
static let defaultValue = false
|
||||
}
|
||||
extension EnvironmentValues {
|
||||
var metricAnimationsEnabled: Bool {
|
||||
get { self[MetricAnimationsKey.self] }
|
||||
set { self[MetricAnimationsKey.self] = newValue }
|
||||
}
|
||||
}
|
||||
|
||||
/// Finite property animations; no opacity substitution or per-frame CPU timer.
|
||||
@MainActor final class MetricMotion {
|
||||
static let duration: TimeInterval = 0.35
|
||||
static let key = "kymo.metric.movement"
|
||||
private weak var layer: CALayer?
|
||||
private static let cleanup = MotionCleanup()
|
||||
var isRunning: Bool { layer?.animation(forKey: Self.key) != nil }
|
||||
|
||||
func start(on layer: CALayer?, animation: CAAnimation) {
|
||||
stop()
|
||||
guard let layer else { return }
|
||||
self.layer = layer
|
||||
animation.duration = Self.duration
|
||||
animation.beginTime = layer.convertTime(CACurrentMediaTime(), from: nil)
|
||||
animation.isRemovedOnCompletion = true
|
||||
layer.add(animation, forKey: Self.key)
|
||||
// Backing layers may retain completed animations. Bound their lifetime explicitly.
|
||||
Self.cleanup.register(self)
|
||||
}
|
||||
/// Cubic timing curve used by the original SwiftUI easeInOut animation.
|
||||
static func easeInOut(_ time: Double) -> Double {
|
||||
let time = min(1, max(0, time))
|
||||
var low = 0.0, high = 1.0
|
||||
for _ in 0..<24 {
|
||||
let u = (low + high) / 2, v = 1 - u
|
||||
let x = 3 * v * v * u * 0.42 + 3 * v * u * u * 0.58 + u * u * u
|
||||
if x < time { low = u } else { high = u }
|
||||
}
|
||||
let u = (low + high) / 2
|
||||
return 3 * (1 - u) * u * u + u * u * u
|
||||
}
|
||||
|
||||
func stop() {
|
||||
Self.cleanup.remove(self)
|
||||
finish()
|
||||
}
|
||||
|
||||
fileprivate func finish() {
|
||||
layer?.removeAnimation(forKey: Self.key); layer = nil
|
||||
}
|
||||
}
|
||||
|
||||
/// One one-shot timer serves the whole visible batch, retaining neither views nor motions.
|
||||
@MainActor private final class MotionCleanup {
|
||||
private struct Entry {
|
||||
weak var motion: MetricMotion?
|
||||
let deadline: DispatchTime
|
||||
}
|
||||
private var entries: [ObjectIdentifier: Entry] = [:]
|
||||
private var timer: DispatchSourceTimer?
|
||||
private var scheduled: UInt64?
|
||||
|
||||
func register(_ motion: MetricMotion) {
|
||||
entries[ObjectIdentifier(motion)] = Entry(motion: motion, deadline: .now() + MetricMotion.duration)
|
||||
schedule()
|
||||
}
|
||||
|
||||
func remove(_ motion: MetricMotion) {
|
||||
guard entries.removeValue(forKey: ObjectIdentifier(motion)) != nil else { return }
|
||||
schedule()
|
||||
}
|
||||
|
||||
private func schedule() {
|
||||
guard let first = entries.values.map(\.deadline.uptimeNanoseconds).min() else {
|
||||
timer?.cancel(); timer = nil; scheduled = nil
|
||||
return
|
||||
}
|
||||
// Core Animation ends at 350 ms. Group nearby cleanup deadlines 10 ms later.
|
||||
let deadline = first + 10_000_000
|
||||
guard scheduled != deadline else { return }
|
||||
scheduled = deadline
|
||||
let newTimer = timer == nil
|
||||
if newTimer {
|
||||
let source = DispatchSource.makeTimerSource(queue: .main)
|
||||
source.setEventHandler { [weak self] in MainActor.assumeIsolated { self?.complete() } }
|
||||
timer = source
|
||||
}
|
||||
timer?.schedule(deadline: DispatchTime(uptimeNanoseconds: deadline), leeway: .milliseconds(10))
|
||||
if newTimer { timer?.resume() }
|
||||
}
|
||||
|
||||
private func complete() {
|
||||
let now = DispatchTime.now().uptimeNanoseconds
|
||||
let expired = entries.filter { $0.value.motion == nil || $0.value.deadline.uptimeNanoseconds <= now }
|
||||
for (id, entry) in expired {
|
||||
entries.removeValue(forKey: id)
|
||||
entry.motion?.finish()
|
||||
}
|
||||
scheduled = nil
|
||||
schedule()
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ 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 }
|
||||
|
||||
@@ -16,8 +15,7 @@ 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 } }
|
||||
.transaction { $0.animation = nil; $0.disablesAnimations = true }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ struct MetricRingGauge: View {
|
||||
VStack(spacing: 3) {
|
||||
ZStack {
|
||||
NativeMetricRing(value: fraction, color: color, lineWidth: 3, trackOpacity: 0.17, inset: 2)
|
||||
AnimatedMetricText(value: MetricFormat.percent(value)).font(.system(size: 8, weight: .semibold))
|
||||
MetricText(value: MetricFormat.percent(value)).font(.system(size: 8, weight: .semibold))
|
||||
.lineLimit(1).minimumScaleFactor(0.6).frame(width: 18, height: 12)
|
||||
}.frame(width: 28, height: 28).accessibilityHidden(true)
|
||||
Text(title).font(.system(size: 8)).foregroundStyle(.secondary)
|
||||
|
||||
@@ -8,7 +8,6 @@ struct MetricRow<Detail: View>: View {
|
||||
let history: [Double?]
|
||||
let accent: Color
|
||||
@ViewBuilder let detail: () -> Detail
|
||||
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
||||
@State private var visible = false
|
||||
@State private var rowHovered = false
|
||||
@State private var detailHovered = false
|
||||
@@ -33,7 +32,6 @@ struct MetricRow<Detail: View>: View {
|
||||
Text(verbatim: value)
|
||||
.font(.system(size: 13, weight: .semibold, design: .rounded))
|
||||
.monospacedDigit()
|
||||
.contentTransition(.numericText())
|
||||
.frame(width: 46, alignment: .trailing)
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
@@ -56,6 +54,6 @@ struct MetricRow<Detail: View>: View {
|
||||
}
|
||||
.onAppear { visible = true }
|
||||
.onDisappear { visible = false; rowHovered = false; detailHovered = false; expanded = false }
|
||||
.animation(!visible || reduceMotion ? nil : .spring(duration: 0.3, bounce: 0), value: value)
|
||||
.transaction { $0.animation = nil; $0.disablesAnimations = true }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import SwiftUI
|
||||
|
||||
/// Metrics change only when a new sample is published; no numeric transition or spring.
|
||||
struct MetricText: View {
|
||||
let value: String
|
||||
var body: some View { Text(verbatim: value).monospacedDigit() }
|
||||
}
|
||||
|
||||
struct PanelCardBackground: ViewModifier {
|
||||
let radius: CGFloat
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
content.background(RoundedRectangle(cornerRadius: radius).fill(Color("PanelCard")))
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import AppKit
|
||||
import SwiftUI
|
||||
|
||||
/// Keeps local animation rendering inside a fixed-size child host.
|
||||
/// Keeps card rendering inside a fixed-size child host.
|
||||
struct NativeContentHost<Content: View>: NSViewRepresentable {
|
||||
let content: Content
|
||||
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import AppKit
|
||||
import SwiftUI
|
||||
|
||||
/// Arc geometry is submitted once; the compositor interpolates strokeEnd continuously.
|
||||
/// Static arc geometry; sampling publishes the final value directly.
|
||||
struct NativeMetricRing: NSViewRepresentable {
|
||||
let value: Double
|
||||
let color: Color
|
||||
let lineWidth: CGFloat
|
||||
let trackOpacity: Double
|
||||
let inset: CGFloat
|
||||
@Environment(\.metricAnimationsEnabled) private var animates
|
||||
|
||||
func sizeThatFits(_ proposal: ProposedViewSize, nsView: RingView, context: Context) -> CGSize? {
|
||||
CGSize(width: proposal.width.flatMap { $0.isFinite ? $0 : nil } ?? 10,
|
||||
@@ -17,7 +16,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, animates: animates))
|
||||
lineWidth: lineWidth, trackOpacity: trackOpacity, inset: inset))
|
||||
}
|
||||
struct Input: Equatable {
|
||||
let value: Double
|
||||
@@ -25,18 +24,11 @@ struct NativeMetricRing: NSViewRepresentable {
|
||||
let lineWidth: CGFloat
|
||||
let trackOpacity: Double
|
||||
let inset: CGFloat
|
||||
var animates = false
|
||||
}
|
||||
final class RingView: NSView {
|
||||
private(set) var input: Input?
|
||||
let track = CAShapeLayer()
|
||||
let arc = CAShapeLayer()
|
||||
private let motion = MetricMotion()
|
||||
var isAnimating: Bool { motion.isRunning }
|
||||
var displayedValue: Double {
|
||||
if isAnimating, let presentation = arc.presentation() { return Double(presentation.strokeEnd) }
|
||||
return Double(arc.strokeEnd)
|
||||
}
|
||||
override var isFlipped: Bool { true }
|
||||
override func hitTest(_ point: NSPoint) -> NSView? { nil }
|
||||
init() {
|
||||
@@ -52,23 +44,12 @@ struct NativeMetricRing: NSViewRepresentable {
|
||||
func configure(_ value: Input) {
|
||||
guard value != input else { return }
|
||||
let old = input
|
||||
let start = displayedValue
|
||||
input = value
|
||||
CATransaction.begin(); CATransaction.setDisableActions(true)
|
||||
if old?.color != value.color || old?.trackOpacity != value.trackOpacity { updateColors() }
|
||||
if old?.inset != value.inset || old?.lineWidth != value.lineWidth { updateGeometry() }
|
||||
arc.strokeEnd = value.value
|
||||
CATransaction.commit()
|
||||
if !value.animates { motion.stop() }
|
||||
else if old?.value != value.value {
|
||||
motion.stop()
|
||||
if old != nil, window != nil, start != value.value {
|
||||
let animation = CABasicAnimation(keyPath: "strokeEnd")
|
||||
animation.fromValue = start; animation.toValue = value.value
|
||||
animation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
|
||||
motion.start(on: arc, animation: animation)
|
||||
}
|
||||
}
|
||||
}
|
||||
private func updateColors() {
|
||||
guard let input else { return }
|
||||
@@ -92,14 +73,12 @@ struct NativeMetricRing: NSViewRepresentable {
|
||||
let changed = frame.size != size
|
||||
super.setFrameSize(size)
|
||||
if changed {
|
||||
motion.stop()
|
||||
CATransaction.begin(); CATransaction.setDisableActions(true)
|
||||
updateGeometry(); CATransaction.commit()
|
||||
}
|
||||
}
|
||||
override func viewDidMoveToWindow() {
|
||||
super.viewDidMoveToWindow()
|
||||
if window == nil { motion.stop() }
|
||||
CATransaction.begin(); CATransaction.setDisableActions(true)
|
||||
updateColors(); CATransaction.commit()
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ struct CapacityField: View {
|
||||
Circle().fill(color).frame(width: 4, height: 4)
|
||||
Text(title).font(PanelStyle.label).foregroundStyle(.secondary)
|
||||
}.frame(height: 14)
|
||||
AnimatedMetricText(value: value).font(PanelStyle.value).frame(height: 14)
|
||||
MetricText(value: value).font(PanelStyle.value).frame(height: 14)
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.lineLimit(1)
|
||||
@@ -99,7 +99,7 @@ struct CardSectionHeader: View {
|
||||
Text(title).font(PanelStyle.section)
|
||||
Spacer(minLength: 4)
|
||||
Text(valueLabel).font(PanelStyle.label).foregroundStyle(.secondary)
|
||||
AnimatedMetricText(value: value).font(PanelStyle.value).foregroundStyle(color)
|
||||
MetricText(value: value).font(PanelStyle.value).foregroundStyle(color)
|
||||
}.frame(height: 16)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,11 +47,11 @@ struct ResourceCard<Content: View>: View {
|
||||
}
|
||||
Spacer(minLength: 0)
|
||||
HStack(alignment: .center, spacing: 6) {
|
||||
AnimatedMetricText(value: value)
|
||||
MetricText(value: value)
|
||||
.font(PanelStyle.title)
|
||||
.foregroundStyle(valueColor ?? color)
|
||||
if let secondaryValue {
|
||||
AnimatedMetricText(value: secondaryValue).font(PanelStyle.title)
|
||||
MetricText(value: secondaryValue).font(PanelStyle.title)
|
||||
.foregroundStyle(secondaryValueColor ?? color)
|
||||
}
|
||||
}.foregroundStyle(color).lineLimit(1)
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import SwiftUI
|
||||
|
||||
/// Opaque semantic surface; no backdrop material, blur or shadow.
|
||||
struct TooltipBackground: View {
|
||||
var body: some View {
|
||||
RoundedRectangle(cornerRadius: 7).fill(Color("PanelTooltip"))
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
import SwiftUI
|
||||
import AppKit
|
||||
|
||||
/// Within-window blending blurs the chart and labels below the card's root overlay.
|
||||
struct TooltipMaterialBackground: View {
|
||||
@Environment(\.accessibilityReduceTransparency) private var reduceTransparency
|
||||
var body: some View {
|
||||
Group {
|
||||
if reduceTransparency { Color(nsColor: .windowBackgroundColor) }
|
||||
else {
|
||||
WithinWindowMaterial()
|
||||
.overlay(Color("PanelTooltip").opacity(0.12))
|
||||
}
|
||||
}.clipShape(.rect(cornerRadius: 7))
|
||||
}
|
||||
}
|
||||
|
||||
private struct WithinWindowMaterial: NSViewRepresentable {
|
||||
func makeNSView(context: Context) -> NSVisualEffectView {
|
||||
let view = PassthroughVisualEffectView()
|
||||
view.material = .popover
|
||||
view.blendingMode = .withinWindow
|
||||
view.state = .active
|
||||
return view
|
||||
}
|
||||
func updateNSView(_ view: NSVisualEffectView, context: Context) {}
|
||||
}
|
||||
|
||||
private final class PassthroughVisualEffectView: NSVisualEffectView {
|
||||
override func hitTest(_ point: NSPoint) -> NSView? { nil }
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import Foundation
|
||||
|
||||
@main struct AppearancePreferencesChecks {
|
||||
@MainActor static func main() {
|
||||
let suite = "kymo.appearance." + UUID().uuidString
|
||||
let defaults = UserDefaults(suiteName: suite)!
|
||||
defer { defaults.removePersistentDomain(forName: suite) }
|
||||
defaults.set(true, forKey: "appearance.reduceMotion")
|
||||
let sampling = SamplingPreferences(defaults: defaults)
|
||||
let appearance = AppearancePreferences(defaults: defaults)
|
||||
precondition(appearance.appearance == .system && !sampling.backgroundEnabled)
|
||||
appearance.appearance = .dark
|
||||
precondition(AppearancePreferences(defaults: defaults).appearance == .dark)
|
||||
precondition(!sampling.backgroundEnabled && sampling.panelMilliseconds == 2000)
|
||||
sampling.backgroundEnabled = true
|
||||
sampling.backgroundMilliseconds = 5000
|
||||
appearance.appearance = .light
|
||||
precondition(sampling.backgroundEnabled && sampling.backgroundMilliseconds == 5000)
|
||||
precondition(defaults.bool(forKey: "appearance.reduceMotion"), "Obsolete motion keys must be ignored, not overwritten")
|
||||
defaults.set("invalid", forKey: "appearance")
|
||||
precondition(AppearancePreferences(defaults: defaults).appearance == .system)
|
||||
print("PASS: appearance persistence/fallback, independent sampling and preservation of obsolete motion preferences")
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
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")
|
||||
}
|
||||
}
|
||||
@@ -19,23 +19,23 @@ import SwiftUI
|
||||
let ideal = host.fittingSize
|
||||
precondition(ideal.width.isFinite && ideal.height.isFinite, "Unconstrained fitting must stay finite")
|
||||
let before = bitmap(host)
|
||||
precondition(probe.appearances == 1 && probe.animates && probe.locale == "en_US" && probe.font == .system(size: 22, weight: .medium))
|
||||
precondition(probe.appearances == 1 && probe.locale == "en_US" && probe.font == .system(size: 22, weight: .medium))
|
||||
precondition(redPixels(before) > 30, "Foreground style must cross the native boundary")
|
||||
let originalLifetime = ObjectIdentifier(probe.lifetime!)
|
||||
host.rootView = Example(value: "345", probe: probe)
|
||||
try? await Task.sleep(for: .milliseconds(140))
|
||||
let middle = bitmap(host)
|
||||
let settled = bitmap(host)
|
||||
try? await Task.sleep(for: .milliseconds(600))
|
||||
let after = bitmap(host)
|
||||
precondition(before.bitmapData != nil && after.bitmapData != nil)
|
||||
precondition(pixels(before) != pixels(after), "Changed values must reach the retained child host")
|
||||
precondition(pixels(middle) != pixels(before) && pixels(middle) != pixels(after),
|
||||
"The system numeric transition must still have an intermediate frame")
|
||||
precondition(pixels(settled) == pixels(after),
|
||||
"A sample must settle immediately without numeric rolling or a later animation frame")
|
||||
precondition(probe.appearances == 1 && probe.lifetime.map(ObjectIdentifier.init) == originalLifetime,
|
||||
"Sampling must update mounted content, not remount it")
|
||||
host.rootView = Example(value: "345", probe: probe, reduced: true, locale: "zh_CN")
|
||||
host.rootView = Example(value: "345", probe: probe, locale: "zh_CN")
|
||||
try? await Task.sleep(for: .milliseconds(100))
|
||||
precondition(!probe.animates && probe.locale == "zh_CN")
|
||||
precondition(probe.locale == "zh_CN")
|
||||
window.setContentSize(NSSize(width: 360, height: 100))
|
||||
try? await Task.sleep(for: .milliseconds(100))
|
||||
@MainActor func childHost(_ view: NSView) -> NSHostingView<AnyView>? {
|
||||
@@ -55,7 +55,7 @@ import SwiftUI
|
||||
window.orderOut(nil)
|
||||
window.contentView = nil
|
||||
window.close()
|
||||
print("PASS: card host preserves system numeric intermediate frames, inherited font/style/locale/motion, child state, resize and unmount")
|
||||
print("PASS: static card host preserves immediate stable text, inherited font/style/locale, child state, resize and unmount")
|
||||
fflush(stdout)
|
||||
NSApp.terminate(nil)
|
||||
}
|
||||
@@ -66,7 +66,6 @@ import SwiftUI
|
||||
@MainActor private final class Probe {
|
||||
var appearances = 0
|
||||
var disappearances = 0
|
||||
var animates = false
|
||||
var locale = ""
|
||||
var font: Font?
|
||||
weak var lifetime: Lifetime?
|
||||
@@ -74,7 +73,6 @@ import SwiftUI
|
||||
private struct Example: View {
|
||||
let value: String
|
||||
let probe: Probe
|
||||
var reduced = false
|
||||
var locale = "en_US"
|
||||
var visible = true
|
||||
var body: some View {
|
||||
@@ -84,29 +82,26 @@ import SwiftUI
|
||||
.font(.system(size: 22, weight: .medium))
|
||||
.foregroundStyle(.red)
|
||||
.environment(\.locale, Locale(identifier: locale))
|
||||
.environment(\.metricAnimationsEnabled, !reduced)
|
||||
}
|
||||
}
|
||||
private struct Content: View {
|
||||
let value: String
|
||||
let probe: Probe
|
||||
@Environment(\.metricAnimationsEnabled) private var animates
|
||||
@Environment(\.locale) private var locale
|
||||
@Environment(\.font) private var font
|
||||
@State private var lifetime = Lifetime()
|
||||
var body: some View {
|
||||
AnimatedMetricText(value: value)
|
||||
MetricText(value: value)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.onAppear {
|
||||
probe.appearances += 1; probe.lifetime = lifetime
|
||||
recordEnvironment()
|
||||
}
|
||||
.onDisappear { probe.disappearances += 1 }
|
||||
.onChange(of: animates) { recordEnvironment() }
|
||||
.onChange(of: locale) { recordEnvironment() }
|
||||
}
|
||||
private func recordEnvironment() {
|
||||
probe.animates = animates; probe.locale = locale.identifier; probe.font = font
|
||||
probe.locale = locale.identifier; probe.font = font
|
||||
}
|
||||
}
|
||||
@MainActor private static func bitmap(_ view: NSView) -> NSBitmapImageRep {
|
||||
|
||||
@@ -43,107 +43,60 @@ import QuartzCore
|
||||
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)
|
||||
let builds = plot.pathBuildCount
|
||||
precondition(plot.grid.animationKeys() == nil, "The grid must stay stationary")
|
||||
let movement = plot.curves.animation(forKey: MetricMotion.key) as! CAKeyframeAnimation
|
||||
precondition(movement.keyPath == "transform" && movement.values?.count == 61)
|
||||
precondition(plot.curves.animation(forKey: kCATransition) == nil, "A moving curve must not be replaced with a fade")
|
||||
let middle = (movement.values![30] as! NSValue).caTransform3DValue
|
||||
let oldDomain = PanelCurveFrame.domain(previousBegin: nil, previousEnd: nil, begin: dates.first!, end: dates.last!, progress: 1)
|
||||
let newDomain = PanelCurveFrame.domain(previousBegin: nil, previousEnd: nil, begin: extendedDates.first!, end: extendedDates.last!, progress: 1)
|
||||
let expected = PanelCurveFrame.horizontalTransform(from: oldDomain, to: newDomain, progress: 0.5, width: 280)
|
||||
precondition(abs(middle.m11 - expected.scale) < 0.0001 && abs(middle.m41 - expected.translation) < 0.0001)
|
||||
// Sampling updates are final immediately, and hover keeps cached curve geometry.
|
||||
let nextDates = dates + [Date(timeIntervalSinceReferenceDate: 8)]
|
||||
let next = NativePanelCurve.Input(frame: PanelCurveFrame(dates: nextDates,
|
||||
series: [[0.8,0.8,0.8,0.8,0.5]], intervals: [2,2,2,2,2], boundaryDates: []),
|
||||
colors: [.red], scales: [1], maximumGap: 5)
|
||||
plot.configure(continuous)
|
||||
let previousBuilds = plot.pathBuildCount
|
||||
plot.configure(next)
|
||||
precondition(plot.pathBuildCount == previousBuilds + 1 && plot.input?.frame == next.frame)
|
||||
let sampled = bitmap(plot)
|
||||
try? await Task.sleep(for: .milliseconds(180))
|
||||
precondition(plot.pathBuildCount == builds, "Animation frames must not rebuild curve geometry")
|
||||
var duringHover = moving; duringHover.hoveredIndex = 2
|
||||
plot.configure(duringHover)
|
||||
precondition(plot.pathBuildCount == builds && plot.isAnimating, "Hover must not rebuild or restart movement")
|
||||
try? await Task.sleep(for: .milliseconds(320))
|
||||
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)
|
||||
root.addSubview(plot)
|
||||
precondition(plot.pathBuildCount == previousBuilds + 1)
|
||||
precondition(pixels(sampled) == pixels(bitmap(plot)), "A sampled curve must not move between updates")
|
||||
var hover = next; hover.hoveredIndex = 2
|
||||
plot.configure(hover)
|
||||
precondition(plot.pathBuildCount == previousBuilds + 1, "Hover must not rebuild curve geometry")
|
||||
let fullDates = (0..<60).map { Date(timeIntervalSinceReferenceDate: Double($0 * 2)) }
|
||||
let fullFrame = PanelCurveFrame(dates: fullDates, series: [Array(repeating: 0.8, count: 60)], intervals: Array(repeating: 2, count: 60), boundaryDates: [])
|
||||
let nextFrame = PanelCurveFrame(dates: Array(fullDates.dropFirst()) + [Date(timeIntervalSinceReferenceDate: 120)],
|
||||
series: [Array(repeating: 0.8, count: 59) + [0.5]], intervals: Array(repeating: 2, count: 60), boundaryDates: [])
|
||||
plot.configure(.init(frame: fullFrame, colors: [.red], scales: [1], maximumGap: 5, animates: true))
|
||||
plot.configure(.init(frame: nextFrame, colors: [.red], scales: [1], maximumGap: 5, animates: true))
|
||||
precondition(plot.isAnimating && plot.drawingFrame?.dates.count == 61)
|
||||
let initialTransform = ((plot.curves.animation(forKey: MetricMotion.key) as! CAKeyframeAnimation).values!.first as! NSValue).caTransform3DValue
|
||||
CATransaction.begin(); CATransaction.setDisableActions(true)
|
||||
plot.curves.transform = initialTransform
|
||||
CATransaction.commit()
|
||||
precondition(redPixels(bitmap(plot), from: 0, to: 0.01) > 0, "Outgoing fill must cover the left edge while scrolling")
|
||||
CATransaction.begin(); CATransaction.setDisableActions(true); plot.curves.transform = CATransform3DIdentity; CATransaction.commit()
|
||||
plot.configure(.init(frame: nextFrame, colors: [.red], scales: [1], maximumGap: 5))
|
||||
precondition(!plot.isAnimating && plot.drawingFrame?.dates.count == 60)
|
||||
plot.removeFromSuperview()
|
||||
ring.configure(NativeMetricRing.Input(value: 0, color: .red, lineWidth: 3, trackOpacity: 0.17, inset: 2, animates: true))
|
||||
precondition(ring.isAnimating)
|
||||
let arcAnimation = ring.arc.animation(forKey: MetricMotion.key) as! CABasicAnimation
|
||||
precondition(arcAnimation.keyPath == "strokeEnd" && (arcAnimation.fromValue as! Double) == 1 && (arcAnimation.toValue as! Double) == 0)
|
||||
precondition(ring.arc.animation(forKey: kCATransition) == nil)
|
||||
try? await Task.sleep(for: .milliseconds(150))
|
||||
let intermediate = ring.displayedValue
|
||||
precondition(intermediate > 0 && intermediate < 1, "Ring must show intermediate arc lengths")
|
||||
try? await Task.sleep(for: .milliseconds(350))
|
||||
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)
|
||||
// Shared cleanup must not stop a different motion or a newer replacement.
|
||||
let firstMotion = MetricMotion(), secondMotion = MetricMotion()
|
||||
let firstLayer = CALayer(), secondLayer = CALayer()
|
||||
root.wantsLayer = true
|
||||
for target in [firstLayer, secondLayer] {
|
||||
target.frame = CGRect(x: 10, y: 10, width: 20, height: 20)
|
||||
target.backgroundColor = NSColor.red.cgColor
|
||||
root.layer?.addSublayer(target)
|
||||
}
|
||||
func makeMovement() -> CABasicAnimation {
|
||||
let animation = CABasicAnimation(keyPath: "position.x")
|
||||
animation.fromValue = 0; animation.toValue = 10
|
||||
return animation
|
||||
}
|
||||
firstMotion.start(on: firstLayer, animation: makeMovement())
|
||||
secondMotion.start(on: secondLayer, animation: makeMovement())
|
||||
let fullFrame = PanelCurveFrame(dates: fullDates, series: [Array(repeating: 0.8, count: 60)],
|
||||
intervals: Array(repeating: 2, count: 60), boundaryDates: [])
|
||||
plot.configure(.init(frame: fullFrame, colors: [.red], scales: [1], maximumGap: 5))
|
||||
let appended = PanelCurveFrame(dates: Array(fullDates.dropFirst()) + [Date(timeIntervalSinceReferenceDate: 120)],
|
||||
series: [Array(repeating: 0.8, count: 59) + [0.5]], intervals: fullFrame.intervals, boundaryDates: [])
|
||||
plot.configure(.init(frame: appended, colors: [.red], scales: [1], maximumGap: 5))
|
||||
precondition(plot.input?.frame.dates.count == 60, "Static history must not retain an outgoing animation point")
|
||||
ring.configure(.init(value: 0.25, color: .red, lineWidth: 3, trackOpacity: 0.17, inset: 2))
|
||||
precondition(ring.arc.strokeEnd == 0.25, "The arc must immediately show the new value")
|
||||
let updated = bitmap(ring)
|
||||
try? await Task.sleep(for: .milliseconds(180))
|
||||
firstMotion.stop()
|
||||
secondMotion.start(on: secondLayer, animation: makeMovement())
|
||||
try? await Task.sleep(for: .milliseconds(210))
|
||||
precondition(!firstMotion.isRunning && secondMotion.isRunning,
|
||||
"An old batch deadline must not remove a restarted animation")
|
||||
try? await Task.sleep(for: .milliseconds(250))
|
||||
precondition(!secondMotion.isRunning, "The replacement must also finish and release its animation")
|
||||
precondition(pixels(updated) == pixels(bitmap(ring)), "A sampled ring must not interpolate later")
|
||||
// Adding a series with an unchanged palette must color the new layer too.
|
||||
plot.configure(.init(frame: PanelCurveFrame(dates: dates, series: [[nil,nil,nil,nil], [0.5,0.5,0.5,0.5]],
|
||||
intervals: [2,2,2,2], boundaryDates: []), colors: [.red], scales: [1], maximumGap: 5))
|
||||
precondition(redPixels(bitmap(plot), from: 0.4, to: 0.6) > 10)
|
||||
assertStatic(plot.layer!)
|
||||
assertStatic(ring.layer!)
|
||||
plot.removeFromSuperview(); ring.removeFromSuperview()
|
||||
window.orderOut(nil); window.close()
|
||||
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")
|
||||
print("PASS: static curve/ring pixels, 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()
|
||||
}
|
||||
@MainActor private static func assertStatic(_ layer: CALayer) {
|
||||
precondition(layer.animationKeys()?.isEmpty != false)
|
||||
precondition(!(layer is CAGradientLayer) && layer.mask == nil && layer.filters?.isEmpty != false)
|
||||
for child in layer.sublayers ?? [] { assertStatic(child) }
|
||||
}
|
||||
private static func pixels(_ bitmap: NSBitmapImageRep) -> Data {
|
||||
var data = Data()
|
||||
for row in 0..<bitmap.pixelsHigh {
|
||||
data.append(bitmap.bitmapData!.advanced(by: row * bitmap.bytesPerRow), count: bitmap.pixelsWide * bitmap.bitsPerPixel / 8)
|
||||
}
|
||||
return data
|
||||
}
|
||||
@MainActor private static func bitmap(_ view: NSView) -> NSBitmapImageRep {
|
||||
view.layoutSubtreeIfNeeded(); view.displayIfNeeded()
|
||||
let result = NSBitmapImageRep(bitmapDataPlanes: nil, pixelsWide: Int(view.bounds.width * 2), pixelsHigh: Int(view.bounds.height * 2),
|
||||
|
||||
@@ -15,7 +15,7 @@ import AppKit
|
||||
NSAppearance(named: appearance)!.performAsCurrentDrawingAppearance {
|
||||
for name in ["PanelBackground", "PanelCard", "PanelTooltip", "MetricCPU", "MetricGPU", "MetricMemory", "MetricNetwork", "MetricDisk", "MetricBattery", "SeriesUser", "SeriesSystem", "SeriesUpload"] {
|
||||
guard let color = NSColor(named: NSColor.Name(name), bundle: bundle)?.usingColorSpace(.sRGB) else { fatalError("Missing color: \(name)") }
|
||||
precondition(abs(color.alphaComponent - (name == "PanelTooltip" ? 0.97 : 1)) < 0.005, "Unexpected alpha \(name)")
|
||||
precondition(abs(color.alphaComponent - 1) < 0.005, "Unexpected alpha \(name)")
|
||||
if name.hasPrefix("Metric") || name.hasPrefix("Series") {
|
||||
let card = NSColor(named: "PanelCard", bundle: bundle)!.usingColorSpace(.sRGB)!
|
||||
let a = luminance(color), b = luminance(card)
|
||||
|
||||
@@ -3,10 +3,6 @@ import Foundation
|
||||
@main struct PanelCurveChecks {
|
||||
static func main() {
|
||||
let dates = (0..<60).map { Date(timeIntervalSinceReferenceDate: Double($0 * 2)) }
|
||||
precondition(PanelCurveGeometry.isAppend(from: Array(dates.prefix(2)), to: Array(dates.prefix(3))))
|
||||
precondition(PanelCurveGeometry.isAppend(from: dates, to: Array(dates.dropFirst()) + [dates.last!.addingTimeInterval(2)]))
|
||||
precondition(!PanelCurveGeometry.isAppend(from: dates, to: Array(dates.dropFirst()) + [dates.last!.addingTimeInterval(8)]))
|
||||
precondition(!PanelCurveGeometry.isAppend(from: dates, to: dates))
|
||||
let runs = PanelCurveGeometry.runs(dates: Array(dates.prefix(6)), values: [0, 0.5, nil, .nan, 0.8, 1])
|
||||
precondition(runs.count == 2 && runs[0].count == 2 && runs[1].count == 2)
|
||||
precondition(PanelCurveGeometry.runs(dates: [dates[0], dates[4]], values: [0.3, 0.5]).count == 2)
|
||||
@@ -15,37 +11,16 @@ import Foundation
|
||||
let slow = [Date(timeIntervalSinceReferenceDate: 0), Date(timeIntervalSinceReferenceDate: 1800), Date(timeIntervalSinceReferenceDate: 3600)]
|
||||
precondition(PanelCurveGeometry.runs(dates: slow, values: [0.1, 0.2, 0.3], maximumGap: 3600).count == 1)
|
||||
precondition(PanelCurveGeometry.runs(dates: slow, values: [0.1, 0.2, 0.3], maximumGap: 3600, boundaryDates: [slow[1]]).count == 2)
|
||||
precondition(PanelCurveGeometry.isAppend(from: Array(slow.prefix(2)), to: slow, maximumGap: 3600))
|
||||
precondition(PanelCurveGeometry.runs(dates: slow, values: [0.1, 0.2, 0.3], maximumGap: 5, intervals: [1800, 1800, 0.5]).count == 1)
|
||||
precondition(PanelCurveGeometry.runs(dates: slow, values: [0.1, 0.2, 0.3], maximumGap: 5, boundaryDates: [slow[2]], intervals: [1800, 1800, 0.5]).count == 2)
|
||||
let old = PanelCurveFrame(dates: dates, series: [Array(repeating: 0.3, count: 60), []], intervals: Array(repeating: 2, count: 60), boundaryDates: [])
|
||||
let next = PanelCurveFrame(dates: Array(dates.dropFirst()) + [dates.last!.addingTimeInterval(2)], series: [Array(repeating: 0.3, count: 59) + [0.4], []], intervals: Array(repeating: 2, count: 60), boundaryDates: [])
|
||||
let transition = PanelCurveFrame.transition(from: old, to: next)
|
||||
precondition(transition.dates.count == 61 && transition.dates.first == old.dates.first)
|
||||
precondition(transition.series[0].first! == 0.3 && transition.series[0].last! == 0.4 && transition.series[1].isEmpty)
|
||||
precondition(Array(transition.series[0].prefix(60)) == old.series[0])
|
||||
for progress in [0.0, 0.25, 0.5, 0.75, 1.0] {
|
||||
let domain = PanelCurveFrame.domain(previousBegin: old.dates.first, previousEnd: old.dates.last,
|
||||
begin: next.dates.first!, end: next.dates.last!, progress: progress)
|
||||
let left = domain.position(transition.dates[0]), right = domain.position(transition.dates[1])
|
||||
precondition(left <= 0 && right >= 0, "Outgoing segment must cover the left boundary throughout the animation")
|
||||
if progress == 0 { precondition(abs(left) < 0.000001 && abs(domain.position(old.dates.last!) - 1) < 0.000001) }
|
||||
if progress == 1 { precondition(abs(right) < 0.000001 && abs(domain.position(next.dates.last!) - 1) < 0.000001) }
|
||||
}
|
||||
// The compositor mapping must equal the original interpolated time-domain formula.
|
||||
for previous in [PanelCurveFrame.Domain(begin: 0, end: 4), .init(begin: 0, end: 118), .init(begin: 2, end: 119.3)] {
|
||||
for target in [PanelCurveFrame.Domain(begin: 0, end: 6), .init(begin: 2, end: 120), .init(begin: 4.4, end: 121.8)] {
|
||||
for p in [0.0, 0.25, 0.5, 0.75, 1] {
|
||||
let map = PanelCurveFrame.horizontalTransform(from: previous, to: target, progress: p, width: 350)
|
||||
let interpolated = PanelCurveFrame.Domain(begin: previous.begin * (1-p) + target.begin * p,
|
||||
end: previous.end * (1-p) + target.end * p)
|
||||
for t in [0.0, 2, 60, 120] {
|
||||
let date = Date(timeIntervalSinceReferenceDate: t)
|
||||
precondition(abs(target.position(date) * 350 * map.scale + map.translation - interpolated.position(date) * 350) < 0.00001)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
print("PASS: timestamp append/full history, pause/reset, missing/nonfinite data, short series, cadence continuity, pause boundaries and 61-point left-edge animation geometry")
|
||||
let frame = PanelCurveFrame(dates: dates, series: [Array(repeating: 0.3, count: 60)], intervals: Array(repeating: 2, count: 60), boundaryDates: [])
|
||||
precondition(frame.dates.count == 60)
|
||||
let domain = PanelCurveFrame.domain(begin: dates.first!, end: dates.last!)
|
||||
precondition(domain.position(dates.first!) == 0 && domain.position(dates.last!) == 1)
|
||||
let irregular = PanelCurveFrame.domain(begin: dates[1], end: dates[5])
|
||||
precondition(abs(irregular.position(dates[2]) - 0.25) < 0.000001)
|
||||
let single = PanelCurveFrame.domain(begin: dates[0], end: dates[0])
|
||||
precondition(single.position(dates[0]) == 1)
|
||||
print("PASS: static timestamp domain, bounded history, missing/nonfinite data, short series, cadence continuity and real pause boundaries")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,8 @@ 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 }, reducedMotion: { reducedMotion }) { _ in
|
||||
openSettings: { settingsRequests += 1 }) { _ in
|
||||
IntervalControl(milliseconds: .constant(1000))
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
@@ -75,9 +74,8 @@ 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))
|
||||
precondition(controller.panel.animationBehavior == .none && !controller.panel.hasShadow)
|
||||
controller.presentation.isPinned = true
|
||||
controller.shutdown()
|
||||
precondition(!controller.presentation.isPinned && !visible)
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
import Foundation
|
||||
|
||||
@main struct TrendScrollChecks {
|
||||
static func main() {
|
||||
precondition(!TrendScroll.isAppend(from: [], to: [0.2]))
|
||||
precondition(TrendScroll.isAppend(from: [0.2, nil], to: [0.2, nil, 0.4]))
|
||||
precondition(!TrendScroll.isAppend(from: [0.2], to: [0.4, 0.5]))
|
||||
let full: [Double?] = (0..<MetricHistory.capacity).map { Double($0) / 100 }
|
||||
precondition(TrendScroll.isAppend(from: full, to: Array(full.dropFirst()) + [nil]))
|
||||
for count in [3, MetricHistory.capacity + 1] {
|
||||
let start = TrendScroll.position(index: count - 2, count: count, progress: 0, scrolling: true)
|
||||
let end = TrendScroll.position(index: count - 1, count: count, progress: 1, scrolling: true)
|
||||
precondition(abs(start - 1) < 0.000001 && abs(end - 1) < 0.000001)
|
||||
let middle = TrendScroll.position(index: count - 2, count: count, progress: 0.5, scrolling: true)
|
||||
precondition(middle < start && abs(start - middle - 0.5 / 59) < 0.000001)
|
||||
}
|
||||
precondition(TrendScroll.position(index: 0, count: 61, progress: 1, scrolling: true) < 0)
|
||||
print("PASS: append detection, missing samples, partial/full history scroll geometry")
|
||||
}
|
||||
}
|
||||
+5
-7
@@ -23,18 +23,16 @@ CHECKS.update({
|
||||
"ProcessEnergyReaderChecks": ["kymo/Core/Models/ProcessMetrics.swift", "kymo/Core/Models/ProcessEnergy.swift", "SMARTService/ProcessEnergyReader.swift"],
|
||||
"BoundedProcessChecks": ["kymo/Core/Services/BoundedProcess.swift"],
|
||||
"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/UI/Components/MetricMotion.swift"],
|
||||
"kymo/Core/Extensions/MetricFormat.swift", "kymo/UI/Components/MetricProgressBar.swift", "kymo/UI/Components/NativeMetricRing.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/Components/MetricMotion.swift"],
|
||||
"NativeContentHostChecks": ["kymo/UI/Components/NativeContentHost.swift", "kymo/UI/Components/AnimatedMetricText.swift",
|
||||
"kymo/UI/Components/MetricMotion.swift"],
|
||||
"kymo/UI/Charts/PanelCurveGeometry.swift", "kymo/UI/Components/NativeMetricRing.swift"],
|
||||
"NativeContentHostChecks": ["kymo/UI/Components/NativeContentHost.swift", "kymo/UI/Components/MetricText.swift"],
|
||||
"ProcessCPULiveChecks": ["kymo/Core/Models/ProcessMetrics.swift", "kymo/Core/Monitors/ProcessMonitor.swift"],
|
||||
"MotionPreferencesChecks": ["kymo/Core/Services/AppearancePreferences.swift", "kymo/Core/Services/SamplingPreferences.swift"],
|
||||
"AppearancePreferencesChecks": ["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",
|
||||
@@ -46,7 +44,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/MetricMotion.swift"],
|
||||
"kymo/UI/Components/FanSpeedIndicator.swift", "kymo/UI/Components/MetricText.swift"],
|
||||
"KeepAwakeChecks": ["kymo/Core/Services/KeepAwakeService.swift"],
|
||||
"LocalizationChecks": ["kymo/Core/Services/LanguagePreferences.swift", "kymo/UI/Components/AppLocalization.swift"],
|
||||
"CodeIdentityChecks": ["kymo/Core/Services/CodeIdentity.swift"],
|
||||
|
||||
Reference in New Issue
Block a user