From 47e3fe6ca8dad2938b0fe615d9e93f1a03b2c6c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=81=E5=86=9C=E9=98=BF=E6=A5=A0?= Date: Sun, 15 Nov 2026 14:39:55 +0800 Subject: [PATCH] =?UTF-8?q?feat(menubar):=20=E5=B0=86=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E6=A6=82=E8=A7=88=E8=B0=83=E6=95=B4=E4=B8=BA=E4=B8=89=E5=88=97?= =?UTF-8?q?=E4=B8=A4=E8=A1=8C=E5=B8=83=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- docs/architecture.md | 4 +- docs/testing.md | 4 +- kymo/Features/MenuBar/MenuPanelView.swift | 19 ++++---- kymo/Features/MenuBar/PanelLayout.swift | 28 +++++++----- kymoTests/PanelLayoutChecks.swift | 54 ++++++++++++++--------- 6 files changed, 65 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 22b7251..87d24aa 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Kymo 是 macOS 菜单栏资源监控工具。菜单栏常驻品牌图标,点 - 网络:接口切换、收发速率与累计字节、路径状态、本地和公网 IP 及复制。 - 进程:PID、名称、CPU、内存 footprint、CPU 平均功率、线程数和路径;支持搜索、列排序及复制,功率缺失始终排末。 -面板支持固定显示、保持唤醒、暂停 / 恢复采样。概览采用按内容定高的独立双列,常规 640×658pt,小屏可滚动,极窄屏退为单列;进程页独占内容区。概览停止进程 / footprint / 功率读取,进程页卸载资源图表并停用概览慢读取与公网任务,基础趋势跨页连续。保留彩色卡片,数字、曲线和进度条随采样直接更新,不播放应用自定义动画或背景模糊特效;后台记录独立控制。面板刷新默认 2 秒;默认隐藏停止采样,可显式开启后台趋势并配置间隔(新配置 30 秒)。设置窗口提供系统 / 浅色 / 深色外观、简体中文 / 繁體中文 / English 和关于信息。 +面板支持固定显示、保持唤醒、暂停 / 恢复采样。概览采用三列两行网格,首行 CPU / GPU / 内存,次行电池 / 存储 / 网络,同一行卡片等高;常规 960×514pt,小屏退为两列或单列,高度不足时滚动;进程页独占内容区。概览停止进程 / footprint / 功率读取,进程页卸载资源图表并停用概览慢读取与公网任务,基础趋势跨页连续。保留彩色卡片,数字、曲线和进度条随采样直接更新,不播放应用自定义动画或背景模糊特效;后台记录独立控制。面板刷新默认 2 秒;默认隐藏停止采样,可显式开启后台趋势并配置间隔(新配置 30 秒)。设置窗口提供系统 / 浅色 / 深色外观、简体中文 / 繁體中文 / English 和关于信息。 部分硬件指标依赖机型、驱动与权限,缺失值显示为 `--` 或对应状态。GPU 不提供逐核占用;耗电进程显示系统归属的 CPU 能量区间平均功率,注明可读覆盖范围,不代表完整应用总耗电。指标口径和限制见[监控指标](docs/monitoring.md)。 diff --git a/docs/architecture.md b/docs/architecture.md index 0e91059..aa7d342 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -20,9 +20,9 @@ App 装配依赖,方向为 Features → UI → Core → 系统 API。Features 入口 kymoApp.main() 启动 NSApplication,由 ApplicationLifecycle 管理;应用以 accessory 模式启动,通过 NSHostingSceneRepresentation 注册 Settings。 -MenuPanelController 拥有模板品牌 NSStatusItem 和无边框、可成为 key 的非激活 MonitoringPanel。左键切换面板,右键提供打开 / 隐藏、设置和退出。窗口以状态项所在屏幕可见区域为边界,水平居中,边缘至少留 16pt;最大宽 640pt,常规高 658pt,按卡片内容预算调整,最大高 800pt,并受实际屏幕限制。 +MenuPanelController 拥有模板品牌 NSStatusItem 和无边框、可成为 key 的非激活 MonitoringPanel。左键切换面板,右键提供打开 / 隐藏、设置和退出。窗口以状态项所在屏幕可见区域为边界,水平居中,边缘至少留 16pt;最大宽 960pt,常规高 514pt,按卡片内容预算调整,最大高 800pt,并受实际屏幕限制。 -每次显式打开进入概览。概览独立双列:左 CPU / GPU / 内存,右电池 / 存储 / 网络。两行 CPU 核心与一行风扇时两列均高 564pt。宽度小于 560pt 退为单列并将页签另放一行;高度不足时滚动。进程页独占中间内容区,两页共用窗口尺寸。底栏显示设备信息、开机时间和刷新间隔。 +每次显式打开进入概览。概览采用三列两行网格:首行 CPU / GPU / 内存,次行电池 / 存储 / 网络。同一行按最高卡片的内容预算等高对齐;两行 CPU 核心与一行风扇时,两行卡片高度分别为 204pt 和 208pt,列宽 308pt。宽度小于 900pt 退为两列三行,小于 560pt 退为单列并将页签另放一行;重排保持上述逐行阅读顺序,高度不足时滚动。进程页独占中间内容区,两页共用窗口尺寸。底栏显示设备信息、开机时间和刷新间隔。 核心数由静态拓扑、硬件核数及快照共同确定;核心单元格按宽度增加行数,避免文字挤压。风扇在本次打开保留已发现槽位。实际卡片宽度和窗口 contentLayoutRect 驱动布局;仅结构预算变化才请求调整窗口高度。 diff --git a/docs/testing.md b/docs/testing.md index 9a6f381..bffe46a 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -33,7 +33,7 @@ python3 tools/check.py --list | GPUStatisticsChecks、CPUTemperatureChecks、FanChecks、DiskHealthChecks | 当前 GPU 利用率与历史、温度范围与解码、风扇零值 / 无效值、SMART 边界与多物理存储拒绝合并 | | SensorScheduleChecks、BoundedProcessChecks | 各能力独立退避;真实受控子进程输出上限、超时、取消、异常退出与回收 | | ProcessEnergyChecks、ProcessEnergyReaderChecks、ProcessCPULiveChecks | UInt64 能量差分、身份 / UID / 缺失 / 回退 / 时间边界、受控本机能量增长和 Mach 时基 CPU 差分 | -| ProcessSelectionChecks、PanelLayoutChecks、CPUCoreGridChecks | 退出与 PID 复用、搜索 / 排序、640pt / 窄屏预算、核心行数与边界 | +| ProcessSelectionChecks、PanelLayoutChecks、CPUCoreGridChecks | 退出与 PID 复用、搜索 / 排序、960pt 三列两行 / 两列及单列窄屏预算、等高行与滚动边界、核心行数与边界 | | PublicIPAddressChecks | 隔离 URLProtocol、600 秒成功 / 30 秒失败缓存、单调时间、持续刷新及取消,不发送真实请求 | | NetworkAddressChecks、ProcessIconCacheChecks | 沙盒下地址格式 / 速率;图标位图、尺寸、共享、过期、LRU 与严格预算 | | AppearancePreferencesChecks、LocalizationChecks、PresentationChecks | 外观与偏好隔离、语言持久化、编译资源、窗口显式 / 系统外观切换 | @@ -53,7 +53,7 @@ LocalizationCatalogChecks.py 检查全部保留键的三语完整性与格式参 自动检查可验证模型、原生组件和窗口策略,不能代替正式应用事件。代码改动涉及相应路径时,应在本机完成: - 菜单栏左键打开 / 收起、右键菜单、设置入口与退出。 -- 概览六张卡片、双列 / 窄屏单列和滚动,进程分页与关闭重开默认概览。 +- 概览六张卡片、三列两行 / 窄屏两列及单列和滚动,进程分页与关闭重开默认概览。 - 固定 / 取消固定、外部点击、Esc 分层处理,图表悬浮、复制、缺失值。 - 底栏刷新间隔、后台趋势、暂停 / 恢复;概览停止进程读取,进程页停止概览慢读取,基础趋势延续。 - 实际签名沙盒应用的 GPU、温度、风扇、SMART、电池、网络、footprint 和 CPU 功率来源 / 单位 / 不可用状态。 diff --git a/kymo/Features/MenuBar/MenuPanelView.swift b/kymo/Features/MenuBar/MenuPanelView.swift index 62a9937..848a09e 100644 --- a/kymo/Features/MenuBar/MenuPanelView.swift +++ b/kymo/Features/MenuBar/MenuPanelView.swift @@ -53,10 +53,10 @@ struct MenuPanelView: View { header if presentation.page == .overview { if PanelLayout.needsResourceScroll(size: panelSize, heights: cardHeights) { - ScrollView { resourceColumns } + ScrollView { resourceGrid } .frame(maxWidth: .infinity, maxHeight: .infinity) } else { - resourceColumns + resourceGrid .frame(maxHeight: .infinity, alignment: .top) } } else if presentation.isOpen { @@ -91,15 +91,16 @@ struct MenuPanelView: View { .modifier(AppearanceStyle(preferences: preferences)) } - private var resourceColumns: some View { - let groups = PanelLayout.cardColumns(columns: columns) - return HStack(alignment: .top, spacing: PanelStyle.gap) { - ForEach(groups.indices, id: \.self) { column in - VStack(spacing: PanelStyle.gap) { - ForEach(groups[column], id: \.self) { card in + private var resourceGrid: some View { + let rows = PanelLayout.cardRows(columns: columns) + let heights = PanelLayout.rowHeights(columns: columns, heights: cardHeights) + return VStack(spacing: PanelStyle.gap) { + ForEach(rows.indices, id: \.self) { row in + HStack(alignment: .top, spacing: PanelStyle.gap) { + ForEach(rows[row], id: \.self) { card in resourceCard(card) .frame(maxWidth: .infinity) - .frame(height: cardHeights[card]) + .frame(height: heights[row]) .onGeometryChange(for: CGFloat.self) { $0.size.width } action: { width in if card == .cpu { measuredCardWidth = width } } diff --git a/kymo/Features/MenuBar/PanelLayout.swift b/kymo/Features/MenuBar/PanelLayout.swift index 3481564..6e758fc 100644 --- a/kymo/Features/MenuBar/PanelLayout.swift +++ b/kymo/Features/MenuBar/PanelLayout.swift @@ -2,22 +2,27 @@ import Foundation import CoreGraphics nonisolated enum PanelCard: Int, CaseIterable { - case cpu, battery, gpu, storage, memory, network + case cpu, gpu, memory, battery, storage, network } nonisolated enum PanelLayout { static let footerHeight: CGFloat = 26 + static let maximumWidth: CGFloat = 960 static let maximumHeight: CGFloat = 800 static func headerHeight(width: CGFloat) -> CGFloat { width >= 560 ? 32 : 64 } - static func columns(width: CGFloat) -> Int { width >= 560 ? 2 : 1 } + static func columns(width: CGFloat) -> Int { width >= 900 ? 3 : width >= 560 ? 2 : 1 } static func cardWidth(size: CGSize) -> CGFloat { let count = columns(width: size.width) return max(0, (size.width - 20 - CGFloat(count - 1) * 8) / CGFloat(count)) } - /// Preserve location and order; never rebalance columns when values change. - static func cardColumns(columns: Int) -> [[PanelCard]] { - columns > 1 ? [[.cpu, .gpu, .memory], [.battery, .storage, .network]] : [PanelCard.allCases] + /// Keep reading order stable across three-, two- and single-column grids. + static func cardRows(columns: Int) -> [[PanelCard]] { + let cards = PanelCard.allCases + let count = max(1, columns) + return stride(from: 0, to: cards.count, by: count).map { start in + Array(cards[start.. [CGFloat] { - cardColumns(columns: columns).map { cards in - cards.reduce(0) { $0 + (heights[$1] ?? 0) } + CGFloat(max(0, cards.count - 1)) * 8 + static func rowHeights(columns: Int, heights: [PanelCard: CGFloat]) -> [CGFloat] { + cardRows(columns: columns).map { cards in + cards.map { heights[$0] ?? 0 }.max() ?? 0 } } static func resourceHeight(columns: Int, heights: [PanelCard: CGFloat]) -> CGFloat { - columnHeights(columns: columns, heights: heights).max() ?? 0 + let rows = rowHeights(columns: columns, heights: heights) + return rows.reduce(0, +) + CGFloat(max(0, rows.count - 1)) * 8 } static func preferredHeight(width: CGFloat, heights: [PanelCard: CGFloat]) -> CGFloat { @@ -44,7 +50,7 @@ nonisolated enum PanelLayout { } static var defaultHeight: CGFloat { - preferredHeight(width: 640, heights: cardHeights(coreRows: 2, fanCount: nil)) + preferredHeight(width: maximumWidth, heights: cardHeights(coreRows: 2, fanCount: nil)) } static func needsResourceScroll(size: CGSize, heights: [PanelCard: CGFloat]) -> Bool { @@ -53,7 +59,7 @@ nonisolated enum PanelLayout { } static func contentSize(visible: CGRect, chrome: CGSize = .zero, preferredHeight: CGFloat? = nil) -> CGSize { - CGSize(width: max(1, min(640, visible.width - 32 - max(0, chrome.width))), + CGSize(width: max(1, min(maximumWidth, visible.width - 32 - max(0, chrome.width))), height: max(1, min(maximumHeight, preferredHeight ?? defaultHeight, visible.height - 32 - max(0, chrome.height)))) } diff --git a/kymoTests/PanelLayoutChecks.swift b/kymoTests/PanelLayoutChecks.swift index a8e5eee..1eea920 100644 --- a/kymoTests/PanelLayoutChecks.swift +++ b/kymoTests/PanelLayoutChecks.swift @@ -3,7 +3,7 @@ import CoreGraphics @main struct PanelLayoutChecks { static func main() { - precondition(PanelLayout.contentSize(visible: CGRect(x: 0, y: 0, width: 1512, height: 900)).width == 640) + precondition(PanelLayout.contentSize(visible: CGRect(x: 0, y: 0, width: 1512, height: 900)) == CGSize(width: 960, height: 514)) for visible in [CGRect(x: 0, y: 67, width: 1512, height: 882), CGRect(x: -1440, y: -200, width: 1440, height: 800), CGRect(x: 0, y: 24, width: 800, height: 600)] { let content = PanelLayout.contentSize(visible: visible, chrome: CGSize(width: 4, height: 12)) precondition(content.width + 4 <= visible.width - 32 && content.height + 12 <= visible.height - 32) @@ -15,39 +15,51 @@ import CoreGraphics } } let compact = PanelLayout.cardHeights(coreRows: 2, fanCount: 2) - precondition(PanelLayout.cardColumns(columns: 2) == [[.cpu, .gpu, .memory], [.battery, .storage, .network]]) - precondition(PanelLayout.cardColumns(columns: 1).first == PanelCard.allCases) - for width: CGFloat in [480, 559, 560, 600, 640, 960] { + precondition(PanelLayout.cardRows(columns: 3) == [[.cpu, .gpu, .memory], [.battery, .storage, .network]]) + precondition(PanelLayout.cardRows(columns: 2) == [[.cpu, .gpu], [.memory, .battery], [.storage, .network]]) + precondition(PanelLayout.cardRows(columns: 1) == PanelCard.allCases.map { [$0] }) + for width: CGFloat in [480, 559, 560, 600, 640, 899, 900, 960] { let size = CGSize(width: width, height: 820) let columns = PanelLayout.columns(width: width) let cardWidth = PanelLayout.cardWidth(size: size) precondition(abs(CGFloat(columns) * cardWidth + CGFloat(columns - 1) * 8 - (width - 20)) < 0.001) - let cards = PanelLayout.cardColumns(columns: columns).flatMap { $0 } - precondition(cards.count == 6 && Set(cards) == Set(PanelCard.allCases)) + let rows = PanelLayout.cardRows(columns: columns) + precondition(rows.flatMap { $0 } == PanelCard.allCases) + precondition(rows.allSatisfy { $0.count == columns }) + for (row, height) in zip(rows, PanelLayout.rowHeights(columns: columns, heights: compact)) { + precondition(row.allSatisfy { (compact[$0] ?? 0) <= height }, "Every card must fit its aligned row") + } precondition(PanelLayout.needsResourceScroll(size: CGSize(width: width, height: 500), heights: compact)) precondition(!PanelLayout.needsResourceScroll(size: CGSize(width: width, height: 2400), heights: compact)) } - precondition(PanelLayout.columnHeights(columns: 2, heights: compact) == [564, 564], - "The compact memory card must align ordinary two-column bottoms") - precondition(PanelLayout.preferredHeight(width: 640, heights: compact) == 658) - precondition(!PanelLayout.needsResourceScroll(size: CGSize(width: 640, height: 658), heights: compact)) - precondition(PanelLayout.needsResourceScroll(size: CGSize(width: 640, height: 640), heights: compact)) + precondition(PanelLayout.rowHeights(columns: 3, heights: compact) == [204, 208]) + precondition(PanelLayout.rowHeights(columns: 2, heights: compact) == [204, 180, 208]) + precondition(PanelLayout.cardWidth(size: CGSize(width: 960, height: 514)) == 308, + "Three columns must retain readable card widths") + precondition(PanelLayout.preferredHeight(width: 960, heights: compact) == 514) + precondition(PanelLayout.preferredHeight(width: 640, heights: compact) == 702) + precondition(!PanelLayout.needsResourceScroll(size: CGSize(width: 960, height: 514), heights: compact)) + precondition(PanelLayout.needsResourceScroll(size: CGSize(width: 960, height: 513), heights: compact)) + precondition(!PanelLayout.needsResourceScroll(size: CGSize(width: 640, height: 702), heights: compact)) + precondition(PanelLayout.needsResourceScroll(size: CGSize(width: 640, height: 701), heights: compact)) precondition(PanelLayout.needsResourceScroll(size: CGSize(width: 480, height: 800), heights: compact)) - precondition(PanelLayout.columns(width: 640) == 2 && PanelLayout.columns(width: 559) == 1) + precondition(PanelLayout.columns(width: 960) == 3 && PanelLayout.columns(width: 900) == 3) + precondition(PanelLayout.columns(width: 899) == 2 && PanelLayout.columns(width: 560) == 2 && PanelLayout.columns(width: 559) == 1) let tallerCPU = PanelLayout.cardHeights(coreRows: 6, fanCount: 2) - precondition(tallerCPU[.cpu]! > compact[.cpu]! && tallerCPU[.battery] == compact[.battery], - "A taller CPU card must not stretch the opposite battery card") - let moreFans = PanelLayout.cardHeights(coreRows: 2, fanCount: 6) + precondition(PanelLayout.rowHeights(columns: 3, heights: tallerCPU) == [308, 208], + "Extra CPU rows must grow the first grid row without changing the second") + let moreFans = PanelLayout.cardHeights(coreRows: 2, fanCount: 10) precondition(moreFans[.gpu]! > compact[.gpu]! && moreFans[.storage] == compact[.storage]) + precondition(PanelLayout.rowHeights(columns: 3, heights: moreFans) == [244, 208]) let noFans = PanelLayout.cardHeights(coreRows: 2, fanCount: 0) - precondition(noFans[.gpu] == 124 && PanelLayout.columnHeights(columns: 2, heights: noFans) == [524, 564]) - precondition(PanelLayout.preferredHeight(width: 640, heights: noFans) == 658, - "The right column owns the height when the GPU has no fan section") + precondition(noFans[.gpu] == 124 && PanelLayout.rowHeights(columns: 3, heights: noFans) == [204, 208]) + precondition(PanelLayout.preferredHeight(width: 960, heights: noFans) == 514, + "A fanless GPU must keep row alignment with CPU and memory") precondition(PanelLayout.cardHeights(coreRows: 2, fanCount: nil) == compact, "Discovery placeholders must reserve the ordinary fan row") let manyCores = PanelLayout.cardHeights(coreRows: 30, fanCount: 10) - precondition(PanelLayout.preferredHeight(width: 640, heights: manyCores) == 800) - precondition(PanelLayout.needsResourceScroll(size: CGSize(width: 640, height: 800), heights: manyCores)) + precondition(PanelLayout.preferredHeight(width: 960, heights: manyCores) == 800) + precondition(PanelLayout.needsResourceScroll(size: CGSize(width: 960, height: 800), heights: manyCores)) let requested = PanelLayout.contentSize(visible: CGRect(x: 0, y: 0, width: 1512, height: 900), preferredHeight: 732) precondition(requested.height == 732, "A hardware-driven height above the default must be preserved") let input: [ProcessMetrics] = (0..<2000).map { (index: Int) -> ProcessMetrics in @@ -77,6 +89,6 @@ import CoreGraphics } let pidSorted = ProcessTableProjection.rows(input, query: "", sorting: [ProcessSort(key: .pid)], order: []) precondition(pidSorted.first?.id.pid == 2000) - print("PASS: independent columns, hardware-driven heights, scroll and screen limits, column breakpoints, width conservation, resource scrolling, visible-frame bounds/chrome/negative origins, 2000-row CPU/footprint projection, frozen order, path search and empty results") + print("PASS: three-column/two-row grid, aligned hardware-driven row heights, responsive reading order, scroll and screen limits, column breakpoints, width conservation, visible-frame bounds/chrome/negative origins, 2000-row CPU/footprint projection, frozen order, path search and empty results") } }