fix(design): 按概念图重排面板层级并验证真实组件

This commit is contained in:
2026-11-02 23:47:12 +08:00
parent ef358794dc
commit 0e8f598fe6
12 changed files with 221 additions and 86 deletions
+2 -2
View File
@@ -57,9 +57,9 @@ GPU 通过 IOAccelerator 的 PerformanceStatistics / Device Utilization % 读取
### 面板、历史与外观
- Store 在每次发布时向 `MetricHistory` 追加一项,最多保留 60 个样本,包含上/下行和设备读/写;分接口历史按索引/名称有界保存,接口消失清理(跨度由真实时间戳确定);缺失值保留为空,在趋势图中断开,不伪造为零。暂停不追加历史,恢复保留历史并重新建立 CPU 基线。
- 当前正式入口为统一 `MenuPanelView`:CPU/GPU/内存、网络/存储/电池六张 ResourceCard + 同面板进程表,宽度按所属屏幕 visibleFrame 限制在 1240pt 内,高度上限 820pt;≥1160pt 三列、≥900pt 两列、其他单列。工具栏固定,资源卡片独立滚动,进程卡固定高 220–300pt;原生 Table 自带纵横滚动与单元格复用,不在资源滚动容器内。首次布局计入屏幕与窗口 chrome,移动/缩放和布局后约束完整 frame 原点;标准布局七行常驻目标仍待真实窗口复验。
- 当前正式入口为统一 `MenuPanelView`:CPU/GPU/内存、网络/存储/电池六张 ResourceCard + 同面板进程表,宽度按所属屏幕 visibleFrame 限制在 1240pt 内,高度上限 820pt;≥1160pt 三列、≥900pt 两列、其他单列。三列且高度至少 810pt 时,两排资源完整布局,参考尺寸两排分别 230/240pt,进程区使用剩余空间(最小 170pt),独立窗口已实测七行。其他尺寸资源独立滚动,进程仍常驻。原生 Table 自带纵横滚动与单元格复用,不在资源滚动容器内。首次布局计入屏幕与窗口 chrome,移动/缩放和布局后约束完整 frame 原点;最终 MenuBarExtra 定位仍待复验。
- `PanelWindowObserver` 属于 Features/MenuBar,以 NSViewRepresentable 观察所属窗口屏幕、key/close/occlusion 通知,通知 Store 可见性和尺寸;App 仍只装配原生 MenuBarExtra,Core 不依赖 AppKit。
- `PanelTrendChart` 只接收时间戳、双序列、颜色/量纲,Canvas 根据真实时间定位;缺失值和超过 5 秒的间隙断线,不跨暂停连线。CPU/GPU/电量固定 0–100%,内存按物理总字节,网络/IO 两线共用量级;扩大立即、缩小连续十次低于一半后调整。没有独立 Timer 或后台动画循环。新图表追加平移动画尚未实施。
- `PanelTrendChart` 只接收时间戳、双序列、颜色/量纲,Canvas 根据真实时间定位,显示网格、三段刻度与分段面积填充;缺失值和超过 5 秒的间隙断线,不跨暂停连线或补面积。CPU/GPU/电量固定 0–100%,内存按物理总字节,网络/IO 两线共用量级;扩大立即、缩小连续十次低于一半后调整。没有独立 Timer 或后台动画循环。新图表追加平移动画尚未实施。
- 卡片底色和各指标语义色在 Assets 中独立定义深浅模式,操作强调色仍由偏好决定;卡片底色不透明。底部继续保留保持唤醒、暂停/恢复、设置、退出四个操作及胶囊玻璃。数字、曲线和行重排当前直接更新;P5 动效与完整可访问性验收待续。
- 进程表支持 CPU/RSS 排序、名称/PID/路径搜索、同卡内选中路径展示/复制与读取覆盖计数。投影按采样/筛选/排序事件计算并缓存,不在 body 或滚动中重复排序;hover、搜索/焦点和选中冻结旧身份顺序,新增项追加到其后。完整路径在表下方同卡展示以保持固定行高;选中进程退出短暂提示后移除,关闭面板拆卸表并清掉路径状态。路径不持久化,不收集参数或环境变量。
- 旧 MetricRow / HoverDetailPresenter / DetailPlacement 与旧迷你趋势源码暂保留作迁移参照,正式面板已无调用;待真实 UI 回归后在 P6 清理并同步其历史检查程序,不能把源码存在理解为仍有双套交互。
+2
View File
@@ -45,3 +45,5 @@
## 2026-11-02 统一面板重试
本会话 getState 可枚举应用;getApp 按 /private/tmp 路径、工具解析的 /tmp 路径和应用名读取均 timeoutReached。bundle ID 路径提示存在 Xcode 与临时构建两个副本,未误操作 Xcode 副本。用户授权并重启后再次尝试,用户另手动展开面板后按准确测试路径仍超时。原因未确定,不能认定为未授权;本轮没有取得可操作 App 对象,故未进行 AX/坐标点击、原生截图与键盘关闭。旧轮次成功记录不替代本轮新面板验收。
后续概念图对齐迭代中,用户 Xcode 副本 AX 读取恢复;独立同源码窗口的 AX、单窗口截图、按钮点击、搜索、Esc 清空及原生 Scroll Down 动作通过。滚动条 setValue 返回元素失效,最终正式菜单弹窗的定位/关闭仍未复验。建立新应用绑定有两次异常长耗时,timeout 参数未截断;不能据此归因为缺少权限,也不能将独立 WindowGroup 检查扩大为所有 MenuBarExtra 路径通过。
+8
View File
@@ -236,3 +236,11 @@ xcodebuild -project kymo.xcodeproj -scheme kymo -configuration Debug build
### 用户实测后的布局修正(2026-11-02,取代上述首版滚动策略)
用户截图确认面板左侧越界,进程滚动带动全页且卡顿。资源卡片改为独立滚动,进程卡固定 220–300pt 高;原生 SwiftUI Table 管理进程纵横滚动和单元格复用,排序筛选按事件计算并缓存。选中路径在同卡表下方展示,保持固定行高。窗口初始尺寸来自实际屏幕,计入 chrome,并在屏幕/窗口变化和布局后校正 frame 原点。资产 alpha 整数字符串被编译为 1/255,已统一改用浮点格式并检查编译资源。修正需真实窗口复验,计算检查不能证明滚动手感。
### 概念图对齐迭代(2026-11-02)
用户指出首版与概念图差距过大。重新逐张对照深浅概念图:采用标题下大号彩色主值、带刻度/网格/面积填充的趋势、真实 CPU 每核横条、进程 CPU 容量条、单行搜索/分段排序工具栏和紧凑底栏。标准三列且高度至少 810pt 时,两排资源直接布局而不滚动;1240×820pt 参考尺寸第一排 230pt、第二排 240pt,其余空间给约七行进程。第一排宽度比例 35/33/32,第二排 42/27/31;较小屏幕仍保留资源滚动和独立进程表。GPU 没有真实每核数据,继续显示独立降级说明。
本机地址默认显示代表接口/地址,更多地址与卷信息使用可选原生 popover;关键指标无需悬浮外侧详情。Store 每轮采样显式传入可见性,窗口可见判断不再要求 occlusion 标志;空搜索框自动聚焦不冻结初始 CPU 排序,首个有效 CPU 基线到达后建立排行。
已使用同源码、同资源的独立签名沙盒 WindowGroup 测试窗口检查深浅色和三段比例,进程初始可见七行;完成独立滚动、搜索、暂停和 Esc 清空搜索检查。该窗口不是正式 MenuBarExtra,不能替代原生弹窗定位、玻璃材质、外部关闭和完整键盘/VoiceOver 验收。详见验证记录。
+12
View File
@@ -47,3 +47,15 @@ Debug / Release 首版构建通过;不能据此标记 P1、P3、P4 退出条
实际编译资源中 alpha 字符串 "1" 被解析为 0.00392157,GPU 蓝通道也有同样问题。统一使用浮点小数字符串后,PanelAssetChecks 从实际 .app 验证七个深浅色资源存在、alpha=1、GPU 深色蓝通道正确。这解释截图中的透明卡片。
实际签名主应用短时采样(本轮 PID 10589 已退出):4 次快速采样 4.08–13.55ms;首帧 SMART/健康/卷未知,下一帧读到 98%/100%/2 卷,GPU 0–18%、20 核;关闭面板进程快照为空。完整沙盒检查 .app 通过进程/可见性/历史检查,实际三语资源检查通过。用户已有 Xcode 副本 PID 10409 保留。短时数据不证明最坏延迟、长期预算或打开面板的资源占用。
## 概念图对齐与真实组件检查(2026-11-02)
本轮重新读取深浅概念图,对照用户截图,确认先前的 250pt 最小卡片、资源区滚动和空进程区占高破坏了三段比例。已改为标准尺寸完整两排资源、较宽网络卡、大号语义色数值、网格面积图、真实每核横条、进程容量条、紧凑工具栏和底栏;关键数据真实读取,不补模拟 GPU 核心或进程。
原生工具本轮恢复:对用户已有 Xcode 副本只读,取得 818 个进程、520 个主要字段可读的 AX 状态,未退出该进程(PID 11160)。随后将同一实际组件和资源编译成独立沙盒 WindowGroup 测试包,隔离应用标识和测试偏好,不改变用户外观设置;检查约 819–828 个真实进程,标准尺寸初始七行可见。
通过:独立窗口深/浅色窄范围截图、两排资源与进程区完整显示;暂停按钮状态更新;搜索 kymo 从 828 行筛到 4 行(名称/路径匹配);Esc 清空后恢复 828 行;滚动区原生 Scroll Down 动作只更换进程可见行,资源字段保持原位。滚动条 setValue 两次返回元素失效,不能标为通过;普通 scroll 动作移动幅度小,以实际成功的原生滚动动作作为证据。没有以一次滚动判断长时流畅度。
新增 Store 端到端检查通过:打开后在有界等待内出现真实可读进程,关闭立即清空且跨采样周期仍为空。采样每轮显式同步可见性,避免只依赖异步事件留下旧状态。Debug / Release 构建通过。
限制:独立测试包使用不同签名标识,SMART XPC 因身份约束不可读,截图中 SMART 为 --,不能用它判定正式主包回归;正式主包/XPC 协议未改。本轮截图是单个测试窗口,未采集无关屏幕;没有复验最终 MenuBarExtra 的锚点定位、玻璃材质、外部关闭、多屏、三语全矩阵或长期资源预算。UI 工具两次建立新应用绑定耗时异常长,超出调用设置的 timeout;后续已绑定对象的截图/交互约一秒,不把工具耗时计入应用采样性能。
+2 -1
View File
@@ -38,7 +38,8 @@ actor SystemSampler {
// A synchronous OS read may outlive cancellation. Keep the in-flight slot occupied.
}
func sample() -> MetricsSnapshot {
func sample(includeProcesses: Bool? = nil) -> MetricsSnapshot {
if let includeProcesses { setProcessVisible(includeProcesses) }
if !didProbe {
didProbe = true
if ProcessInfo.processInfo.environment["KYMO_PANEL_PROBE"] == "1" { PanelCapabilityProbe.run() }
+1 -1
View File
@@ -24,7 +24,7 @@ final class MetricsStore {
await sampler.setProcessVisible(self?.isPanelVisible == true)
while !Task.isCancelled {
let visibleGeneration = self?.visibilityGeneration
var next = await sampler.sample()
var next = await sampler.sample(includeProcesses: self?.isPanelVisible == true)
guard !Task.isCancelled, self?.generation == currentGeneration else { return }
if self?.isPanelVisible != true || self?.visibilityGeneration != visibleGeneration { next.processes = nil }
self?.snapshot = next
+81 -42
View File
@@ -24,26 +24,40 @@ struct MenuPanelView: View {
}
var body: some View {
VStack(spacing: 10) {
VStack(spacing: 8) {
header
if columns == 3 && panelSize.height >= 810 {
VStack(spacing: 8) {
HStack(alignment: .top, spacing: 8) {
cpuCard.frame(width: (panelSize.width - 36) * 0.35)
gpuCard.frame(width: (panelSize.width - 36) * 0.33)
memoryCard.frame(width: (panelSize.width - 36) * 0.32)
}.frame(height: panelSize.height - 590)
HStack(alignment: .top, spacing: 8) {
networkCard.frame(width: (panelSize.width - 36) * 0.42)
diskCard.frame(width: (panelSize.width - 36) * 0.27)
batteryCard.frame(width: (panelSize.width - 36) * 0.31)
}.frame(height: 240)
}
} else {
ScrollView {
LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 12, alignment: .top), count: columns), alignment: .leading, spacing: 12) {
cpuCard
gpuCard
memoryCard
networkCard
diskCard
batteryCard
}.padding(.trailing, 2)
LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 8, alignment: .top), count: columns), spacing: 8) {
cpuCard.frame(minHeight: 240)
gpuCard.frame(minHeight: 240)
memoryCard.frame(minHeight: 240)
networkCard.frame(minHeight: 250)
diskCard.frame(minHeight: 250)
batteryCard.frame(minHeight: 250)
}
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
if metrics.isPanelVisible {
ProcessTableView(snapshot: snapshot.processes)
.frame(height: min(300, max(220, panelSize.height * 0.36)))
ProcessTableView(snapshot: snapshot.processes, wide: panelSize.width >= 900, logicalCPUCount: snapshot.cpu?.cores.count ?? 1).frame(maxWidth: .infinity, maxHeight: .infinity)
.frame(minHeight: 170)
}
footer
}
.padding(12)
.padding(10)
.frame(width: panelSize.width, height: panelSize.height)
.background(PanelWindowObserver { size, visible in
if panelSize != size { panelSize = size }
@@ -86,17 +100,23 @@ struct MenuPanelView: View {
chart(\.cpu, color: Color("MetricCPU"))
if let cpu = snapshot.cpu {
HStack { line("cpu.user", MetricFormat.percent(cpu.user)); line("cpu.system", MetricFormat.percent(cpu.system)) }
LazyVGrid(columns: [GridItem(.adaptive(minimum: 28), spacing: 4)], spacing: 4) {
LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 6), count: 7), spacing: 5) {
ForEach(Array(cpu.cores.enumerated()), id: \.offset) { index, value in
Text(verbatim: "\(index + 1)").font(.system(size: 9)).frame(maxWidth: .infinity).frame(height: 18)
.background(Color("MetricCPU").opacity(0.12 + value * 0.65), in: .rect(cornerRadius: 3))
.help("\(index + 1): \(MetricFormat.percent(value))")
HStack(spacing: 3) {
Text(verbatim: "\(index + 1)").font(.system(size: 9)).frame(width: 12)
GeometryReader { proxy in
Capsule().fill(Color("MetricCPU").opacity(0.15))
Capsule().fill(Color("MetricCPU")).frame(width: proxy.size.width * value)
}.frame(height: 7)
}.help("\(index + 1): \(MetricFormat.percent(value))")
.accessibilityLabel(Text("cpu.core")).accessibilityValue("\(index + 1): \(MetricFormat.percent(value))")
}
}
}.padding(.vertical, 3)
} else { Text("metric.waiting").foregroundStyle(.secondary) }
line("system.load", snapshot.load.map(MetricFormat.decimal).joined(separator: " / "))
line("panel.uptime", String(format: "%.1f h", snapshot.uptime / 3600))
Spacer(minLength: 0)
HStack { line("system.load", snapshot.load.map(MetricFormat.decimal).joined(separator: " / ")); Spacer(minLength: 8); Text(verbatim: String(format: "%.1f h", snapshot.uptime / 3600)) }
}
}
private var gpuCard: some View {
@@ -105,17 +125,18 @@ struct MenuPanelView: View {
if snapshot.gpuUsage == nil { Text("gpu.unavailable").foregroundStyle(.secondary) }
line("panel.gpuCores", snapshot.gpu?.coreCount.map(String.init) ?? "--")
Label("panel.gpuPerCore", systemImage: "info.circle").foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
Text("panel.gpuSource").font(.system(size: 10)).foregroundStyle(.secondary)
Spacer(minLength: 0)
Text("panel.gpuSource").font(.system(size: 9)).foregroundStyle(.secondary)
}
}
private var memoryCard: some View {
ResourceCard(title: "metric.memory", symbol: "memorychip", color: Color("MetricMemory"), value: MetricFormat.percent(snapshot.memory?.usage)) {
ResourceCard(title: "metric.memory", symbol: "memorychip", color: Color("MetricMemory"), value: snapshot.memory.map { String(format: "%.1f / %.1f GB", Double($0.used) / 1_000_000_000, Double($0.total) / 1_000_000_000) } ?? "--") {
PanelTrendChart(dates: samples.map(\.date),
first: samples.map { $0.memory.map { $0 * Double(snapshot.memory?.total ?? 1) } },
color: Color("MetricMemory"), fixedScale: Double(snapshot.memory?.total ?? 1),
scaleLabel: MetricFormat.bytes(snapshot.memory?.total))
if let m = snapshot.memory {
line("memory.used", "\(MetricFormat.bytes(m.used)) / \(MetricFormat.bytes(m.total))")
GeometryReader { geometry in
HStack(spacing: 0) {
ForEach(Array([m.used - min(m.used, m.wired + m.compressed), m.wired, m.compressed, m.total - min(m.total, m.used)].enumerated()), id: \.offset) { i, bytes in
@@ -127,7 +148,7 @@ struct MenuPanelView: View {
line("memory.app", MetricFormat.bytes(m.used - min(m.used, m.wired + m.compressed)))
HStack { line("memory.wired", MetricFormat.bytes(m.wired)); line("memory.compressed", MetricFormat.bytes(m.compressed)) }
HStack { line("memory.available", MetricFormat.bytes(m.total - min(m.total, m.used))); line("memory.swap", MetricFormat.bytes(m.swapUsed)) }
HStack { Text("memory.pressure").foregroundStyle(.secondary); Spacer(); pressure(m.pressure) }
HStack { Text("memory.pressure").foregroundStyle(.secondary); Spacer(); pressure(m.pressure); Text(verbatim: MetricFormat.percent(m.usage)).foregroundStyle(Color("MetricMemory")) }
} else { Text("metric.waiting") }
}
}
@@ -140,14 +161,19 @@ struct MenuPanelView: View {
}
}
private var networkCard: some View {
ResourceCard(title: "metric.network", symbol: "network", color: Color("MetricNetwork"), value: MetricFormat.rate(total(\.download))) {
ResourceCard(title: "metric.network", symbol: "network", color: Color("MetricNetwork"), value: "↓ " + MetricFormat.rate(total(\.download)), secondaryValue: "↑ " + MetricFormat.rate(total(\.upload))) {
HStack {
Picker("panel.interface", selection: $selectedInterface) {
Text("panel.totalNetwork").tag("")
ForEach(snapshot.network ?? [], id: \.identity) { item in Text(verbatim: item.name).tag(item.identity) }
}.labelsHidden().controlSize(.small)
}.labelsHidden().controlSize(.mini).frame(maxWidth: 200)
Spacer(minLength: 0)
}
if let item = network.first, let address = item.addresses.first {
Text(verbatim: "\(item.name) · \(address)").font(.system(size: 10)).lineLimit(1).truncationMode(.middle).textSelection(.enabled)
}
PanelTrendChart(dates: networkDates, first: networkDownloads, second: networkUploads, color: Color("MetricNetwork"), fixedScale: nil).id(selectedInterface)
if !network.isEmpty && total(\.download) == nil { Text("panel.rateBaseline").foregroundStyle(.secondary) }
HStack { line("network.download", MetricFormat.rate(total(\.download))); line("network.upload", MetricFormat.rate(total(\.upload))) }
HStack { line("network.received", network.isEmpty ? "--" : MetricFormat.bytes(network.reduce(0) { $0 + $1.received })); line("network.sent", network.isEmpty ? "--" : MetricFormat.bytes(network.reduce(0) { $0 + $1.sent })) }
switch snapshot.networkPath {
case .available: Text("network.pathAvailable").foregroundStyle(.secondary)
@@ -155,7 +181,10 @@ struct MenuPanelView: View {
case .requiresConnection: Text("network.pathRequiresConnection").foregroundStyle(.secondary)
case nil: Text("metric.waiting")
}
DisclosureGroup("panel.addresses", isExpanded: $showAddresses) {
HStack {
Button("panel.addresses") { showAddresses.toggle() }.popover(isPresented: $showAddresses) {
VStack(alignment: .leading, spacing: 8) {
Group {
ForEach(network, id: \.identity) { item in
VStack(alignment: .leading, spacing: 3) {
Text(verbatim: item.name).fontWeight(.medium)
@@ -171,22 +200,33 @@ struct MenuPanelView: View {
}
}
Text(selectedInterface.isEmpty ? "panel.totalScope" : "panel.interfaceScope").font(.system(size: 9)).foregroundStyle(.secondary)
}.padding(12).frame(width: 350)
}
Spacer()
Image(systemName: "info.circle").help(Text(selectedInterface.isEmpty ? "panel.totalScope" : "panel.interfaceScope"))
}
}
}
private var networkDates: [Date] { selectedInterface.isEmpty ? samples.map(\.date) : (metrics.history.interfaces[selectedInterface] ?? []).map(\.date) }
private var networkDownloads: [Double?] { selectedInterface.isEmpty ? samples.map(\.download) : (metrics.history.interfaces[selectedInterface] ?? []).map(\.download) }
private var networkUploads: [Double?] { selectedInterface.isEmpty ? samples.map(\.upload) : (metrics.history.interfaces[selectedInterface] ?? []).map(\.upload) }
private var diskCard: some View {
ResourceCard(title: "metric.disk", symbol: "internaldrive", color: Color("MetricDisk"), value: MetricFormat.percent(snapshot.disk?.usage)) {
Text("disk.homeVolume").foregroundStyle(.secondary)
line("memory.used", snapshot.disk.map { "\(MetricFormat.bytes($0.total - min($0.total, $0.available))) / \(MetricFormat.bytes($0.total))" } ?? "--")
ResourceCard(title: "metric.disk", symbol: "internaldrive", color: Color("MetricDisk"), value: snapshot.disk.map { String(format: "%.0f / %.0f GB", Double($0.total - min($0.total, $0.available)) / 1_000_000_000, Double($0.total) / 1_000_000_000) } ?? "--") {
PanelTrendChart(dates: samples.map(\.date), first: samples.map(\.read), second: samples.map(\.write), color: Color("MetricDisk"), secondColor: Color("MetricMemory"), fixedScale: nil)
Text("disk.physicalIO").foregroundStyle(.secondary)
HStack { line("disk.read", MetricFormat.rate(snapshot.diskIO?.read)); line("disk.write", MetricFormat.rate(snapshot.diskIO?.written)) }
HStack { line("disk.remainingLife", MetricFormat.percent(snapshot.diskHealth?.remainingLife)); line("disk.powerOnHours", snapshot.diskHealth?.powerOnHours.map { "\($0) h" } ?? "--") }
Text("panel.smartScope").font(.system(size: 9)).foregroundStyle(.secondary)
if let date = snapshot.diskHealthDate { Text(date, style: .time).font(.system(size: 9)).foregroundStyle(.secondary) }
DisclosureGroup("disk.volumes", isExpanded: $showVolumes) {
Spacer(minLength: 0)
Button("disk.volumes") { showVolumes.toggle() }.popover(isPresented: $showVolumes) {
VStack(alignment: .leading, spacing: 8) {
Text("disk.homeVolume")
Text("panel.smartScope").foregroundStyle(.secondary)
Group {
ForEach(snapshot.volumes ?? [], id: \.path) { volume in
VStack(alignment: .leading) {
Text(verbatim: volume.name).lineLimit(1).truncationMode(.middle)
@@ -195,6 +235,9 @@ struct MenuPanelView: View {
}
Text("panel.apfsScope").font(.system(size: 9)).foregroundStyle(.secondary)
}
}.padding(12).frame(width: 330)
}
}
}
private var batteryCard: some View {
@@ -211,7 +254,7 @@ struct MenuPanelView: View {
else if let minutes = battery.minutesRemaining { Text(verbatim: "\(minutes) min") }
else { Text("battery.timeUnknown") }
}
if let date = snapshot.batteryHealthDate { Text(date, style: .time).font(.system(size: 9)).foregroundStyle(.secondary) }
} else {
Text(snapshot.batteryState == .absent ? "panel.noBattery" : "panel.batteryFailed").foregroundStyle(.secondary)
}
@@ -219,11 +262,7 @@ struct MenuPanelView: View {
}
private var footer: some View {
HStack(spacing: 8) {
VStack(alignment: .leading, spacing: 2) {
Text(verbatim: "Kymo").font(.system(size: 12, weight: .semibold))
Text(verbatim: "v\(Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "--")")
.font(.system(size: 9)).foregroundStyle(.tertiary)
}
Text(verbatim: "v\(Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "--")").font(.system(size: 10)).foregroundStyle(.secondary)
Spacer()
HStack(spacing: 2) {
Button { keepAwake.toggle() } label: {
@@ -258,7 +297,7 @@ struct MenuPanelView: View {
.glassEffect(.regular, in: .capsule)
}
.controlSize(.small)
.padding(.horizontal, 8).padding(.vertical, 6)
.padding(.horizontal, 2).padding(.vertical, 0)
}
}
@@ -278,7 +317,7 @@ private struct FooterButtonBody<Content: View>: View {
var body: some View {
content()
.frame(width: 34, height: 34)
.frame(width: 26, height: 24)
.background {
Circle().fill(.primary.opacity(isPressed ? 0.16 : (isHovered ? 0.08 : 0)))
}
@@ -35,7 +35,7 @@ struct PanelWindowObserver: NSViewRepresentable {
let chrome = CGSize(width: max(0, window.frame.width - window.contentLayoutRect.width),
height: max(0, window.frame.height - window.contentLayoutRect.height))
let size = PanelLayout.contentSize(visible: frame, chrome: chrome)
let visible = window.isVisible && window.occlusionState.contains(.visible)
let visible = window.isVisible
DispatchQueue.main.async { [weak self, weak window] in
guard let self, let window else { return }
self.update(size, visible)
+40 -17
View File
@@ -3,6 +3,8 @@ import AppKit
struct ProcessTableView: View {
let snapshot: ProcessSnapshot?
var wide: Bool = true
var logicalCPUCount: Int = 1
@State private var search = ""
@State private var byMemory = false
@State private var hovering = false
@@ -11,7 +13,7 @@ struct ProcessTableView: View {
@State private var departed: ProcessMetrics?
@FocusState private var searchFocused: Bool
private var held: Bool { hovering || selected != nil || searchFocused || !search.isEmpty }
private var held: Bool { hovering || selected != nil || !search.isEmpty }
private var selectedRow: ProcessMetrics? { rows.first { $0.id == selected } }
private var exitedSelection: ProcessIdentity? {
guard let selected, snapshot != nil, !rows.contains(where: { $0.id == selected }) else { return nil }
@@ -20,22 +22,18 @@ struct ProcessTableView: View {
var body: some View {
VStack(alignment: .leading, spacing: 6) {
HStack {
Label("panel.processes", systemImage: "list.bullet.rectangle").fontWeight(.semibold)
Text(verbatim: "\(snapshot?.readable ?? 0) / \(snapshot?.enumerated ?? 0) · \(rows.count)")
.foregroundStyle(.secondary).help(Text("panel.coverage"))
if wide {
HStack(spacing: 10) {
processTitle
Image(systemName: "info.circle").foregroundStyle(.secondary).help(Text("panel.processScope"))
Spacer(minLength: 0)
if held { Button("panel.liveSort") { selected = nil; rebuild(retainOrder: false) } }
Picker("panel.sort", selection: $byMemory) {
Text("CPU %").tag(false)
Text("panel.rss").tag(true)
}.labelsHidden().frame(width: 100)
if held { Button { selected = nil; rebuild(retainOrder: false) } label: { Image(systemName: "arrow.up.arrow.down") }.help(Text("panel.liveSort")) }
searchField.frame(width: 220)
sorting.frame(width: 160)
}
HStack {
Text("panel.processScope").font(.system(size: 10)).foregroundStyle(.secondary).lineLimit(2)
Spacer(minLength: 4)
TextField("panel.search", text: $search).textFieldStyle(.roundedBorder)
.frame(width: 210).focused($searchFocused)
} else {
HStack { processTitle; Spacer(); sorting.frame(width: 140) }
searchField
}
if snapshot?.failed == true { Text("panel.processFailed") }
else if snapshot == nil { Text("metric.waiting").foregroundStyle(.secondary) }
@@ -44,7 +42,15 @@ struct ProcessTableView: View {
TableColumn("PID") { row in Text(verbatim: "\(row.id.pid)") }.width(48)
TableColumn("panel.name") { row in Text(verbatim: row.name).lineLimit(1) }.width(min: 90, ideal: 140, max: 180)
TableColumn("panel.path") { row in Text(verbatim: row.path ?? "--").lineLimit(1).truncationMode(.middle).foregroundStyle(.secondary) }.width(min: 150, ideal: 400)
TableColumn("CPU %") { row in Text(verbatim: row.cpu.map { String(format: "%.1f", $0 * 100) } ?? "--") }.width(62)
TableColumn("CPU %") { row in
HStack(spacing: 6) {
GeometryReader { proxy in
Capsule().fill(Color("MetricCPU").opacity(0.15))
if let cpu = row.cpu { Capsule().fill(Color("MetricCPU")).frame(width: proxy.size.width * min(1, max(0, cpu / Double(max(1, logicalCPUCount))))) }
}.frame(width: 45, height: 6).accessibilityHidden(true)
Text(verbatim: row.cpu.map { String(format: "%.1f", $0 * 100) } ?? "--").frame(maxWidth: .infinity, alignment: .trailing)
}
}.width(105)
TableColumn("panel.rss") { row in Text(verbatim: row.residentBytes.map { String(format: "%.1f MB", Double($0) / 1_000_000) } ?? "--") }.width(85)
TableColumn("panel.threads") { row in
HStack { Text(verbatim: row.threads.map(String.init) ?? "--"); if row.restricted { Image(systemName: "lock").accessibilityLabel(Text("panel.restricted")) } }
@@ -52,6 +58,7 @@ struct ProcessTableView: View {
}
.font(.system(size: 11)).monospacedDigit()
.tableStyle(.inset(alternatesRowBackgrounds: true))
.scrollContentBackground(.hidden)
.transaction { $0.animation = nil }
.overlay { if snapshot != nil && rows.isEmpty && snapshot?.failed != true { Text("panel.noResults").foregroundStyle(.secondary).allowsHitTesting(false) } }
if let row = selectedRow {
@@ -67,7 +74,7 @@ struct ProcessTableView: View {
.background(Color("PanelCard"), in: .rect(cornerRadius: 14))
.overlay(RoundedRectangle(cornerRadius: 14).strokeBorder(.primary.opacity(0.1)))
.onAppear { rebuild(retainOrder: false) }
.onChange(of: snapshot?.date) { _, _ in rebuild(retainOrder: held) }
.onChange(of: snapshot?.date) { _, _ in rebuild(retainOrder: held && (byMemory ? rows.contains { $0.residentBytes != nil } : rows.contains { $0.cpu != nil })) }
.onChange(of: search) { _, _ in rebuild(retainOrder: held) }
.onChange(of: byMemory) { _, _ in rebuild(retainOrder: false) }
.onChange(of: selected) { _, _ in if let row = selectedRow { departed = row } }
@@ -85,6 +92,22 @@ struct ProcessTableView: View {
else { NSApp.keyWindow?.close() }
}
}
private var processTitle: some View {
HStack(spacing: 8) {
Label("panel.processes", systemImage: "list.bullet.rectangle").fontWeight(.semibold)
Text(verbatim: "\(snapshot?.readable ?? 0) / \(snapshot?.enumerated ?? 0) · \(rows.count)")
.foregroundStyle(.secondary).help(Text("panel.coverage"))
}
}
private var searchField: some View {
TextField("panel.search", text: $search).textFieldStyle(.roundedBorder).focused($searchFocused)
}
private var sorting: some View {
Picker("panel.sort", selection: $byMemory) {
Text("CPU %").tag(false)
Text("panel.rss").tag(true)
}.labelsHidden().pickerStyle(.segmented).controlSize(.small)
}
private func rebuild(retainOrder: Bool) {
rows = ProcessTableProjection.rows(snapshot?.rows ?? [], query: search, byMemory: byMemory, order: retainOrder ? rows.map(\.id) : [])
}
+42 -8
View File
@@ -13,35 +13,69 @@ struct PanelTrendChart: View {
@State private var smallSamples = 0
private var maximum: Double { max(1, (first + second).compactMap { $0 }.filter(\.isFinite).max() ?? 1) }
private var middleLabel: String {
if let fixedScale { return fixedScale == 1 ? "50%" : MetricFormat.bytes(UInt64(max(0, fixedScale / 2))) }
return MetricFormat.rate(retainedScale / 2)
}
var body: some View {
VStack(spacing: 2) {
HStack {
HStack(spacing: 5) {
VStack(alignment: .trailing) {
Text(verbatim: scaleLabel ?? (fixedScale == nil ? MetricFormat.rate(retainedScale) : "100%"))
Spacer()
}.font(.system(size: 9)).foregroundStyle(.secondary)
.lineLimit(1).minimumScaleFactor(0.75)
Spacer(minLength: 0)
Text(verbatim: middleLabel).lineLimit(1).minimumScaleFactor(0.75)
Spacer(minLength: 0)
Text(verbatim: "0")
}.font(.system(size: 8)).foregroundStyle(.secondary).frame(width: 52, height: 48)
Canvas { context, size in
var grid = Path()
for step in 0...10 {
let x = size.width * Double(step) / 10
grid.move(to: CGPoint(x: x, y: 0)); grid.addLine(to: CGPoint(x: x, y: size.height))
}
for step in 0...2 {
let y = size.height * Double(step) / 2
grid.move(to: CGPoint(x: 0, y: y)); grid.addLine(to: CGPoint(x: size.width, y: y))
}
context.stroke(grid, with: .color(color.opacity(0.14)), lineWidth: 0.5)
guard let begin = dates.first, let end = dates.last, end > begin else { return }
let scale = fixedScale ?? retainedScale
for (values, tint) in [(first, color), (second, secondColor)] {
var path = Path()
var connected = false
var fill = Path()
var runStart: CGPoint?
var runEnd: CGPoint?
func closeRun() {
guard let start = runStart, let end = runEnd else { return }
fill.addLine(to: CGPoint(x: end.x, y: size.height))
fill.addLine(to: CGPoint(x: start.x, y: size.height)); fill.closeSubpath()
runStart = nil; runEnd = nil
}
for index in dates.indices {
guard index < values.count, let value = values[index], value.isFinite else { connected = false; continue }
if index > 0 && dates[index].timeIntervalSince(dates[index - 1]) > 5 { connected = false }
guard index < values.count, let value = values[index], value.isFinite else { closeRun(); connected = false; continue }
if index > 0 && dates[index].timeIntervalSince(dates[index - 1]) > 5 { closeRun(); connected = false }
let point = CGPoint(x: size.width * dates[index].timeIntervalSince(begin) / end.timeIntervalSince(begin),
y: size.height * (1 - min(1, max(0, value / scale))))
if connected { path.addLine(to: point) } else { path.move(to: point) }
if connected { path.addLine(to: point); fill.addLine(to: point) }
else { path.move(to: point); fill.move(to: point); runStart = point }
runEnd = point
connected = true
}
closeRun()
context.fill(fill, with: .linearGradient(Gradient(colors: [tint.opacity(0.45), tint.opacity(0.03)]), startPoint: .zero, endPoint: CGPoint(x: 0, y: size.height)))
context.stroke(path, with: .color(tint), style: StrokeStyle(lineWidth: 1.5, lineCap: .round))
}
}.frame(height: 44)
}.frame(height: 48)
}
HStack {
if let date = dates.first { Text(date, style: .time) }
Spacer()
if let date = dates.last { Text(date, style: .time) }
}.font(.system(size: 9)).foregroundStyle(.secondary)
}.font(.system(size: 9)).foregroundStyle(.secondary).frame(maxWidth: .infinity)
}
.frame(maxWidth: .infinity)
.onAppear { retainedScale = maximum }
.onChange(of: dates.last) { _, _ in
let target = maximum
+14 -10
View File
@@ -5,22 +5,26 @@ struct ResourceCard<Content: View>: View {
let symbol: String
let color: Color
let value: String
var secondaryValue: String? = nil
@ViewBuilder var content: () -> Content
var body: some View {
VStack(alignment: .leading, spacing: 8) {
HStack {
Label(title, systemImage: symbol).font(.system(size: 13, weight: .semibold)).foregroundStyle(color)
Spacer(minLength: 6)
Text(verbatim: value).font(.system(size: 20, weight: .semibold, design: .rounded)).monospacedDigit()
VStack(alignment: .leading, spacing: 4) {
Label { Text(title).foregroundStyle(.primary) } icon: {
Image(systemName: symbol).foregroundStyle(color)
}.font(.system(size: 13, weight: .semibold))
HStack(alignment: .firstTextBaseline) {
Text(verbatim: value).font(.system(size: 27, weight: .semibold, design: .rounded))
.foregroundStyle(color).monospacedDigit().lineLimit(1).minimumScaleFactor(0.8)
Spacer(minLength: 4)
if let secondaryValue { Text(verbatim: secondaryValue).font(.system(size: 15, weight: .semibold)).foregroundStyle(color).lineLimit(1) }
}
content()
Spacer(minLength: 0)
}
.font(.system(size: 11))
.padding(12)
.frame(maxWidth: .infinity, minHeight: 250, alignment: .topLeading)
.background(Color("PanelCard"), in: .rect(cornerRadius: 14))
.overlay(RoundedRectangle(cornerRadius: 14).strokeBorder(.primary.opacity(0.1)))
.padding(10)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
.background(Color("PanelCard"), in: .rect(cornerRadius: 10))
.overlay(RoundedRectangle(cornerRadius: 10).strokeBorder(.primary.opacity(0.14)))
}
}
+12
View File
@@ -37,6 +37,18 @@ import Foundation
await sampler.setProcessVisible(true)
let reopened = await sampler.sample()
precondition(reopened.processes == nil)
let store = MetricsStore()
store.setPanelVisible(true)
for _ in 0..<40 {
if store.snapshot.processes != nil { break }
try? await Task.sleep(for: .milliseconds(200))
}
precondition(store.snapshot.processes?.readable ?? 0 > 0)
store.setPanelVisible(false)
precondition(store.snapshot.processes == nil)
try? await Task.sleep(for: .milliseconds(2200))
precondition(store.snapshot.processes == nil)
store.togglePause()
print("PASS: process CPU boundaries/live baseline, GPU range, VPN total exclusion, bounded interface history, visibility reset")
}
}