diff --git a/docs/architecture.md b/docs/architecture.md index 2492109..25718ed 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -212,3 +212,7 @@ CPU、GPU、电池在三列及窄屏网格中共享显式行高:基础 260pt 内存分类历史由 MetricHistory 随每次采样保存应用、联动、压缩的字节值,缺失保持 nil,不使用当前分类回填过去。PanelTrendChart 支持可选四序列;内存采用总量与三类分量同一容量轴,配色与分类条一致,总量单独使用青色。 存储卡片由 MenuPanelView 装配趋势与 StorageDetailsView:前者仍显示全部块设备读写,后者展示主目录所在卷已用/可用容量、利用率、物理设备预计剩余寿命与通电时间,并通过回调打开原有卷详情。容量条整体 Capsule 裁切且不设最小填充宽度;未知值显示 --,不生成健康状态判断。两类统计范围分别通过图表下方标签和容量标题帮助说明。底部三列双行左对齐、竖线分隔,不显示更新频率提示,不改变采样链路。 + +### 网络卡片布局 + +网络卡片使用单行接口选择与默认接口地址,保留地址复制和接口地址详情浮层;标题上下行速率分别使用下载蓝、上传琥珀色。趋势图可关闭图例实时值(悬浮历史值不受影响),避免与标题重复。底部累计接收、累计发送及系统网络路径状态按三列双行展示。系统路径可用不代表外网探测成功,累计流量仍为所选接口的系统计数,总体仅汇总活动 en 接口。未知速率显示 --,不以零替代。 diff --git a/docs/unified-panel-validation.md b/docs/unified-panel-validation.md index 79a2d23..062d675 100644 --- a/docs/unified-panel-validation.md +++ b/docs/unified-panel-validation.md @@ -232,3 +232,10 @@ GPU 专项第二轮:已完成 LLDB 失败分支定位、探针调用原样转 - 按概念图新增容量分布、已用/可用双行信息;底部剩余寿命、通电时间、本地卷入口三列左对齐,删除重复读写数据。 - 容量条整体圆角裁切,不设最小填充宽度;遵循减少动态效果。保持主目录卷容量与全部块设备 I/O 的原有统计口径。 - Debug 签名构建、git diff --check、本地化 JSON 校验通过。保留用户已有 Xcode 启动实例(PID 45331),未重启;实际 240pt 卡片布局、卷详情弹窗与低值动画尚待新版本运行验收。 + +### 网络卡片重排(2026-11-03) + +- 上下行标题独立配色,图例只保留标签;接口选择、默认 IP 和复制同排。 +- 累计接收/发送与网络路径状态三列双行,保留地址详情与统计范围说明。 +- 已通过:标准 Debug 签名构建、Git 空白检查、新增状态标题三语言资源检查。 +- 已读取现有面板的辅助功能状态,确认运行实例仍是旧网络布局;未重启用户的 Xcode 实例,因此新版实际接口切换、地址复制、地址浮层及窄宽度排版仍待重新运行后验收。 diff --git a/kymo/Features/MenuBar/MenuPanelView.swift b/kymo/Features/MenuBar/MenuPanelView.swift index ec1929c..7818be0 100644 --- a/kymo/Features/MenuBar/MenuPanelView.swift +++ b/kymo/Features/MenuBar/MenuPanelView.swift @@ -255,29 +255,54 @@ struct MenuPanelView: View { } } private var networkCard: some View { - 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(.mini).frame(maxWidth: 200) + ResourceCard(title: "metric.network", symbol: "network", color: Color("MetricNetwork"), value: "↓ " + MetricFormat.rate(total(\.download)), secondaryValue: "↑ " + MetricFormat.rate(total(\.upload)), valueColor: Color("MetricMemory"), secondaryValueColor: Color("SeriesUpload")) { + HStack(spacing: 6) { + 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(.mini).frame(maxWidth: 150) + Divider().frame(height: 14) + if let item = addressInterface { + let address = item.addresses.first(where: { !$0.contains(":") }) ?? item.addresses.first + Text(verbatim: "\(item.name) · \(address ?? "--")") + .lineLimit(1).minimumScaleFactor(0.7).textSelection(.enabled) + Spacer(minLength: 0) + if let address { + Button { + NSPasteboard.general.clearContents() + NSPasteboard.general.setString(address, forType: .string) + } label: { Image(systemName: "doc.on.doc") } + .buttonStyle(.plain).accessibilityLabel(Text("panel.copy")) + } + } else { Text("panel.addressUnknown").foregroundStyle(.secondary) } + } + .font(.system(size: 10)).padding(5) + .background(.primary.opacity(0.04), in: RoundedRectangle(cornerRadius: 5)) + PanelTrendChart(dates: networkDates, first: networkDownloads, second: networkUploads, color: Color("MetricMemory"), secondColor: Color("SeriesUpload"), fixedScale: nil, firstLabel: "network.download", secondLabel: "network.upload", expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: networkIntervals, plotHeight: 58, showsLegendValues: false).id(selectedInterface) + Divider().padding(.vertical, 4) + HStack(alignment: .top, spacing: 8) { + networkTotal("network.received", value: network.isEmpty ? "--" : MetricFormat.bytes(network.reduce(0) { $0 + $1.received }), symbol: "arrow.down", color: Color("MetricMemory")) + Divider().frame(height: 32) + networkTotal("network.sent", value: network.isEmpty ? "--" : MetricFormat.bytes(network.reduce(0) { $0 + $1.sent }), symbol: "arrow.up", color: Color("SeriesUpload")) + Divider().frame(height: 32) + VStack(alignment: .leading, spacing: 4) { + HStack { + Text("network.status").foregroundStyle(.secondary) + Spacer(minLength: 0) + Button { showAddresses.toggle() } label: { Image(systemName: "network") } + .buttonStyle(.plain).accessibilityLabel(Text("panel.addresses")) + } + HStack(spacing: 4) { + Circle().fill(networkStatusColor).frame(width: 5, height: 5) + Text(networkStatusLabel) + } + }.frame(maxWidth: .infinity, alignment: .leading) + }.font(.system(size: 10)).lineLimit(1).minimumScaleFactor(0.65) Spacer(minLength: 0) - } - if let item = addressInterface { - Text(verbatim: "\(item.name) · \(item.addresses.first(where: { !$0.contains(":") }) ?? item.addresses.first ?? "--")") - .font(.system(size: 10)).lineLimit(1).minimumScaleFactor(0.8).textSelection(.enabled) - } else { Text("panel.addressUnknown").foregroundStyle(.secondary) } - PanelTrendChart(dates: networkDates, first: networkDownloads, second: networkUploads, color: Color("MetricMemory"), secondColor: Color("SeriesUpload"), fixedScale: nil, firstLabel: "network.download", secondLabel: "network.upload", expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: networkIntervals).id(selectedInterface) - if !network.isEmpty && total(\.download) == nil { Text("panel.rateBaseline").foregroundStyle(.secondary) } - 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) - case .unavailable: Text("network.pathUnavailable").foregroundStyle(.secondary) - case .requiresConnection: Text("network.pathRequiresConnection").foregroundStyle(.secondary) - case nil: Text("metric.waiting") - } HStack { - Button("panel.addresses") { showAddresses.toggle() }.popover(isPresented: $showAddresses) { + Text(selectedInterface.isEmpty ? "panel.totalScope" : "panel.interfaceScope") + .font(.system(size: 8)).foregroundStyle(.secondary).lineLimit(1) + .popover(isPresented: $showAddresses) { VStack(alignment: .leading, spacing: 8) { Group { ForEach(network, id: \.identity) { item in @@ -303,6 +328,31 @@ struct MenuPanelView: View { } } + private func networkTotal(_ title: LocalizedStringKey, value: String, symbol: String, color: Color) -> some View { + VStack(alignment: .leading, spacing: 4) { + Text(title).foregroundStyle(.secondary) + HStack(spacing: 3) { + Image(systemName: symbol).foregroundStyle(color) + AnimatedMetricText(value: value).fontWeight(.medium) + } + }.frame(maxWidth: .infinity, alignment: .leading) + } + private var networkStatusLabel: LocalizedStringKey { + switch snapshot.networkPath { + case .available: "network.pathAvailable" + case .unavailable: "network.pathUnavailable" + case .requiresConnection: "network.pathRequiresConnection" + case nil: "metric.waiting" + } + } + private var networkStatusColor: Color { + switch snapshot.networkPath { + case .available: .green + case .unavailable: .red + case .requiresConnection: .orange + case nil: .secondary + } + } private var addressInterface: NetworkInterfaceMetrics? { let name = selectedInterface.isEmpty ? snapshot.defaultNetworkInterface : network.first?.name return snapshot.network?.first { $0.name == name && $0.active } diff --git a/kymo/Resources/Localizable.xcstrings b/kymo/Resources/Localizable.xcstrings index 501aabe..e436fbf 100644 --- a/kymo/Resources/Localizable.xcstrings +++ b/kymo/Resources/Localizable.xcstrings @@ -2774,6 +2774,28 @@ } } }, + "network.status" : { + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Network status" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "网络状态" + } + }, + "zh-Hant": { + "stringUnit": { + "state": "translated", + "value": "網路狀態" + } + } + } + }, "network.upload" : { "localizations" : { "en" : { diff --git a/kymo/UI/Charts/PanelTrendChart.swift b/kymo/UI/Charts/PanelTrendChart.swift index 43d9dd6..75bc0a7 100644 --- a/kymo/UI/Charts/PanelTrendChart.swift +++ b/kymo/UI/Charts/PanelTrendChart.swift @@ -32,6 +32,7 @@ struct PanelTrendChart: View { var boundaryDates: Set = [] var intervals: [TimeInterval] = [] var plotHeight: CGFloat = 58 + var showsLegendValues = true @Environment(\.accessibilityReduceMotion) private var reduceMotion @State private var retainedScale: Double = 1 @State private var smallSamples = 0 @@ -80,7 +81,9 @@ struct PanelTrendChart: View { HStack(spacing: 3) { RoundedRectangle(cornerRadius: 1).fill(tint).frame(width: 7, height: 7) Text(label) - Text(verbatim: formatted(values.last ?? nil, format: format)).monospacedDigit() + if showsLegendValues { + Text(verbatim: formatted(values.last ?? nil, format: format)).monospacedDigit() + } }.font(.system(size: 9)).lineLimit(1).minimumScaleFactor(0.8) } diff --git a/kymo/UI/Components/ResourceCard.swift b/kymo/UI/Components/ResourceCard.swift index 3be1769..8aee5e4 100644 --- a/kymo/UI/Components/ResourceCard.swift +++ b/kymo/UI/Components/ResourceCard.swift @@ -6,6 +6,8 @@ struct ResourceCard: View { let color: Color let value: String var secondaryValue: String? = nil + var valueColor: Color? = nil + var secondaryValueColor: Color? = nil var status: String? = nil var statusWarning = false var statusHelp: Text? = nil @@ -42,8 +44,10 @@ struct ResourceCard: View { HStack(alignment: .center, spacing: 6) { AnimatedMetricText(value: value) .font(.system(size: 13, weight: .semibold)) + .foregroundStyle(valueColor ?? color) if let secondaryValue { AnimatedMetricText(value: secondaryValue).font(.system(size: 13, weight: .semibold)) + .foregroundStyle(secondaryValueColor ?? color) } }.foregroundStyle(color).lineLimit(1).minimumScaleFactor(0.65) }