Compare commits
2
Commits
6300db3d15
..
v1.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1595af6d13 | ||
|
|
fe62b7910b |
@@ -1,6 +1,6 @@
|
||||
# Kymo
|
||||
|
||||
Kymo 是 macOS 菜单栏资源监控工具。菜单栏常驻品牌图标,点击打开资源卡片与进程同页的监控面板。
|
||||
Kymo 是 macOS 菜单栏资源监控工具。菜单栏以竖条显示 CPU、GPU、内存和磁盘占用,以两行文字显示上传和下载速率。点击状态项打开资源卡片与进程同页的监控面板。
|
||||
|
||||
## 当前功能
|
||||
|
||||
@@ -12,7 +12,7 @@ Kymo 是 macOS 菜单栏资源监控工具。菜单栏常驻品牌图标,点
|
||||
- 网络:接口切换、收发速率与累计字节、路径状态、本地和公网 IP 及复制。
|
||||
- 进程:PID、名称、CPU、内存 footprint、CPU 平均功率、线程数六列;路径仍支持搜索和右键复制,无横向滚动条;支持列排序及复制,功率缺失始终排末。
|
||||
|
||||
面板支持固定显示、保持唤醒、暂停 / 恢复采样。首行 CPU / GPU / 内存,次行电池 / 存储 / 网络,第三行进程表跨满内容区;默认三行均高 176pt,面板 648×630pt,小屏退为两列或单列并滚动。CPU、GPU、内存和电池趋势覆盖整卡,存储和网络趋势位于详情下方;CPU 系统 / 用户、内存应用 / 联动 / 压缩按分量堆叠,悬浮查询原始历史;存储 / 网络以绘图区 60% 高度零轴上下显示读 / 写、上传 / 下载,内存不再重复显示容量条。每个逻辑核对应一格,以填充高度表示占用;风扇图标沿用转速档位旋转,暂停、隐藏或系统减弱动态效果时停转。数值随采样直接更新。曲线随新采样平滑平移,遵循系统减弱动态效果。资源和进程同时按可见性采样,后台趋势独立控制。面板刷新默认 2 秒;默认隐藏停止采样,可显式开启后台趋势并配置间隔(新配置 30 秒)。设置窗口提供系统 / 浅色 / 深色外观、简体中文 / 繁體中文 / English 和关于信息。
|
||||
面板支持固定显示、保持唤醒、暂停 / 恢复采样。首行 CPU / GPU / 内存,次行电池 / 存储 / 网络,第三行进程表跨满内容区;默认三行均高 176pt,面板 648×630pt,小屏退为两列或单列并滚动。CPU、GPU、内存和电池趋势覆盖整卡,存储和网络趋势位于详情下方;CPU 系统 / 用户、内存应用 / 联动 / 压缩按分量堆叠,悬浮查询原始历史;存储 / 网络以绘图区 60% 高度零轴上下显示读 / 写、上传 / 下载,内存不再重复显示容量条。每个逻辑核对应一格,以填充高度表示占用;风扇图标沿用转速档位旋转,暂停、隐藏或系统减弱动态效果时停转。数值随采样直接更新。曲线随新采样平滑平移,遵循系统减弱动态效果。资源和进程同时按可见性采样,后台趋势独立控制。面板及亮屏菜单栏指标默认每 2 秒刷新。设置的「菜单栏」页可预览并勾选 CPU、GPU、内存、磁盘和网络,全部取消则显示品牌图标。没有实时展示需求时,可显式开启后台趋势并配置间隔(新配置 30 秒)。设置窗口提供系统 / 浅色 / 深色外观、简体中文 / 繁體中文 / English 和关于信息。
|
||||
|
||||
部分硬件指标依赖机型、驱动与权限,缺失值显示为 `--` 或对应状态。GPU 不提供逐核占用;耗电进程显示系统归属的 CPU 能量区间平均功率,注明可读覆盖范围,不代表完整应用总耗电。指标口径和限制见[监控指标](docs/monitoring.md)。
|
||||
|
||||
@@ -26,7 +26,7 @@ open kymo.xcodeproj
|
||||
xcodebuild -project kymo.xcodeproj -scheme kymo -configuration Debug build
|
||||
```
|
||||
|
||||
在 Xcode 中运行 `kymo`。平时仅显示菜单栏图标,打开设置时临时显示 Dock 图标。左键图标切换面板,右键打开快捷菜单。
|
||||
在 Xcode 中运行 `kymo`。平时通过菜单栏状态项操作,打开设置时临时显示 Dock 图标。左键状态项切换面板,右键打开快捷菜单。
|
||||
|
||||
## 文档与协作
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
| [测试与验证](testing.md) | 统一检查入口、覆盖范围、实际交互与验收边界 |
|
||||
| [测试分发](free-test-distribution.md) | 本地 Release 打包、签名与安装支持范围 |
|
||||
| [UI 设计规范](ui-design-standard.md) | 单页布局、卡片尺寸、字体、颜色、堆叠背景、风扇动效与信息契约 |
|
||||
| [菜单栏动态指标](menu-bar-metrics-plan.md) | 设计图、勾选与预览同步、采样需求及验收结果 |
|
||||
| [卡片背景趋势设计稿](designs/card-background-trends-v1/README.md) | 已采纳的浅色 / 深色风格参考,具体实现以设计规范和代码为准 |
|
||||
|
||||
修改实现时直接更新相应主题;大型变更的临时方案按 [AGENTS.md](../AGENTS.md) 存放在本目录,完成后将有效结论归入主题文档并清理失效记录。
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
| --- | --- |
|
||||
| `kymo/App` | AppKit 入口、生命周期、依赖装配、主菜单和 SwiftUI Settings 场景 |
|
||||
| `kymo/Features/MenuBar` | 状态项、监控 NSPanel、资源卡片、进程表、业务展示投影与本地验证驱动 |
|
||||
| `kymo/Features/Settings` | 通用 / 关于设置页、窗口焦点和 Dock 生命周期 |
|
||||
| `kymo/Features/Settings` | 通用 / 菜单栏 / 关于设置页、窗口焦点和 Dock 生命周期 |
|
||||
| `kymo/Core/Monitors` | 系统采样、报告解析与 SystemSampler actor |
|
||||
| `kymo/Core/Services` | MetricsStore、偏好、XPC 客户端、网络地址、保持唤醒与诊断 |
|
||||
| `kymo/Core/Models` / `Extensions` | 指标、进程身份、有界历史 / 格式化 |
|
||||
@@ -20,7 +20,7 @@ App 装配依赖,方向为 Features → UI → Core → 系统 API。Features
|
||||
|
||||
入口 kymoApp.main() 启动 NSApplication,由 ApplicationLifecycle 管理;应用以 accessory 模式启动,通过 NSHostingSceneRepresentation 注册 Settings。
|
||||
|
||||
MenuPanelController 拥有模板品牌 NSStatusItem 和无边框、可成为 key 的非激活 MonitoringPanel。左键切换面板,右键提供打开 / 隐藏、设置和退出。窗口以状态项所在屏幕可见区域为边界,水平居中,边缘至少留 16pt;最大宽 648pt,常规高 630pt,按卡片内容预算调整,最大高 800pt,并受实际屏幕限制。
|
||||
MenuPanelController 拥有可变宽度 NSStatusItem 和无边框、可成为 key 的非激活 MonitoringPanel。左键切换面板,右键提供打开 / 隐藏、设置和退出。窗口以状态项所在屏幕可见区域为边界,水平居中,边缘至少留 16pt;最大宽 648pt,常规高 630pt,按卡片内容预算调整,最大高 800pt,并受实际屏幕限制。
|
||||
|
||||
单页面板首行 CPU / GPU / 内存,次行电池 / 存储 / 网络,第三行进程表跨满内容区。所有行按最高资源卡片的结构预算等高,默认均为 176pt;资源卡片宽 205⅓pt。32pt 顶栏在品牌标题右上方显示包内短版本号。26pt 底栏从左向右排列开机时间、设备与刷新间隔,面板间隔输入框宽 50pt。宽度小于 620pt 退为两列资源网格,小于 430pt 退为单列;进程始终放在资源之后,高度不足时中间区域整体滚动,表格保留自身滚动。
|
||||
|
||||
@@ -28,22 +28,24 @@ MenuPanelController 拥有模板品牌 NSStatusItem 和无边框、可成为 key
|
||||
|
||||
固定按钮切换 normal / floating 层级。未固定时外部交互或应用失活收起;固定仍可显式关闭。进程表 Esc 依次清空搜索、清除选择、退出搜索焦点,然后关闭面板。隐藏卸载内容、关闭底层窗口资源并移除外部鼠标监听,控制器保留窗口对象供重开。presentation.isOpen 控制内容装配,采样可见性同时要求窗口 isVisible 与 occlusionState 可见;完全遮挡降级采样而保留内容及交互状态。
|
||||
|
||||
MenuBarPreferences 在 UserDefaults 保存勾选集合,首次全选,空集保留。单项和批量选择均一次写入整组,只在空选与有选项之间切换时通知采样需求变化。App 将同一读取闭包注入设置页和状态项。闭包从当前 MetricsSnapshot 生成 MenuBarReading,UI 的 MenuBarMetricStrip 在两处绘制四项竖条占用及独立上下行文本。状态按钮负责点击与辅助功能,绘图子视图透传命中。取消全部后恢复原品牌图标;系统空间不足可能隐藏状态项,此时从 Finder 或 Spotlight 再次打开 Kymo 可进入设置。
|
||||
|
||||
设置窗口打开时转为 regular 模式并恢复焦点,SettingsWindowLifecycle 在关闭后恢复 accessory。关闭最后一个窗口不退出应用;退出时清理状态项、窗口、通知和保持唤醒断言。
|
||||
|
||||
## 采样、状态与并发
|
||||
|
||||
```text
|
||||
系统 API → SystemSampler actor → MetricsSnapshot → MetricsStore(MainActor)
|
||||
│ ├─ snapshot → 资源卡片
|
||||
│ ├─ snapshot → 资源卡片 / 设置预览 / 状态项
|
||||
├─ 慢任务缓存 ├─ processSnapshot / energy → 进程表
|
||||
└─ 单在途进程任务 └─ MetricHistory → 趋势图
|
||||
SMARTService(XPC)→ 只读客户端 → 整机功率 / 慢缓存 / 进程任务
|
||||
实际可见性、详情需求、睡眠与偏好 → MetricsStore 调度
|
||||
```
|
||||
|
||||
MetricsStore 是 MainActor 可观察状态。App 装配时通过 setDetailDemand(processes: true, slowMetrics: true) 同时请求进程和慢指标,Core 只接收需求布尔值,不依赖界面类型。实际可见性、暂停与睡眠统一决定是否执行;隐藏默认停止采样,显式后台趋势仅延续基础历史,不启动进程、footprint、能量或慢报告。
|
||||
MetricsStore 是 MainActor 可观察状态。App 装配时通过 setDetailDemand(processes: true, slowMetrics: true) 同时请求进程和慢指标,Core 只接收需求布尔值,不依赖界面类型。实际可见性、暂停与睡眠统一决定是否执行;面板隐藏时,亮屏且菜单栏至少勾选一项会延续基础采样。只有后台趋势开启时,息屏才按后台间隔记录。这两种需求均不启动进程、footprint、能量或慢报告。
|
||||
|
||||
新配置隐藏不采样;显式启用后台趋势后使用后台间隔,默认 30 秒。已有数值后台间隔且没有显式开关时保留启用状态,显式关闭优先。面板可见默认 2 秒,范围与各指标周期见[监控指标](monitoring.md)。周期按单调时钟从每轮开始安排,不补跑错过轮次;配置变化参考上次发布时间。允许 10% 周期容差,前台最多 200ms、后台最多 1 秒,速率仍按实际经过时间差分。
|
||||
面板可见或菜单栏指标启用且亮屏时按面板间隔更新。两者都不需要时,显式后台趋势按后台间隔更新(默认 30 秒),否则停止采样。已有数值后台间隔且没有显式开关时保留启用状态,显式关闭优先。面板可见默认 2 秒,范围与各指标周期见[监控指标](monitoring.md)。周期按单调时钟从每轮开始安排,不补跑错过轮次;配置变化参考上次发布时间。允许 10% 周期容差,前台最多 200ms、后台最多 1 秒,速率仍按实际经过时间差分。
|
||||
|
||||
SystemSampler actor 持有差分基线。CPU / 内存 Mach 查询取得的 host 发送权在调用结束释放。卷和进程枚举使用 utility detached Task;温度、磁盘健康、电池健康各最多一个慢任务在途。缓存可晚于快照更新,已开始的系统调用可能在需求结束后完成。快照仅保留当前消费者需要的数据;GPU 总占用直接由 gpu.usage 派生。
|
||||
|
||||
@@ -65,7 +67,7 @@ MetricText 用等宽数字直接显示当前读数。连续追加时 NativePanel
|
||||
|
||||
进程列表使用 view-based NSTableView,只创建可见单元格并原地更新。ProcessTableProjection 负责搜索、排序及悬停 / 选择 / 搜索期间的顺序保持。选择由完整 ProcessIdentity 同步,原生委托回调之后才写回 SwiftUI。只显示 PID、名称、CPU、内存、CPU 功率、线程数六列;使用 plain 样式消除额外行内缩进,由原生滚动宿主在 tile 时按可用宽度分配六列,禁用横向滚动及手动扩宽。路径保留在模型中用于搜索与右键复制。原可见口径 / 能量覆盖说明行移至进程标题提示,保留状态且不占行高。ProcessIconCache 保存 30×30 像素缩略图,最多 128 项 / 1 MiB,30 秒过期、LRU 淘汰、内存压力清空,无轮询任务。
|
||||
|
||||
外观、语言和采样配置写入 UserDefaults;固定、暂停、保持唤醒与进程交互不持久化。旧减弱动画偏好键忽略但不清除。AppLanguageScope 传递应用语言并刷新宿主,AppLocalization 为原生菜单取文案;编号风扇保留参数化 Text。
|
||||
外观、语言、菜单栏勾选和采样配置写入 UserDefaults;固定、暂停、保持唤醒与进程交互不持久化。旧减弱动画偏好键忽略但不清除。AppLanguageScope 传递应用语言并刷新宿主,AppLocalization 为原生菜单取文案;编号风扇保留参数化 Text。
|
||||
|
||||
## XPC 与数据边界
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.4 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.2 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.4 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.3 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.5 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.3 MiB |
+1
-1
@@ -24,7 +24,7 @@ kymo/ 使用文件系统同步组,源码自动纳入应用;新增非源码
|
||||
| 采样 | MetricsStore.swift、SystemSampler.swift |
|
||||
| 设置 | AppearanceSettingsView.swift、SettingsWindowLifecycle.swift |
|
||||
|
||||
通常启动仅显示菜单栏图标;打开设置时临时显示 Dock 图标。面板底栏修改可见采样间隔,通用设置控制后台趋势与后台间隔。App 同时启用 Core 的进程与慢指标需求,由实际可见性、暂停与睡眠控制执行。
|
||||
启动后按选择显示菜单栏指标,取消全部时显示品牌图标;打开设置时临时显示 Dock 图标。面板底栏修改可见采样间隔,菜单栏指标共用面板刷新间隔,通用设置控制无实时展示需求时的后台趋势与后台间隔。App 同时启用 Core 的进程与慢指标需求,由实际可见性、暂停与睡眠控制执行。
|
||||
|
||||
颜色与图片放入 Assets.xcassets;字符串位于 Resources 的 Localizable、CPUDetails、Process、StatusItem 四个目录,支持简体中文、繁体中文、英文及跟随系统。SwiftUI 文案使用当前 locale,原生文案通过 AppLocalization 读取。新增文案同步三语、格式参数并检查真实布局:
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Kymo 免费测试包
|
||||
|
||||
当前版本为 **1.2(构建 14)**。主程序与内嵌 SMARTService 共用工程级 MARKETING_VERSION / CURRENT_PROJECT_VERSION,Debug 与 Release 保持一致。
|
||||
当前版本为 **1.3(构建 15)**。主程序与内嵌 SMARTService 共用工程级 MARKETING_VERSION / CURRENT_PROJECT_VERSION,Debug 与 Release 保持一致。
|
||||
|
||||
## 构建与校验
|
||||
|
||||
@@ -22,7 +22,7 @@ SHA-256 核对内容一致性,不等同于 Apple 身份认证;校验值应
|
||||
|
||||
工程最低 macOS 27.0;实际产物架构由打包输出决定。该工具生成未公证的本地 ad-hoc 签名包,没有 Developer ID 分发身份,不上传、不公证、不修改系统安全策略。
|
||||
|
||||
解压后安装完整 kymo.app,先退出旧版再启动新版本;不要单独提取可执行文件或混搭内嵌 XPC。应用通常仅显示菜单栏图标,设置窗口打开时才显示 Dock 图标。
|
||||
解压后安装完整 kymo.app,先退出旧版再启动新版本;不要单独提取可执行文件或混搭内嵌 XPC。应用在菜单栏展示已勾选的指标,空选时显示品牌图标,设置窗口打开时才显示 Dock 图标。
|
||||
|
||||
接收方需核对来源、校验值和本机安全策略,再按 [Apple 对未识别开发者应用的说明](https://support.apple.com/en-gb/102445) 决定是否允许运行。企业管理策略可能禁止运行。本地签名校验通过不能证明其他 Mac 的默认 Gatekeeper 放行,也不代表跨机器安装已验收。
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
# 菜单栏动态指标实施计划
|
||||
|
||||
## 初版
|
||||
|
||||
以 [设置页](designs/menu-bar-metrics-v1/settings.png) 和 [菜单栏](designs/menu-bar-metrics-v1/menu-bar.png) 为视觉依据。现有状态项只显示品牌图标,面板隐藏时默认没有采样需求。目标是让勾选项、预览和真实状态项同步,并保留左键面板与右键菜单入口。
|
||||
|
||||
1. Core 保存有序指标的选择,从已有历史提取最近六个采样点,显示 CPU / GPU 利用率、内存已用比例、磁盘读写与网络收发总速率。首次使用按设计图全选,显式空选持久化。菜单栏有指标且屏幕亮起时使用面板间隔,只请求基础数据;沿用一次采样循环、暂停与睡眠规则。
|
||||
2. UI 共享紧凑柱图和两行文字绘制,App 注入同一选择、历史及语言。Settings 增加独立页,MenuBar 在原生状态按钮内绘制,随选择调整宽度。空选恢复品牌按钮。百分比使用固定刻度,速率使用最近窗口峰值,缺测留空。
|
||||
3. 补齐三语文案与架构说明。构建并检查选项恢复、采样需求切换、速率、缺值和历史断点。本机验证设置、预览、状态项和面板交互。窄屏菜单栏的可用宽度由系统决定,分辨率与刘海影响需在对应环境验收。
|
||||
|
||||
## 实施与验证结果
|
||||
|
||||
三个阶段已完成。状态项与预览共用同一读取闭包、有限历史和绘图组件。保留原生按钮负责打开面板和右键菜单,动态数值使用固定栏宽。
|
||||
|
||||
- Debug 构建通过。MenuBarMetricChecks、SamplingIntervalChecks、DetailDemandChecks、LocalizationChecks、PanelWindowChecks、SettingsWindowChecks 和三语目录检查通过。
|
||||
- 本机隔离应用中,逐项取消五项并反向逐项勾选,每步比对设置复选框、预览和真实状态项的辅助功能内容。名称、顺序和数值一致,全选状态项实测宽 356pt,空选为 24pt。单独重启核对空选,以及仅选 CPU 和网络,两组配置均恢复。
|
||||
- 已检查浅色和深色设置窗口局部截图、外接显示器上的五项状态栏,实测状态项 AX 按压、坐标左击、右键菜单进入设置及键盘 Esc 收起面板。空选的品牌图标也能切换面板。
|
||||
- 本机主显示器在现有菜单排列下会隐藏放不下的整组指标。实测重新打开已运行且无窗口的应用可进入设置,减少选项后状态项可见。不同桌面排列下的可用宽度与长期能耗仍由实际使用环境决定。
|
||||
|
||||
|
||||
## 第三版紧凑布局
|
||||
|
||||
按已确认的[状态项](designs/menu-bar-metrics-v3/menu-bar.png)与[设置预览](designs/menu-bar-metrics-v3/settings.png)调整。四项占用各用 3pt 宽、18pt 高的矩形槽,名称与百分比在右侧上下排列。网络仅显示上下两行速率。设置预览靠近时钟右对齐,继续与状态项共用绘图组件。数据直接取当前快照,沿用已有选项键与采样调度。
|
||||
|
||||
Debug 构建和 MenuBarMetricChecks、PanelWindowChecks、SettingsWindowChecks、LocalizationChecks 通过。本机简体中文五项全选实测 239pt,比首版 356pt 缩短约 33%。隔离副本逐项取消并重新勾选,每步比对预览和实际状态项内容及宽度;空选为 24pt。重启后仅选磁盘和网络的配置恢复。本机主目录卷按系统容量计算为 38%,与同期菜单栏一致。已检查局部截图、左键开合、右键进入设置及 Esc 收起面板。
|
||||
+3
-1
@@ -47,7 +47,7 @@ CPU / GPU / 电池的零值与 100% 分别映射到卡片底边和顶边,内
|
||||
|
||||
| 数据 | 默认 / 周期策略 |
|
||||
| --- | --- |
|
||||
| 常规资源快照 | 面板可见默认 2000ms;新配置隐藏默认停止采样,显式启用后台趋势后默认 30000ms;已有合法后台间隔保留启用和原值,显式开关优先;可设 500–1,800,000ms,步进 100ms |
|
||||
| 常规资源快照 | 面板可见或勾选菜单栏指标且亮屏时默认 2000ms;其余情况仅在显式启用后台趋势时采样,默认 30000ms;已有合法后台间隔保留启用和原值,显式开关优先;可设 500–1,800,000ms,步进 100ms |
|
||||
| 进程 | 请求进程详情且面板实际可见、未暂停 / 睡眠时随采样请求更新;异步独立发布,最多一个在途 |
|
||||
| 进程 CPU 能量 | 复用同轮进程候选,成功后至少 5 秒再读(默认 2 秒轮次下通常约 6 秒);失败 30–600 秒退避,明确不支持后 600 秒;最多一批在途 |
|
||||
| CPU / GPU 温度、风扇 | 一次批量请求中只读取到期类别;各类别成功后至少 10 秒再读,失败独立退避 60–600 秒 |
|
||||
@@ -57,6 +57,8 @@ CPU / GPU / 电池的零值与 100% 分别映射到卡片底边和顶边,内
|
||||
| 公网 IP | 同一路由键成功缓存 600 秒,失败缓存 30 秒,请求超时 5 秒;面板可见时按缓存到期持续刷新,路由键变化、暂停或面板隐藏取消请求及等待,取消不缓存;有效期使用单调时间 |
|
||||
| 趋势 | 全局与每接口最多各 60 点,仅内存保存 |
|
||||
|
||||
菜单栏按 CPU、GPU、内存、磁盘、网络顺序展示。前四项的等高竖条以 0–100% 从底部填充,右侧显示名称与百分比。CPU / GPU 为总利用率,内存为已用 / 总量,磁盘为主目录所在卷的(总容量 − 可用空间)/ 总容量。网络上行在首行(↑),下行在次行(↓),分别复用当前快照的活动 en 接口汇总,每个方向以十进制 B/s 自动换算单位。缺测的读数独立显示 --。
|
||||
|
||||
传感器、卷与慢报告只在请求慢指标的可见采样轮次检查是否到期;后台趋势不启动这些慢读取。快照中的慢指标可能来自之前的缓存。暂停停止发布,不保证取消已进入系统调用的工作。
|
||||
|
||||
常规周期允许系统在配置周期 10% 的容差内合并唤醒,前台最多 200ms、后台最多 1 秒;不是严格实时截止。差分的时间分母始终取实际经过的单调时间,历史保留真实采样日期,配置周期不被改写。
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
Kymo 1.3 可以直接在 macOS 菜单栏查看资源占用和网速。点击状态项,即可在同一面板查看资源趋势和进程列表。
|
||||
|
||||
### 本版更新
|
||||
|
||||
- CPU、GPU、内存和磁盘各用一根竖条和百分比显示当前占用。磁盘显示主目录所在卷的已用空间比例。网络以 ↑ 和 ↓ 分两行显示上传和下载速率。
|
||||
- 在「设置 → 菜单栏」中可逐项勾选、全选或取消全选。预览与实际菜单栏同步,空选时恢复 Kymo 图标,重启后保留选择。亮屏时菜单栏沿用面板刷新间隔,默认每 2 秒更新。
|
||||
- 监控面板将六张资源卡片与进程表放在同一页。CPU 和内存以堆叠趋势呈现,存储读写和网络收发沿零轴分向绘制。进程路径可通过搜索定位,也可右键复制。
|
||||
- 对于没有内置电池且可读取功率传感器的 Mac,电源卡片显示整机即时功率和变化趋势。
|
||||
|
||||
### 下载与安装
|
||||
|
||||
适用于 Apple Silicon(arm64),最低系统版本为 macOS 27.0。本次构建号为 15,使用本地 ad-hoc 签名,未经 Apple 公证。
|
||||
|
||||
ZIP 的 SHA-256 为 `7eb8a746fe30998ef9f380fdf14154744adb6bac9790f16d1241cb88e545d4a8`。将 ZIP 和同名校验文件下载到同一目录后,运行以下命令。
|
||||
|
||||
```sh
|
||||
shasum -a 256 -c kymo-1.3-15-arm64-adhoc.zip.sha256
|
||||
```
|
||||
|
||||
看到 `OK` 后解压,将完整的 `kymo.app` 拖入「应用程序」。如果正在使用旧版,请先退出旧版再替换。
|
||||
@@ -45,6 +45,7 @@ python3 tools/check.py --list
|
||||
| ProcessSectionChecks(--gui) | 生产进程区域固定 176pt,三语 / 浅深色及 340 / 628pt 下移除说明行后表格占满剩余高度且无横向滚动条 |
|
||||
| NativeContentHostChecks(--gui) | 小数末位增减后直接显示最终读数、更新帧与稳定帧像素一致、父环境继承、挂载身份、有限尺寸和卸载 |
|
||||
| NativeProcessTableChecks(--gui) | 原生虚拟表格、原地更新、身份选择、六列窄宽度适配、隐藏路径列但真实菜单复制路径、排序 / 列序 / 复制 / 三语列头、合成 Esc 投递 |
|
||||
| MenuBarMetricChecks | 全选 / 取消全选与单项持久化、隐藏面板后跟随前台间隔调整、息屏与暂停、四项占用、磁盘容量口径、网络双向独立速率、零值与缺测 |
|
||||
| TabPickerChecks、LanguageScopeChecks、SettingsWindowChecks(--gui) | 原生页签选择与键盘、已挂载语言即时切换、设置焦点 / 最小化恢复 / Dock 生命周期 |
|
||||
| PanelWindowChecks(--gui) | 真实 NSPanel 居中、尺寸反馈、固定、遮挡可见性、显式关闭重开和退出复位 |
|
||||
| ReleaseServiceChecks(--services) | 临时 hardened sandbox 主程序调用本轮实际嵌入服务,核对同 UID footprint / 能量与传感器 |
|
||||
@@ -56,6 +57,7 @@ LocalizationCatalogChecks.py 检查全部保留键的三语完整性与格式参
|
||||
|
||||
自动检查可验证模型、原生组件和窗口策略,不能代替正式应用事件。代码改动涉及相应路径时,应在本机完成:
|
||||
|
||||
- 在「设置 → 菜单栏」逐项勾选与取消,核对预览与真实状态项的顺序、数值及宽度。空选保留品牌入口,重启保留选项。系统菜单栏宽度不足时检查重新打开应用的设置入口。
|
||||
- 菜单栏左键打开 / 收起、右键菜单、设置入口与退出。
|
||||
- 六张资源卡片与等高通栏进程同页,三列资源 / 窄屏两列及单列和整体滚动,关闭重开。
|
||||
- 固定 / 取消固定、外部点击、Esc 分层处理,图表悬浮、复制、缺失值。
|
||||
|
||||
@@ -303,7 +303,7 @@
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
CURRENT_PROJECT_VERSION = 14;
|
||||
CURRENT_PROJECT_VERSION = 15;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
@@ -325,7 +325,7 @@
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 27.0;
|
||||
MARKETING_VERSION = 1.2;
|
||||
MARKETING_VERSION = 1.3;
|
||||
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
|
||||
MTL_FAST_MATH = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
@@ -371,7 +371,7 @@
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
CURRENT_PROJECT_VERSION = 14;
|
||||
CURRENT_PROJECT_VERSION = 15;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
DEPLOYMENT_POSTPROCESSING = YES;
|
||||
@@ -388,7 +388,7 @@
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 27.0;
|
||||
MARKETING_VERSION = 1.2;
|
||||
MARKETING_VERSION = 1.3;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
MTL_FAST_MATH = YES;
|
||||
SDKROOT = macosx;
|
||||
|
||||
+20
-2
@@ -17,6 +17,7 @@ import AppKit
|
||||
private let awake = KeepAwakeService()
|
||||
private let presentation = SettingsPresentation()
|
||||
private let appearance = AppearancePreferences()
|
||||
private let menuBarPreferences = MenuBarPreferences()
|
||||
private let language = LanguagePreferences()
|
||||
private var openSettingsAction: (() -> Void)?
|
||||
private var scenes: AnyObject?
|
||||
@@ -35,10 +36,21 @@ import AppKit
|
||||
MainActor.assumeIsolated { self?.metrics.setDisplaySleeping(sleeping) }
|
||||
})
|
||||
}
|
||||
let readings = { [metrics, menuBarPreferences, language] () -> [MenuBarReading] in
|
||||
let selected = menuBarPreferences.selected
|
||||
guard !selected.isEmpty else { return [] }
|
||||
let locale = language.locale
|
||||
return MenuBarReading.readings(selection: selected, snapshot: metrics.snapshot) {
|
||||
AppLocalization.string($0.titleKey, locale: locale)
|
||||
}
|
||||
}
|
||||
menuBarPreferences.onDemandChange = { [metrics] in metrics.setMenuBarEnabled($0) }
|
||||
metrics.setMenuBarEnabled(!menuBarPreferences.selected.isEmpty)
|
||||
let settings = NSHostingSceneRepresentation {
|
||||
Settings {
|
||||
AppLanguageScope(preferences: language, onChange: { self.configureMainMenu() }) { [self] in
|
||||
AppearanceSettingsView(preferences: appearance, language: language, sampling: metrics.sampling, presentation: presentation)
|
||||
AppearanceSettingsView(preferences: appearance, language: language, sampling: metrics.sampling,
|
||||
menuBar: menuBarPreferences, readings: readings, presentation: presentation)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,7 +59,7 @@ import AppKit
|
||||
openSettingsAction = { settings.environment.openSettings() }
|
||||
configureMainMenu()
|
||||
metrics.setDetailDemand(processes: true, slowMetrics: true)
|
||||
menuBar = MenuPanelController(visibility: { [metrics] in metrics.setPanelVisible($0) },
|
||||
menuBar = MenuPanelController(readings: readings, visibility: { [metrics] in metrics.setPanelVisible($0) },
|
||||
menuTitle: { [language] key in
|
||||
AppLocalization.string("status." + key, locale: language.locale, table: "StatusItem")
|
||||
}, openSettings: { [weak self] in self?.settingsCommand() }) { [self] panel in
|
||||
@@ -104,5 +116,11 @@ import AppKit
|
||||
scenes = nil
|
||||
}
|
||||
|
||||
// Finder or Spotlight remains a settings entry point when macOS hides a wide status item.
|
||||
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
|
||||
if !flag { settingsCommand() }
|
||||
return true
|
||||
}
|
||||
|
||||
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { false }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import Foundation
|
||||
|
||||
nonisolated enum MenuBarMetric: String, CaseIterable {
|
||||
case cpu, gpu, memory, disk, network
|
||||
|
||||
var titleKey: String { self == .disk ? "menuBar.disk" : "metric." + rawValue }
|
||||
}
|
||||
|
||||
nonisolated struct MenuBarReading: Equatable {
|
||||
enum Content: Equatable {
|
||||
case usage(Double?)
|
||||
case network(upload: String, download: String)
|
||||
}
|
||||
|
||||
let metric: MenuBarMetric
|
||||
let title: String
|
||||
let content: Content
|
||||
|
||||
static func readings(selection: Set<MenuBarMetric>, snapshot: MetricsSnapshot,
|
||||
title: (MenuBarMetric) -> String) -> [Self] {
|
||||
MenuBarMetric.allCases.filter(selection.contains).map { metric in
|
||||
let content: Content = switch metric {
|
||||
case .cpu: .usage(snapshot.cpu?.usage)
|
||||
case .gpu: .usage(snapshot.gpuUsage)
|
||||
case .memory: .usage(snapshot.memory?.usage)
|
||||
case .disk: .usage(snapshot.disk?.usage)
|
||||
case .network: .network(upload: compactRate(snapshot.uploadRate), download: compactRate(snapshot.downloadRate))
|
||||
}
|
||||
return Self(metric: metric, title: title(metric), content: content)
|
||||
}
|
||||
}
|
||||
|
||||
private static func compactRate(_ value: Double?) -> String {
|
||||
MetricFormat.rate(value).replacingOccurrences(of: ".0 ", with: " ")
|
||||
}
|
||||
|
||||
var accessibilityText: String {
|
||||
switch content {
|
||||
case let .usage(value): "\(title) \(MetricFormat.percent(value))"
|
||||
case let .network(upload, download): "\(title) ↑ \(upload), ↓ \(download)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nonisolated extension Array where Element == MenuBarReading {
|
||||
var accessibilitySummary: String {
|
||||
isEmpty ? "Kymo" : map(\.accessibilityText).joined(separator: ", ")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import Foundation
|
||||
import Observation
|
||||
|
||||
@MainActor @Observable final class MenuBarPreferences {
|
||||
private static let key = "menuBar.metrics"
|
||||
@ObservationIgnored private let defaults: UserDefaults
|
||||
@ObservationIgnored var onDemandChange: ((Bool) -> Void)?
|
||||
private(set) var selected: Set<MenuBarMetric>
|
||||
|
||||
var allSelected: Bool { selected.count == MenuBarMetric.allCases.count }
|
||||
|
||||
init(defaults: UserDefaults = .standard) {
|
||||
self.defaults = defaults
|
||||
selected = defaults.stringArray(forKey: Self.key).map { Set($0.compactMap(MenuBarMetric.init(rawValue:))) }
|
||||
?? Set(MenuBarMetric.allCases)
|
||||
}
|
||||
|
||||
func set(_ metric: MenuBarMetric, enabled: Bool) {
|
||||
var next = selected
|
||||
if enabled { next.insert(metric) } else { next.remove(metric) }
|
||||
replaceSelection(with: next)
|
||||
}
|
||||
|
||||
func setAllSelected(_ enabled: Bool) {
|
||||
replaceSelection(with: enabled ? Set(MenuBarMetric.allCases) : [])
|
||||
}
|
||||
|
||||
private func replaceSelection(with next: Set<MenuBarMetric>) {
|
||||
guard selected != next else { return }
|
||||
let wasEmpty = selected.isEmpty
|
||||
selected = next
|
||||
defaults.set(MenuBarMetric.allCases.filter(selected.contains).map(\.rawValue), forKey: Self.key)
|
||||
if wasEmpty != selected.isEmpty { onDemandChange?(!selected.isEmpty) }
|
||||
}
|
||||
}
|
||||
@@ -15,12 +15,14 @@ final class MetricsStore {
|
||||
private(set) var slowMetricsRequested = true
|
||||
let sampling: SamplingPreferences
|
||||
private var panelDemand: Bool { isPanelVisible && !isDisplaySleeping }
|
||||
private var menuBarEnabled = false
|
||||
private var liveDemand: Bool { panelDemand || (menuBarEnabled && !isDisplaySleeping) }
|
||||
private var processDemand: Bool { panelDemand && processUpdatesRequested }
|
||||
var effectiveMilliseconds: Int { panelDemand ? sampling.panelMilliseconds : sampling.backgroundMilliseconds }
|
||||
private var hasSamplingDemand: Bool { !isSystemSleeping && (panelDemand || sampling.backgroundEnabled) }
|
||||
var effectiveMilliseconds: Int { liveDemand ? sampling.panelMilliseconds : sampling.backgroundMilliseconds }
|
||||
private var hasSamplingDemand: Bool { !isSystemSleeping && (liveDemand || sampling.backgroundEnabled) }
|
||||
// Permit timer coalescing without changing the requested cadence or delta timestamps.
|
||||
private var schedulingTolerance: Duration {
|
||||
.milliseconds(min(effectiveMilliseconds / 10, panelDemand ? 200 : 1_000))
|
||||
.milliseconds(min(effectiveMilliseconds / 10, liveDemand ? 200 : 1_000))
|
||||
}
|
||||
@ObservationIgnored private var generation = 0
|
||||
@ObservationIgnored private var visibilityGeneration = 0
|
||||
@@ -36,7 +38,7 @@ final class MetricsStore {
|
||||
self.sampling.onChange = { [weak self] in
|
||||
guard let self, !self.isPaused,
|
||||
self.effectiveMilliseconds != self.scheduledInterval || self.hasSamplingDemand != (self.task != nil) else { return }
|
||||
self.reschedule(reset: false, sampleImmediately: false)
|
||||
self.reschedule(reset: self.task == nil, sampleImmediately: self.task == nil)
|
||||
}
|
||||
start()
|
||||
}
|
||||
@@ -134,14 +136,25 @@ final class MetricsStore {
|
||||
|
||||
func setDisplaySleeping(_ sleeping: Bool) {
|
||||
guard sleeping != isDisplaySleeping else { return }
|
||||
let wasActive = hasSamplingDemand
|
||||
isDisplaySleeping = sleeping
|
||||
updateDemand(reset: !sampling.backgroundEnabled, sampleImmediately: panelDemand)
|
||||
updateDemand(reset: !wasActive || !hasSamplingDemand, sampleImmediately: liveDemand)
|
||||
}
|
||||
|
||||
func setPanelVisible(_ visible: Bool) {
|
||||
guard isPanelVisible != visible else { return }
|
||||
let wasActive = hasSamplingDemand
|
||||
isPanelVisible = visible
|
||||
updateDemand(reset: !sampling.backgroundEnabled, sampleImmediately: panelDemand)
|
||||
updateDemand(reset: !wasActive || !hasSamplingDemand, sampleImmediately: panelDemand)
|
||||
}
|
||||
|
||||
func setMenuBarEnabled(_ enabled: Bool) {
|
||||
guard menuBarEnabled != enabled else { return }
|
||||
let wasLive = liveDemand
|
||||
let wasActive = hasSamplingDemand
|
||||
menuBarEnabled = enabled
|
||||
guard wasLive != liveDemand, !isPaused, !isSystemSleeping else { return }
|
||||
reschedule(reset: !wasActive || !hasSamplingDemand, sampleImmediately: enabled)
|
||||
}
|
||||
|
||||
/// The caller supplies data needs, without introducing UI types into Core.
|
||||
|
||||
@@ -15,6 +15,8 @@ import Observation
|
||||
#if DEBUG || KYMO_AUDIT
|
||||
private(set) weak var lastHiddenContent: NSView?
|
||||
#endif
|
||||
private let metricStrip = MenuBarMetricStrip()
|
||||
private let readings: () -> [MenuBarReading]
|
||||
private var statusItem: NSStatusItem?
|
||||
private var localMouse: Any?
|
||||
private var globalMouse: Any?
|
||||
@@ -28,10 +30,12 @@ import Observation
|
||||
private var isHiding = false
|
||||
private var preferredContentHeight = PanelLayout.defaultHeight
|
||||
|
||||
init<Content: View>(installStatusItem: Bool = true, visibility: @escaping (Bool) -> Void,
|
||||
init<Content: View>(installStatusItem: Bool = true, readings: @escaping () -> [MenuBarReading] = { [] },
|
||||
visibility: @escaping (Bool) -> Void,
|
||||
menuTitle: @escaping (String) -> String = { $0 },
|
||||
openSettings: @escaping () -> Void = {},
|
||||
@ViewBuilder content: @escaping (PanelPresentation) -> Content) {
|
||||
self.readings = readings
|
||||
self.visibility = visibility
|
||||
self.menuTitle = menuTitle
|
||||
self.openSettings = openSettings
|
||||
@@ -54,13 +58,13 @@ import Observation
|
||||
presentation.onPinChange = { [weak self] pinned in self?.panel.level = pinned ? .floating : .normal }
|
||||
if installStatusItem {
|
||||
let item = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)
|
||||
item.button?.image = NSImage(named: "BrandMark")
|
||||
item.button?.image?.isTemplate = true
|
||||
item.button?.setAccessibilityLabel("Kymo")
|
||||
item.button?.target = self
|
||||
item.button?.action = #selector(statusItemClicked)
|
||||
item.button?.sendAction(on: [.leftMouseUp, .rightMouseUp])
|
||||
statusItem = item
|
||||
metricStrip.setAccessibilityElement(false)
|
||||
item.button?.addSubview(metricStrip)
|
||||
refreshStatusItem()
|
||||
}
|
||||
tokens.append(NotificationCenter.default.addObserver(forName: NSApplication.didChangeScreenParametersNotification, object: nil, queue: .main) { [weak self] _ in
|
||||
MainActor.assumeIsolated { self?.place() }
|
||||
@@ -79,6 +83,29 @@ import Observation
|
||||
})
|
||||
}
|
||||
|
||||
private func refreshStatusItem() {
|
||||
guard let statusItem, let button = statusItem.button else { return }
|
||||
let current = withObservationTracking { readings() } onChange: { [weak self] in
|
||||
Task { @MainActor [weak self] in self?.refreshStatusItem() }
|
||||
}
|
||||
metricStrip.readings = current
|
||||
metricStrip.isHidden = current.isEmpty
|
||||
if current.isEmpty {
|
||||
button.image = NSImage(named: "BrandMark")
|
||||
button.image?.isTemplate = true
|
||||
statusItem.length = NSStatusItem.squareLength
|
||||
} else {
|
||||
button.image = nil
|
||||
let size = metricStrip.intrinsicContentSize
|
||||
let length = size.width + 8
|
||||
if statusItem.length != length { statusItem.length = length }
|
||||
metricStrip.frame = NSRect(x: 4, y: 0, width: size.width, height: button.bounds.height)
|
||||
metricStrip.autoresizingMask = [.height]
|
||||
}
|
||||
button.setAccessibilityLabel("Kymo")
|
||||
button.setAccessibilityValue(current.accessibilitySummary)
|
||||
}
|
||||
|
||||
@objc func togglePanel() { panel.isVisible ? hide() : show() }
|
||||
|
||||
@objc private func statusItemClicked() {
|
||||
|
||||
@@ -6,6 +6,8 @@ struct AppearanceSettingsView: View {
|
||||
@Bindable var preferences: AppearancePreferences
|
||||
@Bindable var language: LanguagePreferences
|
||||
@Bindable var sampling: SamplingPreferences
|
||||
let menuBar: MenuBarPreferences
|
||||
let readings: () -> [MenuBarReading]
|
||||
let presentation: SettingsPresentation
|
||||
@Environment(\.locale) private var locale
|
||||
@State private var selection = SettingsPage.general
|
||||
@@ -14,6 +16,7 @@ struct AppearanceSettingsView: View {
|
||||
Group {
|
||||
switch selection {
|
||||
case .general: generalPage
|
||||
case .menuBar: MenuBarSettingsPage(preferences: menuBar, readings: readings())
|
||||
case .about: aboutPage
|
||||
}
|
||||
}
|
||||
@@ -21,7 +24,7 @@ struct AppearanceSettingsView: View {
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .principal) {
|
||||
NeutralTabPicker(title: "settings.title", selection: $selection,
|
||||
options: [(.general, "settings.general"), (.about, "settings.about")])
|
||||
options: [(.general, "settings.general"), (.menuBar, "settings.menuBar"), (.about, "settings.about")])
|
||||
}
|
||||
.sharedBackgroundVisibility(.hidden)
|
||||
}
|
||||
@@ -120,5 +123,5 @@ private extension AppAppearance {
|
||||
}
|
||||
|
||||
private enum SettingsPage: Hashable {
|
||||
case general, about
|
||||
case general, menuBar, about
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
import SwiftUI
|
||||
|
||||
struct MenuBarSettingsPage: View {
|
||||
let preferences: MenuBarPreferences
|
||||
let readings: [MenuBarReading]
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 18) {
|
||||
HStack(spacing: 8) {
|
||||
Image(systemName: "apple.logo").accessibilityHidden(true)
|
||||
Spacer(minLength: 0)
|
||||
if readings.isEmpty {
|
||||
Image("BrandMark").renderingMode(.template)
|
||||
.resizable().scaledToFit().frame(width: 18, height: 18)
|
||||
} else {
|
||||
MenuBarStripPreview(readings: readings).fixedSize()
|
||||
}
|
||||
Text(verbatim: "09:41").font(.system(size: 11, weight: .medium))
|
||||
}
|
||||
.padding(.horizontal, 10)
|
||||
.frame(height: 36)
|
||||
.background(Color.primary.opacity(0.06), in: RoundedRectangle(cornerRadius: 8))
|
||||
.accessibilityElement(children: .ignore)
|
||||
.accessibilityAddTraits(.isImage)
|
||||
.accessibilityLabel(Text("menuBar.preview \(readings.accessibilitySummary)"))
|
||||
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
HStack {
|
||||
Text("menuBar.items").font(.headline)
|
||||
Spacer()
|
||||
Button {
|
||||
preferences.setAllSelected(!preferences.allSelected)
|
||||
} label: {
|
||||
if preferences.allSelected { Text("menuBar.deselectAll") }
|
||||
else { Text("action.selectAll") }
|
||||
}
|
||||
.controlSize(.small)
|
||||
}
|
||||
VStack(spacing: 0) {
|
||||
ForEach(MenuBarMetric.allCases, id: \.self) { metric in
|
||||
if metric != .cpu { Divider() }
|
||||
HStack {
|
||||
Toggle(isOn: Binding(get: { preferences.selected.contains(metric) },
|
||||
set: { preferences.set(metric, enabled: $0) })) {
|
||||
Text(LocalizedStringKey(metric.titleKey))
|
||||
}
|
||||
.toggleStyle(.checkbox)
|
||||
Spacer()
|
||||
Text(descriptionKey(for: metric)).foregroundStyle(.secondary)
|
||||
}
|
||||
.padding(.horizontal, 12)
|
||||
.frame(height: 42)
|
||||
}
|
||||
}
|
||||
.background(.background, in: RoundedRectangle(cornerRadius: 8))
|
||||
.overlay(RoundedRectangle(cornerRadius: 8).strokeBorder(.quaternary))
|
||||
}
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
.padding(8)
|
||||
}
|
||||
|
||||
private func descriptionKey(for metric: MenuBarMetric) -> LocalizedStringKey {
|
||||
switch metric {
|
||||
case .cpu, .gpu: "menuBar.utilization"
|
||||
case .memory: "menuBar.usedFraction"
|
||||
case .disk: "menuBar.diskSpace"
|
||||
case .network: "menuBar.networkRate"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3289,6 +3289,213 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"settings.menuBar" : {
|
||||
"extractionState" : "manual",
|
||||
"localizations" : {
|
||||
"en" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "Menu Bar"
|
||||
}
|
||||
},
|
||||
"zh-Hans" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "菜单栏"
|
||||
}
|
||||
},
|
||||
"zh-Hant" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "選單列"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"menuBar.preview %@" : {
|
||||
"extractionState" : "manual",
|
||||
"localizations" : {
|
||||
"en" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "Menu bar preview: %@"
|
||||
}
|
||||
},
|
||||
"zh-Hans" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "菜单栏预览:%@"
|
||||
}
|
||||
},
|
||||
"zh-Hant" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "選單列預覽:%@"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"menuBar.items" : {
|
||||
"extractionState" : "manual",
|
||||
"localizations" : {
|
||||
"en" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "Displayed items"
|
||||
}
|
||||
},
|
||||
"zh-Hans" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "显示项目"
|
||||
}
|
||||
},
|
||||
"zh-Hant" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "顯示項目"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"menuBar.deselectAll" : {
|
||||
"extractionState" : "manual",
|
||||
"localizations" : {
|
||||
"en" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "Deselect All"
|
||||
}
|
||||
},
|
||||
"zh-Hans" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "取消全选"
|
||||
}
|
||||
},
|
||||
"zh-Hant" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "取消全選"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"menuBar.disk" : {
|
||||
"extractionState" : "manual",
|
||||
"localizations" : {
|
||||
"en" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "Disk"
|
||||
}
|
||||
},
|
||||
"zh-Hans" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "磁盘"
|
||||
}
|
||||
},
|
||||
"zh-Hant" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "磁碟"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"menuBar.utilization" : {
|
||||
"extractionState" : "manual",
|
||||
"localizations" : {
|
||||
"en" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "Utilization"
|
||||
}
|
||||
},
|
||||
"zh-Hans" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "使用率"
|
||||
}
|
||||
},
|
||||
"zh-Hant" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "使用率"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"menuBar.usedFraction" : {
|
||||
"extractionState" : "manual",
|
||||
"localizations" : {
|
||||
"en" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "Percent used"
|
||||
}
|
||||
},
|
||||
"zh-Hans" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "已用比例"
|
||||
}
|
||||
},
|
||||
"zh-Hant" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "已用比例"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"menuBar.diskSpace" : {
|
||||
"extractionState" : "manual",
|
||||
"localizations" : {
|
||||
"en" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "Disk space used"
|
||||
}
|
||||
},
|
||||
"zh-Hans" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "空间已用比例"
|
||||
}
|
||||
},
|
||||
"zh-Hant" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "空間已用比例"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"menuBar.networkRate" : {
|
||||
"extractionState" : "manual",
|
||||
"localizations" : {
|
||||
"en" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "Upload and download rates"
|
||||
}
|
||||
},
|
||||
"zh-Hans" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "上传和下载速率"
|
||||
}
|
||||
},
|
||||
"zh-Hant" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "上傳和下載速率"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"settings.title" : {
|
||||
"extractionState" : "manual",
|
||||
"localizations" : {
|
||||
@@ -3318,19 +3525,19 @@
|
||||
"en" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "When off, hiding the panel stops recording and leaves gaps in charts. When on, recording follows the background interval. Pausing or system sleep stops recording."
|
||||
"value" : "Menu bar items update at the panel interval while the display is awake. Enable background recording to keep trends when neither is displayed. Pausing or system sleep stops recording."
|
||||
}
|
||||
},
|
||||
"zh-Hans" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "关闭时,隐藏面板停止记录,图表保留空档。开启后按后台间隔记录;暂停或系统睡眠期间不记录。"
|
||||
"value" : "亮屏时,菜单栏指标按面板间隔刷新。面板和菜单栏均不展示指标时,可开启后台记录以延续趋势。暂停或系统睡眠时停止记录。"
|
||||
}
|
||||
},
|
||||
"zh-Hant" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "關閉時,隱藏面板停止記錄,圖表保留空檔。開啟後按背景間隔記錄;暫停或系統睡眠期間不記錄。"
|
||||
"value" : "螢幕亮起時,選單列指標依面板間隔更新。面板與選單列均未顯示指標時,可開啟背景記錄以延續趨勢。暫停或系統睡眠時停止記錄。"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
import AppKit
|
||||
import SwiftUI
|
||||
|
||||
private extension MenuBarMetric {
|
||||
var colorName: String {
|
||||
switch self {
|
||||
case .cpu: "MetricCPU"
|
||||
case .gpu: "MetricGPU"
|
||||
case .memory: "MetricMemory"
|
||||
case .disk: "MetricDisk"
|
||||
case .network: "MetricNetwork"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The same drawing is hosted by the settings preview and by the native status button.
|
||||
final class MenuBarMetricStrip: NSView {
|
||||
private let titleFont = NSFont.systemFont(ofSize: 8.5, weight: .medium)
|
||||
private let valueFont = NSFont.monospacedDigitSystemFont(ofSize: 10, weight: .semibold)
|
||||
private let rateFont = NSFont.monospacedDigitSystemFont(ofSize: 9.5, weight: .medium)
|
||||
private let gaugeWidth: CGFloat = 3
|
||||
private let textInset: CGFloat = 6
|
||||
private let spacing: CGFloat = 4
|
||||
var readings: [MenuBarReading] = [] {
|
||||
didSet {
|
||||
guard readings != oldValue else { return }
|
||||
invalidateIntrinsicContentSize()
|
||||
needsDisplay = true
|
||||
}
|
||||
}
|
||||
|
||||
override var isFlipped: Bool { true }
|
||||
override func hitTest(_ point: NSPoint) -> NSView? { nil }
|
||||
|
||||
private func width(of reading: MenuBarReading) -> CGFloat {
|
||||
switch reading.content {
|
||||
case .network:
|
||||
return ceil(("↓ 999.9 MB/s" as NSString).size(withAttributes: [.font: rateFont]).width)
|
||||
case .usage:
|
||||
let valueWidth = ("100%" as NSString).size(withAttributes: [.font: valueFont]).width
|
||||
let titleWidth = (reading.title as NSString).size(withAttributes: [.font: titleFont]).width
|
||||
return textInset + ceil(max(titleWidth, valueWidth))
|
||||
}
|
||||
}
|
||||
|
||||
override var intrinsicContentSize: NSSize {
|
||||
NSSize(width: readings.reduce(0) { $0 + width(of: $1) } + CGFloat(max(0, readings.count - 1)) * spacing,
|
||||
height: 22)
|
||||
}
|
||||
|
||||
override func draw(_ dirtyRect: NSRect) {
|
||||
var x: CGFloat = 0
|
||||
let top = floor(bounds.midY - 11)
|
||||
for item in readings {
|
||||
switch item.content {
|
||||
case let .usage(fraction):
|
||||
let track = NSRect(x: x, y: top + 2, width: gaugeWidth, height: 18)
|
||||
NSColor.labelColor.withAlphaComponent(0.18).setFill()
|
||||
NSBezierPath(rect: track).fill()
|
||||
if let fraction, fraction.isFinite, fraction > 0 {
|
||||
let height = track.height * min(1, fraction)
|
||||
(NSColor(named: item.metric.colorName) ?? .labelColor).setFill()
|
||||
NSBezierPath(rect: NSRect(x: x, y: track.maxY - height, width: gaugeWidth, height: height)).fill()
|
||||
}
|
||||
drawText(item.title, x: x + textInset, y: top, font: titleFont)
|
||||
drawText(MetricFormat.percent(fraction), x: x + textInset, y: top + 9, font: valueFont)
|
||||
case let .network(upload, download):
|
||||
drawText("↑ \(upload)", x: x, y: top, font: rateFont)
|
||||
drawText("↓ \(download)", x: x, y: top + 10, font: rateFont)
|
||||
}
|
||||
x += width(of: item) + spacing
|
||||
}
|
||||
}
|
||||
private func drawText(_ text: String, x: CGFloat, y: CGFloat, font: NSFont) {
|
||||
(text as NSString).draw(at: NSPoint(x: x, y: y),
|
||||
withAttributes: [.font: font, .foregroundColor: NSColor.labelColor])
|
||||
}
|
||||
}
|
||||
|
||||
struct MenuBarStripPreview: NSViewRepresentable {
|
||||
let readings: [MenuBarReading]
|
||||
func makeNSView(context: Context) -> MenuBarMetricStrip { MenuBarMetricStrip() }
|
||||
func updateNSView(_ view: MenuBarMetricStrip, context: Context) { view.readings = readings }
|
||||
func sizeThatFits(_ proposal: ProposedViewSize, nsView: MenuBarMetricStrip, context: Context) -> CGSize? {
|
||||
nsView.intrinsicContentSize
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
import Foundation
|
||||
|
||||
@main struct MenuBarMetricChecks {
|
||||
@MainActor static func main() async throws {
|
||||
let suite = "kymo-menubar-checks-" + UUID().uuidString
|
||||
let defaults = UserDefaults(suiteName: suite)!
|
||||
defer { defaults.removePersistentDomain(forName: suite) }
|
||||
let preferences = MenuBarPreferences(defaults: defaults)
|
||||
precondition(preferences.selected == Set(MenuBarMetric.allCases))
|
||||
let sampling = SamplingPreferences(defaults: defaults)
|
||||
sampling.panelMilliseconds = 500
|
||||
sampling.backgroundMilliseconds = 30000
|
||||
let store = MetricsStore(sampling: sampling)
|
||||
var demandChanges: [Bool] = []
|
||||
preferences.onDemandChange = { demandChanges.append($0); store.setMenuBarEnabled($0) }
|
||||
store.setMenuBarEnabled(!preferences.selected.isEmpty)
|
||||
try await until { store.history.samples.count >= 2 }
|
||||
precondition(!store.isPanelVisible && store.processSnapshot == nil && store.effectiveMilliseconds == 500)
|
||||
sampling.panelMilliseconds = 1200
|
||||
precondition(store.effectiveMilliseconds == 1200)
|
||||
let beforeChange = store.history.samples.count
|
||||
try await until { store.history.samples.count >= beforeChange + 2 }
|
||||
let times = store.history.samples.suffix(2).map(\.date)
|
||||
precondition(times[1].timeIntervalSince(times[0]) >= 1.1, "Hidden menu bar must adopt the new foreground interval")
|
||||
sampling.panelMilliseconds = 500
|
||||
preferences.set(.gpu, enabled: false)
|
||||
precondition(!preferences.allSelected)
|
||||
preferences.setAllSelected(true)
|
||||
precondition(preferences.allSelected && MenuBarPreferences(defaults: defaults).allSelected && demandChanges.isEmpty)
|
||||
preferences.setAllSelected(false)
|
||||
preferences.setAllSelected(false)
|
||||
precondition(MenuBarPreferences(defaults: defaults).selected.isEmpty && demandChanges == [false])
|
||||
try await expectStopped(store)
|
||||
preferences.setAllSelected(true)
|
||||
precondition(preferences.allSelected && demandChanges == [false, true])
|
||||
preferences.setAllSelected(false)
|
||||
preferences.set(.disk, enabled: true)
|
||||
preferences.set(.cpu, enabled: true)
|
||||
preferences.set(.cpu, enabled: true)
|
||||
let restored = MenuBarPreferences(defaults: defaults)
|
||||
precondition(restored.selected == [.cpu, .disk] && demandChanges == [false, true, false, true])
|
||||
let last = store.snapshot.date
|
||||
try await until { store.snapshot.date > last }
|
||||
precondition(store.history.samples.last?.breakBefore == true)
|
||||
store.setDisplaySleeping(true)
|
||||
try await expectStopped(store)
|
||||
store.setDisplaySleeping(false)
|
||||
let wake = store.snapshot.date
|
||||
try await until { store.snapshot.date > wake }
|
||||
store.togglePause()
|
||||
try await expectStopped(store)
|
||||
checkReadings()
|
||||
print("PASS: menu bar persistence, selection demand, hidden-panel sampling, sleep, pause, ordered vertical gauges, disk space, independent transfer rates and missing data")
|
||||
}
|
||||
|
||||
private static func checkReadings() {
|
||||
let selected = Set(MenuBarMetric.allCases)
|
||||
var snapshot = MetricsSnapshot()
|
||||
snapshot.cpu = CPUMetrics(usage: 0.86, user: 0.86, system: 0, cores: [])
|
||||
snapshot.gpu = GPUMetrics(usage: 0.12, coreCount: nil)
|
||||
snapshot.memory = MemoryMetrics(total: 100, used: 64, wired: 0, compressed: 0, swapUsed: nil, pressure: nil)
|
||||
snapshot.disk = DiskMetrics(total: 1_000, available: 270)
|
||||
snapshot.network = [NetworkInterfaceMetrics(name: "en0", received: 0, sent: 0,
|
||||
download: 2_400_000, upload: 128_000)]
|
||||
func readings() -> [MenuBarReading] {
|
||||
MenuBarReading.readings(selection: selected, snapshot: snapshot) { $0.rawValue }
|
||||
}
|
||||
let result = readings()
|
||||
precondition(result.map(\.metric) == MenuBarMetric.allCases)
|
||||
precondition(result.map(\.content) == [.usage(0.86), .usage(0.12), .usage(0.64), .usage(0.73),
|
||||
.network(upload: "128 KB/s", download: "2.4 MB/s")])
|
||||
snapshot.disk = nil
|
||||
snapshot.diskIO = DiskIOMetrics(read: 40_000_000, written: 60_000_000)
|
||||
snapshot.network = [NetworkInterfaceMetrics(name: "en0", received: 0, sent: 0, download: 0, upload: nil)]
|
||||
precondition(readings()[3].content == .usage(nil))
|
||||
precondition(readings()[4].content == .network(upload: "--", download: "0 B/s"))
|
||||
snapshot.disk = DiskMetrics(total: 100, available: 0)
|
||||
precondition(readings()[3].accessibilityText == "disk 100%")
|
||||
snapshot = MetricsSnapshot()
|
||||
precondition(readings().accessibilitySummary == "cpu --, gpu --, memory --, disk --, network ↑ --, ↓ --")
|
||||
}
|
||||
|
||||
@MainActor private static func expectStopped(_ store: MetricsStore) async throws {
|
||||
let date = store.snapshot.date
|
||||
try await Task.sleep(for: .milliseconds(750))
|
||||
precondition(store.snapshot.date == date && store.processSnapshot == nil)
|
||||
}
|
||||
|
||||
@MainActor private static func until(_ condition: () -> Bool) async throws {
|
||||
let deadline = ContinuousClock.now.advanced(by: .seconds(4))
|
||||
while !condition() && ContinuousClock.now < deadline { try await Task.sleep(for: .milliseconds(20)) }
|
||||
precondition(condition())
|
||||
}
|
||||
}
|
||||
@@ -74,6 +74,9 @@ CHECKS["ResourceCardChecks"] = list(dict.fromkeys(CORE + CHECKS["ResourceCardChe
|
||||
"kymo/Features/MenuBar/MemoryDetailsView.swift", "kymo/Features/MenuBar/StorageDetailsView.swift",
|
||||
]))
|
||||
|
||||
CHECKS["MenuBarMetricChecks"] = CORE
|
||||
CHECKS["PanelWindowChecks"] += CORE + ["kymo/UI/Components/MenuBarMetricStrip.swift"]
|
||||
|
||||
for name in ("PanelLayoutChecks", "PanelWindowChecks"):
|
||||
CHECKS[name].append("kymo/UI/Components/ResourceCardMetrics.swift")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user