feat(menubar): 实现趋势面板外侧详情与三语外观设置
接入有界趋势、平滑滚动、菜单式外侧详情、底部操作与三语文案,装配独立外观设置和 Dock 生命周期。 合并跟随系统外观刷新、自选颜色入口与色块绘制修复,保留用户确认的配色联动、重启保存及滚动验收。 多场景视觉与长期资源验证边界仍记录于 docs。
This commit is contained in:
@@ -15,12 +15,18 @@ import SwiftUI
|
||||
struct kymoApp: App {
|
||||
@State private var metrics = MetricsStore()
|
||||
|
||||
@State private var appearance = AppearancePreferences()
|
||||
|
||||
var body: some Scene {
|
||||
MenuBarExtra {
|
||||
MenuPanelView(metrics: metrics)
|
||||
MenuPanelView(metrics: metrics, preferences: appearance)
|
||||
} label: {
|
||||
MenuBarLabel(snapshot: metrics.snapshot)
|
||||
}
|
||||
.menuBarExtraStyle(.window)
|
||||
|
||||
Settings {
|
||||
AppearanceSettingsView(preferences: appearance)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import Foundation
|
||||
|
||||
nonisolated enum MetricFormat {
|
||||
static func percent(_ value: Double?) -> String {
|
||||
guard let value, value.isFinite else { return "--" }
|
||||
return "\(Int((min(1, max(0, value)) * 100).rounded()))%"
|
||||
}
|
||||
|
||||
static func bytes(_ value: UInt64?) -> String {
|
||||
guard let value else { return "--" }
|
||||
return String(format: "%.1f GB", Double(value) / 1_000_000_000)
|
||||
}
|
||||
|
||||
static func decimal(_ value: Double) -> String { String(format: "%.1f", value) }
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import Foundation
|
||||
|
||||
nonisolated struct TrendSample: Sendable {
|
||||
let date: Date
|
||||
let cpu: Double?
|
||||
let gpu: Double?
|
||||
let memory: Double?
|
||||
}
|
||||
|
||||
/// Bounded sampling history; no timer or UI visibility dependence.
|
||||
nonisolated struct MetricHistory: Sendable {
|
||||
static let capacity = 60
|
||||
private(set) var samples: [TrendSample] = []
|
||||
|
||||
mutating func append(_ snapshot: MetricsSnapshot) {
|
||||
samples.append(TrendSample(date: snapshot.date, cpu: snapshot.cpu?.usage,
|
||||
gpu: snapshot.gpuUsage, memory: snapshot.memory?.usage))
|
||||
if samples.count > Self.capacity { samples.removeFirst(samples.count - Self.capacity) }
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ nonisolated struct MetricsSnapshot: Sendable {
|
||||
var cpu: CPUMetrics?
|
||||
var memory: MemoryMetrics?
|
||||
var load: [Double] = []
|
||||
var uptime: TimeInterval = 0
|
||||
// GPU remains unavailable until a reliable IOReport subscription is validated.
|
||||
var gpuUsage: Double? = nil
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ actor SystemSampler {
|
||||
var result = MetricsSnapshot()
|
||||
result.cpu = cpu.sample()
|
||||
result.memory = MemoryMonitor.sample()
|
||||
result.uptime = ProcessInfo.processInfo.systemUptime
|
||||
var load = [Double](repeating: 0, count: 3)
|
||||
if getloadavg(&load, 3) == 3 { result.load = load }
|
||||
return result
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import Foundation
|
||||
import Observation
|
||||
|
||||
nonisolated enum AppAppearance: String, CaseIterable, Identifiable {
|
||||
case system, light, dark
|
||||
var id: String { rawValue }
|
||||
}
|
||||
|
||||
nonisolated enum AccentChoice: String, CaseIterable, Identifiable {
|
||||
case system, blue, purple, teal, green, orange, pink, custom
|
||||
var id: String { rawValue }
|
||||
}
|
||||
|
||||
@MainActor @Observable
|
||||
final class AppearancePreferences {
|
||||
@ObservationIgnored private let defaults: UserDefaults
|
||||
var appearance: AppAppearance { didSet { defaults.set(appearance.rawValue, forKey: "appearance") } }
|
||||
var accent: AccentChoice { didSet { defaults.set(accent.rawValue, forKey: "accent") } }
|
||||
var red: Double { didSet { defaults.set(red, forKey: "accent.red") } }
|
||||
var green: Double { didSet { defaults.set(green, forKey: "accent.green") } }
|
||||
var blue: Double { didSet { defaults.set(blue, forKey: "accent.blue") } }
|
||||
|
||||
init(defaults: UserDefaults = .standard) {
|
||||
self.defaults = defaults
|
||||
appearance = AppAppearance(rawValue: defaults.string(forKey: "appearance") ?? "") ?? .system
|
||||
accent = AccentChoice(rawValue: defaults.string(forKey: "accent") ?? "") ?? .system
|
||||
red = Self.component(defaults.object(forKey: "accent.red"), fallback: 0.2)
|
||||
green = Self.component(defaults.object(forKey: "accent.green"), fallback: 0.5)
|
||||
blue = Self.component(defaults.object(forKey: "accent.blue"), fallback: 0.9)
|
||||
}
|
||||
|
||||
private static func component(_ value: Any?, fallback: Double) -> Double {
|
||||
guard let value = value as? Double, value.isFinite else { return fallback }
|
||||
return min(1, max(0, value))
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import Observation
|
||||
@MainActor @Observable
|
||||
final class MetricsStore {
|
||||
private(set) var snapshot = MetricsSnapshot()
|
||||
private(set) var history = MetricHistory()
|
||||
private(set) var isPaused = false
|
||||
@ObservationIgnored private var task: Task<Void, Never>?
|
||||
@ObservationIgnored private let sampler = SystemSampler()
|
||||
@@ -19,6 +20,7 @@ final class MetricsStore {
|
||||
let next = await sampler.sample()
|
||||
guard !Task.isCancelled else { return }
|
||||
self?.snapshot = next
|
||||
self?.history.append(next)
|
||||
SamplingDiagnostics.record(next)
|
||||
do { try await Task.sleep(for: .seconds(2)) }
|
||||
catch { return }
|
||||
|
||||
@@ -16,15 +16,11 @@ struct MenuBarLabel: View {
|
||||
}
|
||||
|
||||
private var title: String {
|
||||
var items = ["CPU \(percent(snapshot.cpu?.usage))"]
|
||||
var items = ["CPU \(MetricFormat.percent(snapshot.cpu?.usage))"]
|
||||
if let gpu = snapshot.gpuUsage {
|
||||
items.append("GPU \(percent(gpu))")
|
||||
items.append("GPU \(MetricFormat.percent(gpu))")
|
||||
}
|
||||
items.append("MEM \(percent(snapshot.memory?.usage))")
|
||||
items.append("MEM \(MetricFormat.percent(snapshot.memory?.usage))")
|
||||
return items.joined(separator: " · ")
|
||||
}
|
||||
|
||||
private func percent(_ value: Double?) -> String {
|
||||
value.map { "\(Int(($0 * 100).rounded()))%" } ?? "--"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +1,115 @@
|
||||
//
|
||||
// MenuPanelView.swift
|
||||
// kymo
|
||||
//
|
||||
// Created by Airnan on 2026/10/29.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import AppKit
|
||||
|
||||
/// A 阶段临时面板:展示采样时间与暂停入口,正式面板在 B 阶段实现。
|
||||
struct MenuPanelView: View {
|
||||
let metrics: MetricsStore
|
||||
let preferences: AppearancePreferences
|
||||
@Environment(\.openSettings) private var openSettings
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
Label("Kymo 资源监控", systemImage: "gauge")
|
||||
.font(.headline)
|
||||
|
||||
Text(metrics.snapshot.date, style: .time)
|
||||
Button(metrics.isPaused ? "继续监控" : "暂停监控") {
|
||||
metrics.togglePause()
|
||||
VStack(spacing: 4) {
|
||||
VStack(spacing: 2) {
|
||||
MetricRow(title: "metric.cpu", symbol: "cpu", value: MetricFormat.percent(metrics.snapshot.cpu?.usage),
|
||||
usage: metrics.snapshot.cpu?.usage, history: metrics.history.samples.map(\.cpu), accent: preferences.tintColor) {
|
||||
cpuDetail
|
||||
}
|
||||
MetricRow(title: "metric.gpu", symbol: "square.grid.2x2", value: MetricFormat.percent(metrics.snapshot.gpuUsage),
|
||||
usage: metrics.snapshot.gpuUsage, history: metrics.history.samples.map(\.gpu), accent: preferences.tintColor) {
|
||||
Text("gpu.unavailable").foregroundStyle(.secondary)
|
||||
}
|
||||
MetricRow(title: "metric.memory", symbol: "memorychip", value: MetricFormat.percent(metrics.snapshot.memory?.usage),
|
||||
usage: metrics.snapshot.memory?.usage, history: metrics.history.samples.map(\.memory), accent: preferences.tintColor) {
|
||||
memoryDetail
|
||||
}
|
||||
}
|
||||
Text("GPU 暂不可用")
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(.secondary)
|
||||
Divider().padding(.horizontal, 10)
|
||||
HStack {
|
||||
Text("system.load")
|
||||
Text(verbatim: metrics.snapshot.load.map(MetricFormat.decimal).joined(separator: " / "))
|
||||
Spacer(minLength: 4)
|
||||
Image(systemName: "clock")
|
||||
Text(verbatim: String(format: "%.0fh", floor(metrics.snapshot.uptime / 3600)))
|
||||
}
|
||||
.font(.system(size: 10)).monospacedDigit().foregroundStyle(.secondary)
|
||||
.padding(.horizontal, 10).padding(.vertical, 8)
|
||||
footer
|
||||
}
|
||||
.padding(16)
|
||||
.frame(width: 280, alignment: .leading)
|
||||
.padding(10)
|
||||
.frame(width: 320)
|
||||
.modifier(AppearanceStyle(preferences: preferences))
|
||||
}
|
||||
|
||||
@ViewBuilder private var cpuDetail: some View {
|
||||
if let cpu = metrics.snapshot.cpu {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
detailLine("cpu.user", MetricFormat.percent(cpu.user))
|
||||
detailLine("cpu.system", MetricFormat.percent(cpu.system))
|
||||
LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 4), count: 7), spacing: 4) {
|
||||
ForEach(Array(cpu.cores.enumerated()), id: \.offset) { index, usage in
|
||||
RoundedRectangle(cornerRadius: 4)
|
||||
.fill(preferences.tintColor.opacity(0.12 + 0.88 * usage))
|
||||
.frame(height: 18)
|
||||
.overlay(Text(verbatim: "\(index + 1)").font(.system(size: 9)).foregroundStyle(.primary))
|
||||
.help(MetricFormat.percent(usage))
|
||||
.accessibilityLabel(Text("cpu.core"))
|
||||
.accessibilityValue(Text(verbatim: "\(index + 1): \(MetricFormat.percent(usage))"))
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { Text("metric.waiting").foregroundStyle(.secondary) }
|
||||
}
|
||||
|
||||
@ViewBuilder private var memoryDetail: some View {
|
||||
if let memory = metrics.snapshot.memory {
|
||||
VStack(spacing: 6) {
|
||||
detailLine("memory.used", MetricFormat.bytes(memory.used))
|
||||
detailLine("memory.available", MetricFormat.bytes(memory.total - memory.used))
|
||||
detailLine("memory.app", MetricFormat.bytes(memory.used - min(memory.used, memory.wired + memory.compressed)))
|
||||
detailLine("memory.wired", MetricFormat.bytes(memory.wired))
|
||||
detailLine("memory.compressed", MetricFormat.bytes(memory.compressed))
|
||||
detailLine("memory.swap", MetricFormat.bytes(memory.swapUsed))
|
||||
HStack {
|
||||
Text("memory.pressure").foregroundStyle(.secondary)
|
||||
Spacer()
|
||||
switch memory.pressure {
|
||||
case 1: Text("pressure.normal")
|
||||
case 2: Text("pressure.warning").foregroundStyle(.orange)
|
||||
case 4: Text("pressure.critical").foregroundStyle(.red)
|
||||
default: Text(verbatim: "--")
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { Text("metric.waiting").foregroundStyle(.secondary) }
|
||||
}
|
||||
|
||||
private func detailLine(_ key: LocalizedStringKey, _ value: String) -> some View {
|
||||
HStack { Text(key).foregroundStyle(.secondary); Spacer(); Text(verbatim: value).monospacedDigit() }
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
Spacer()
|
||||
Button { metrics.togglePause() } label: {
|
||||
Image(systemName: metrics.isPaused ? "play.fill" : "pause.fill").frame(width: 20, height: 20)
|
||||
}
|
||||
.help(metrics.isPaused ? Text("action.resume") : Text("action.pause"))
|
||||
.accessibilityLabel(metrics.isPaused ? Text("action.resume") : Text("action.pause"))
|
||||
Button { NSApp.activate(); openSettings() } label: {
|
||||
Image(systemName: "gearshape").frame(width: 20, height: 20)
|
||||
}
|
||||
.help(Text("action.settings")).accessibilityLabel(Text("action.settings"))
|
||||
Button { NSApp.terminate(nil) } label: {
|
||||
Image(systemName: "power").frame(width: 20, height: 20)
|
||||
}
|
||||
.help(Text("action.quit")).accessibilityLabel(Text("action.quit"))
|
||||
}
|
||||
.buttonStyle(.glass)
|
||||
.controlSize(.small)
|
||||
.padding(.horizontal, 8).padding(.vertical, 6)
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
MenuPanelView(metrics: MetricsStore())
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import SwiftUI
|
||||
import AppKit
|
||||
|
||||
/// B-stage appearance controls; general/modules/permissions remain D-stage work.
|
||||
struct AppearanceSettingsView: View {
|
||||
@Bindable var preferences: AppearancePreferences
|
||||
@State private var colorPicker = CustomColorPicker()
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
Section("settings.appearance") {
|
||||
Picker("appearance.title", selection: $preferences.appearance) {
|
||||
Text("appearance.system").tag(AppAppearance.system)
|
||||
Text("appearance.light").tag(AppAppearance.light)
|
||||
Text("appearance.dark").tag(AppAppearance.dark)
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
Picker("accent.title", selection: $preferences.accent) {
|
||||
Text("accent.system").tag(AccentChoice.system)
|
||||
Text("accent.blue").tag(AccentChoice.blue)
|
||||
Text("accent.purple").tag(AccentChoice.purple)
|
||||
Text("accent.teal").tag(AccentChoice.teal)
|
||||
Text("accent.green").tag(AccentChoice.green)
|
||||
Text("accent.orange").tag(AccentChoice.orange)
|
||||
Text("accent.pink").tag(AccentChoice.pink)
|
||||
Text("accent.custom").tag(AccentChoice.custom)
|
||||
}
|
||||
if preferences.accent == .custom {
|
||||
HStack {
|
||||
Text("accent.custom")
|
||||
Spacer()
|
||||
CustomColorWell(preferences: preferences, picker: colorPicker)
|
||||
.frame(width: 44, height: 26)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.background(SettingsWindowLifecycle(onClose: { colorPicker.close() }))
|
||||
.onChange(of: preferences.accent) { _, choice in
|
||||
if choice == .custom {
|
||||
Task { @MainActor in
|
||||
await Task.yield()
|
||||
guard preferences.accent == .custom else { return }
|
||||
colorPicker.show(for: preferences)
|
||||
}
|
||||
}
|
||||
else { colorPicker.close() }
|
||||
}
|
||||
.onAppear { NSApp.setActivationPolicy(.regular); NSApp.activate() }
|
||||
.formStyle(.grouped)
|
||||
.frame(width: 420, height: 240)
|
||||
.modifier(AppearanceStyle(preferences: preferences))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import AppKit
|
||||
import OSLog
|
||||
|
||||
@MainActor final class CustomColorPicker: NSObject {
|
||||
private let logger = Logger(subsystem: "cn.airnan.kymo", category: "color-picker")
|
||||
private static weak var owner: CustomColorPicker?
|
||||
private var preferences: AppearancePreferences?
|
||||
|
||||
func show(for preferences: AppearancePreferences) {
|
||||
logger.info("Custom color panel requested")
|
||||
Self.owner = self
|
||||
self.preferences = preferences
|
||||
let panel = NSColorPanel.shared
|
||||
panel.appearance = preferences.appearance.windowAppearance
|
||||
panel.showsAlpha = false
|
||||
panel.isContinuous = true
|
||||
panel.color = NSColor(srgbRed: preferences.red, green: preferences.green,
|
||||
blue: preferences.blue, alpha: 1)
|
||||
panel.setTarget(self)
|
||||
panel.setAction(#selector(colorChanged(_:)))
|
||||
NSApp.activate()
|
||||
panel.level = .floating
|
||||
panel.makeKeyAndOrderFront(nil)
|
||||
panel.orderFrontRegardless()
|
||||
logger.info("Custom color panel visible: \(panel.isVisible, privacy: .public)")
|
||||
}
|
||||
|
||||
@objc private func colorChanged(_ sender: NSColorPanel) {
|
||||
guard let preferences, let rgb = sender.color.usingColorSpace(.sRGB) else { return }
|
||||
preferences.red = rgb.redComponent
|
||||
preferences.green = rgb.greenComponent
|
||||
preferences.blue = rgb.blueComponent
|
||||
}
|
||||
|
||||
func close() {
|
||||
guard Self.owner === self else { return }
|
||||
NSColorPanel.shared.setTarget(nil)
|
||||
NSColorPanel.shared.setAction(nil)
|
||||
NSColorPanel.shared.close()
|
||||
preferences = nil
|
||||
Self.owner = nil
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import SwiftUI
|
||||
import AppKit
|
||||
|
||||
/// A native hit target avoids Form/plain-Button hit-testing ambiguity on the swatch.
|
||||
struct CustomColorWell: NSViewRepresentable {
|
||||
let preferences: AppearancePreferences
|
||||
let picker: CustomColorPicker
|
||||
|
||||
func makeNSView(context: Context) -> SwatchButton {
|
||||
let button = SwatchButton()
|
||||
button.setAccessibilityLabel(String(localized: "accent.custom"))
|
||||
return button
|
||||
}
|
||||
|
||||
func updateNSView(_ button: SwatchButton, context: Context) {
|
||||
button.open = { picker.show(for: preferences) }
|
||||
button.swatchColor = NSColor(srgbRed: preferences.red, green: preferences.green, blue: preferences.blue, alpha: 1)
|
||||
}
|
||||
|
||||
func sizeThatFits(_ proposal: ProposedViewSize, nsView: SwatchButton, context: Context) -> CGSize? {
|
||||
CGSize(width: 44, height: 26)
|
||||
}
|
||||
|
||||
final class SwatchButton: NSButton {
|
||||
var swatchColor = NSColor.systemBlue { didSet { needsDisplay = true } }
|
||||
override var intrinsicContentSize: NSSize { NSSize(width: 44, height: 26) }
|
||||
|
||||
override func draw(_ dirtyRect: NSRect) {
|
||||
// Draw the actual RGB color inside bounds; no scalable SF Symbol/cell image.
|
||||
let shape = NSBezierPath(roundedRect: bounds.insetBy(dx: 4, dy: 4), xRadius: 4, yRadius: 4)
|
||||
(isHighlighted ? swatchColor.withAlphaComponent(0.7) : swatchColor).setFill()
|
||||
shape.fill()
|
||||
NSColor.separatorColor.setStroke()
|
||||
shape.lineWidth = 1
|
||||
shape.stroke()
|
||||
}
|
||||
|
||||
var open: () -> Void = {}
|
||||
override init(frame frameRect: NSRect) {
|
||||
super.init(frame: frameRect)
|
||||
bezelStyle = .rounded
|
||||
isBordered = false
|
||||
wantsLayer = true
|
||||
layer?.masksToBounds = true
|
||||
title = ""
|
||||
target = self
|
||||
action = #selector(openPicker)
|
||||
}
|
||||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||||
override func acceptsFirstMouse(for event: NSEvent?) -> Bool { true }
|
||||
@objc func openPicker() { open() }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import SwiftUI
|
||||
import AppKit
|
||||
|
||||
/// Keep the app discoverable while its settings window is open, including reopen.
|
||||
struct SettingsWindowLifecycle: NSViewRepresentable {
|
||||
var onClose: () -> Void = {}
|
||||
|
||||
func makeNSView(context: Context) -> WindowObserverView { WindowObserverView() }
|
||||
func updateNSView(_ nsView: WindowObserverView, context: Context) { nsView.onClose = onClose }
|
||||
|
||||
final class WindowObserverView: NSView {
|
||||
override func hitTest(_ point: NSPoint) -> NSView? { nil }
|
||||
var onClose: () -> Void = {}
|
||||
private var tokens: [NSObjectProtocol] = []
|
||||
|
||||
override func viewDidMoveToWindow() {
|
||||
super.viewDidMoveToWindow()
|
||||
for token in tokens { NotificationCenter.default.removeObserver(token) }
|
||||
tokens.removeAll()
|
||||
guard let window else { return }
|
||||
tokens.append(NotificationCenter.default.addObserver(forName: NSWindow.didBecomeKeyNotification,
|
||||
object: window, queue: .main) { _ in
|
||||
MainActor.assumeIsolated {
|
||||
if NSApp.activationPolicy() != .regular { NSApp.setActivationPolicy(.regular) }
|
||||
}
|
||||
})
|
||||
tokens.append(NotificationCenter.default.addObserver(forName: NSWindow.willCloseNotification,
|
||||
object: window, queue: .main) { [weak self] _ in
|
||||
MainActor.assumeIsolated {
|
||||
self?.onClose()
|
||||
NSApp.setActivationPolicy(.accessory)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
deinit { for token in tokens { NotificationCenter.default.removeObserver(token) } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,903 @@
|
||||
{
|
||||
"sourceLanguage": "en",
|
||||
"strings": {
|
||||
"metric.cpu": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "CPU"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "CPU"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "CPU"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"metric.gpu": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "GPU"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "GPU"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "GPU"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"metric.memory": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Memory"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "内存"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "記憶體"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"metric.waiting": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Waiting for sample…"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "等待采样…"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "等待取樣…"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"gpu.unavailable": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "GPU sampling is unavailable on this device."
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "此设备暂不支持 GPU 采样。"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "此裝置暫不支援 GPU 取樣。"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"cpu.user": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "User"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "用户"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "使用者"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"cpu.system": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "System"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "系统"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "系統"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"cpu.core": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Core"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "核心"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "核心"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"memory.used": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Used"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "已用"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "已使用"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"memory.available": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Available"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "可用"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "可用"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"memory.app": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "App memory"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "应用内存"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "App 記憶體"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"memory.wired": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Wired"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "联动内存"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "連動記憶體"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"memory.compressed": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Compressed"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "已压缩"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "已壓縮"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"memory.swap": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Swap used"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "交换使用量"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "交換使用量"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"memory.pressure": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Memory pressure"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "内存压力"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "記憶體壓力"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"pressure.normal": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Normal"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "正常"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "正常"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"pressure.warning": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Warning"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "偏高"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "偏高"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"pressure.critical": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Critical"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "严重"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "嚴重"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"system.load": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Load"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "负载"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "負載"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"action.pause": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Pause monitoring"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "暂停监控"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "暫停監控"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"action.resume": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Resume monitoring"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "继续监控"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "繼續監控"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"action.settings": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Settings"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "设置"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "設定"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"action.quit": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Quit Kymo"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "退出 Kymo"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "結束 Kymo"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"detail.expanded": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Details expanded"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "详情已展开"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "詳細資訊已展開"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"detail.collapsed": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Details collapsed"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "详情已收起"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "詳細資訊已收合"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"settings.appearance": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Appearance"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "外观"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "外觀"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"appearance.title": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Appearance"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "外观模式"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "外觀模式"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"appearance.system": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "System"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "跟随系统"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "跟隨系統"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"appearance.light": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Light"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "浅色"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "淺色"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"appearance.dark": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Dark"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "深色"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "深色"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"accent.title": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Accent color"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "强调色"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "強調色"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"accent.system": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "System accent"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "系统强调色"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "系統強調色"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"accent.blue": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Blue"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "蓝色"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "藍色"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"accent.purple": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Purple"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "紫色"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "紫色"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"accent.teal": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Teal"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "青色"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "青色"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"accent.green": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Green"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "绿色"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "綠色"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"accent.orange": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Orange"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "橙色"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "橘色"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"accent.pink": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Pink"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "粉色"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "粉紅色"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"accent.custom": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Custom color"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "自选颜色"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "自選顏色"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"version": "1.0"
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import SwiftUI
|
||||
|
||||
struct MiniTrendChart: View {
|
||||
let values: [Double?]
|
||||
let color: Color
|
||||
|
||||
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
||||
@State private var displayed: [Double?] = []
|
||||
@State private var progress: CGFloat = 1
|
||||
@State private var scrolling = false
|
||||
|
||||
var body: some View {
|
||||
TrendCanvas(values: displayed, color: color, progress: progress, scrolling: scrolling)
|
||||
.clipped()
|
||||
.accessibilityHidden(true)
|
||||
.onAppear { displayed = values; scrolling = false; progress = 1 }
|
||||
.onChange(of: values) { old, new in
|
||||
var transaction = Transaction()
|
||||
transaction.disablesAnimations = true
|
||||
withTransaction(transaction) {
|
||||
scrolling = !reduceMotion && TrendScroll.isAppend(from: old, to: new)
|
||||
displayed = scrolling ? old + [new.last!] : new
|
||||
progress = scrolling ? 0 : 1
|
||||
}
|
||||
}
|
||||
.task(id: values) {
|
||||
guard scrolling, !reduceMotion else { return }
|
||||
// Commit the starting frame before requesting interpolation; no repeating timer.
|
||||
do { try await Task.sleep(for: .milliseconds(16)) } catch { return }
|
||||
guard !Task.isCancelled else { return }
|
||||
withAnimation(.easeInOut(duration: 0.35)) { progress = 1 }
|
||||
}
|
||||
.onChange(of: reduceMotion) { _, reduced in
|
||||
if reduced {
|
||||
var transaction = Transaction()
|
||||
transaction.disablesAnimations = true
|
||||
withTransaction(transaction) { displayed = values; scrolling = false; progress = 1 }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private struct TrendCanvas: View, Animatable {
|
||||
let values: [Double?]
|
||||
let color: Color
|
||||
var progress: CGFloat
|
||||
let scrolling: Bool
|
||||
var animatableData: CGFloat {
|
||||
get { progress }
|
||||
set { progress = newValue }
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Canvas { context, size in
|
||||
guard values.count > 1 else { return }
|
||||
var path = Path()
|
||||
var run: [CGPoint] = []
|
||||
func appendRun() {
|
||||
guard let first = run.first, let last = run.last else { return }
|
||||
path.move(to: first)
|
||||
if run.count == 1 { path.addLine(to: CGPoint(x: first.x + 0.1, y: first.y)) }
|
||||
for index in 1..<run.count {
|
||||
let previous = run[index - 1]
|
||||
let current = run[index]
|
||||
let midpoint = CGPoint(x: (previous.x + current.x) / 2, y: (previous.y + current.y) / 2)
|
||||
path.addQuadCurve(to: midpoint, control: previous)
|
||||
}
|
||||
path.addQuadCurve(to: last, control: last)
|
||||
run.removeAll(keepingCapacity: true)
|
||||
}
|
||||
for (index, value) in values.enumerated() {
|
||||
guard let value, value.isFinite else { appendRun(); continue }
|
||||
let x = size.width * TrendScroll.position(index: index, count: values.count,
|
||||
progress: progress, scrolling: scrolling)
|
||||
run.append(CGPoint(x: x, y: 2 + (size.height - 4) * (1 - min(1, max(0, value)))))
|
||||
}
|
||||
appendRun()
|
||||
context.stroke(path, with: .color(color.opacity(0.85)), style: StrokeStyle(lineWidth: 1.8, lineCap: .round, lineJoin: .round))
|
||||
}
|
||||
.accessibilityHidden(true)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import Foundation
|
||||
|
||||
/// Geometry for a single appended sample, including the outgoing point at full capacity.
|
||||
nonisolated enum TrendScroll {
|
||||
static func isAppend(from old: [Double?], to new: [Double?]) -> Bool {
|
||||
guard !old.isEmpty, !new.isEmpty else { return false }
|
||||
if old.count < MetricHistory.capacity {
|
||||
return new.count == old.count + 1 && Array(new.dropLast()) == old
|
||||
}
|
||||
return new.count == old.count && Array(old.dropFirst()) == Array(new.dropLast())
|
||||
}
|
||||
|
||||
static func position(index: Int, count: Int, progress: CGFloat, scrolling: Bool) -> CGFloat {
|
||||
let offset = MetricHistory.capacity - count
|
||||
let shift = scrolling ? 1 - min(1, max(0, progress)) : 0
|
||||
return (CGFloat(index + offset) + shift) / CGFloat(MetricHistory.capacity - 1)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
import SwiftUI
|
||||
import AppKit
|
||||
import Observation
|
||||
|
||||
extension AppAppearance {
|
||||
func resolved(systemIsDark: Bool) -> AppAppearance {
|
||||
self == .system ? (systemIsDark ? .dark : .light) : self
|
||||
}
|
||||
|
||||
var windowAppearance: NSAppearance? {
|
||||
switch self {
|
||||
case .system: nil
|
||||
case .light: NSAppearance(named: .aqua)
|
||||
case .dark: NSAppearance(named: .darkAqua)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension AppearancePreferences {
|
||||
var tintColor: Color {
|
||||
switch accent {
|
||||
case .system: .accentColor
|
||||
case .blue: .blue
|
||||
case .purple: .purple
|
||||
case .teal: .teal
|
||||
case .green: .green
|
||||
case .orange: .orange
|
||||
case .pink: .pink
|
||||
case .custom: Color(red: red, green: green, blue: blue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct AppearanceStyle: ViewModifier {
|
||||
let preferences: AppearancePreferences
|
||||
@State private var system = SystemAppearanceObserver()
|
||||
private var resolved: AppAppearance { preferences.appearance.resolved(systemIsDark: system.isDark) }
|
||||
private var scheme: ColorScheme { resolved == .dark ? .dark : .light }
|
||||
func body(content: Content) -> some View {
|
||||
content
|
||||
.background(WindowAppearanceBridge(choice: resolved))
|
||||
.preferredColorScheme(scheme)
|
||||
.environment(\.colorScheme, scheme)
|
||||
.tint(preferences.tintColor)
|
||||
}
|
||||
}
|
||||
|
||||
/// Explicitly clear the NSWindow override when returning to system appearance.
|
||||
private struct WindowAppearanceBridge: NSViewRepresentable {
|
||||
let choice: AppAppearance
|
||||
func makeNSView(context: Context) -> AppearanceView { AppearanceView() }
|
||||
func updateNSView(_ view: AppearanceView, context: Context) { view.choice = choice }
|
||||
|
||||
final class AppearanceView: NSView {
|
||||
override func hitTest(_ point: NSPoint) -> NSView? { nil }
|
||||
var choice = AppAppearance.system { didSet { apply() } }
|
||||
override func viewDidMoveToWindow() { super.viewDidMoveToWindow(); apply() }
|
||||
private func apply() {
|
||||
WindowAppearance.apply(choice, to: window)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor enum WindowAppearance {
|
||||
static func apply(_ choice: AppAppearance, to window: NSWindow?) {
|
||||
let appearance = choice.windowAppearance
|
||||
if window?.appearance?.name != appearance?.name { window?.appearance = appearance }
|
||||
for child in window?.childWindows ?? [] where child.appearance?.name != appearance?.name {
|
||||
child.appearance = appearance
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// System source is independent of the color scheme inherited by this window.
|
||||
@MainActor @Observable final class SystemAppearanceObserver {
|
||||
private(set) var isDark = false
|
||||
@ObservationIgnored private var observation: NSKeyValueObservation?
|
||||
@ObservationIgnored private var themeToken: NSObjectProtocol?
|
||||
|
||||
init() {
|
||||
refresh()
|
||||
observation = NSApp.observe(\.effectiveAppearance, options: [.new]) { [weak self] _, _ in
|
||||
guard let self else { return }
|
||||
Task { @MainActor in self.refresh() }
|
||||
}
|
||||
themeToken = DistributedNotificationCenter.default().addObserver(
|
||||
forName: Notification.Name("AppleInterfaceThemeChangedNotification"), object: nil, queue: .main
|
||||
) { [weak self] _ in
|
||||
guard let self else { return }
|
||||
Task { @MainActor in self.refresh() }
|
||||
}
|
||||
}
|
||||
|
||||
private func refresh() {
|
||||
// Read the global domain, not this app's effective window appearance.
|
||||
isDark = Self.isDark(globalDomain: UserDefaults.standard.persistentDomain(forName: UserDefaults.globalDomain))
|
||||
}
|
||||
|
||||
static func isDark(globalDomain: [String: Any]?) -> Bool {
|
||||
(globalDomain?["AppleInterfaceStyle"] as? String)?.caseInsensitiveCompare("Dark") == .orderedSame
|
||||
}
|
||||
|
||||
deinit { if let themeToken { DistributedNotificationCenter.default().removeObserver(themeToken) } }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import Foundation
|
||||
import CoreGraphics
|
||||
|
||||
|
||||
/// Screen coordinates: prefer the parent's right side, otherwise use its left.
|
||||
nonisolated enum DetailPlacement {
|
||||
static func frame(anchor: CGRect, parent: CGRect, content: CGSize, visible: CGRect) -> CGRect {
|
||||
let gap: CGFloat = 4
|
||||
let width = min(content.width, visible.width)
|
||||
let height = min(content.height, visible.height)
|
||||
let right = parent.maxX + gap
|
||||
let left = parent.minX - gap - width
|
||||
let candidate = right + width <= visible.maxX ? right : left
|
||||
let x = max(visible.minX, min(candidate, visible.maxX - width))
|
||||
let y = max(visible.minY, min(anchor.maxY - height, visible.maxY - height))
|
||||
return CGRect(x: x, y: y, width: width, height: height)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
import SwiftUI
|
||||
import AppKit
|
||||
|
||||
/// A non-activating child window: outside the parent layout, below no other app.
|
||||
struct HoverDetailPresenter<Detail: View>: NSViewRepresentable {
|
||||
let isPresented: Bool
|
||||
let detail: Detail
|
||||
let onHover: (Bool) -> Void
|
||||
let onDismiss: () -> Void
|
||||
|
||||
func makeNSView(context: Context) -> AnchorView { AnchorView() }
|
||||
func updateNSView(_ view: AnchorView, context: Context) {
|
||||
view.configure(presented: isPresented, detail: AnyView(detail), onHover: onHover, onDismiss: onDismiss)
|
||||
}
|
||||
static func dismantleNSView(_ view: AnchorView, coordinator: ()) { view.detach() }
|
||||
|
||||
final class AnchorView: NSView {
|
||||
override func hitTest(_ point: NSPoint) -> NSView? { nil }
|
||||
private var panel: DetailPanel?
|
||||
private var host: NSHostingView<AnyView>?
|
||||
private var tokens: [NSObjectProtocol] = []
|
||||
private var presented = false
|
||||
private var detail = AnyView(EmptyView())
|
||||
private var onHover: (Bool) -> Void = { _ in }
|
||||
private var onDismiss: () -> Void = {}
|
||||
|
||||
func configure(presented: Bool, detail: AnyView,
|
||||
onHover: @escaping (Bool) -> Void, onDismiss: @escaping () -> Void) {
|
||||
self.presented = presented
|
||||
self.detail = detail
|
||||
self.onHover = onHover
|
||||
self.onDismiss = onDismiss
|
||||
refresh()
|
||||
}
|
||||
|
||||
override func viewDidMoveToWindow() {
|
||||
super.viewDidMoveToWindow()
|
||||
detach()
|
||||
guard let window else { return }
|
||||
for name in [NSWindow.willCloseNotification, NSWindow.didChangeOcclusionStateNotification] {
|
||||
tokens.append(NotificationCenter.default.addObserver(forName: name, object: window, queue: .main) { [weak self, weak window] notification in
|
||||
MainActor.assumeIsolated {
|
||||
guard notification.name == NSWindow.willCloseNotification || window?.occlusionState.contains(.visible) != true else { return }
|
||||
self?.hide()
|
||||
let dismiss = self?.onDismiss
|
||||
DispatchQueue.main.async { dismiss?() }
|
||||
}
|
||||
})
|
||||
}
|
||||
refresh()
|
||||
}
|
||||
|
||||
func detach() {
|
||||
hide()
|
||||
for token in tokens { NotificationCenter.default.removeObserver(token) }
|
||||
tokens.removeAll()
|
||||
}
|
||||
|
||||
private func refresh() {
|
||||
guard presented, let parent = window, parent.isVisible, let screen = parent.screen else { hide(); return }
|
||||
let content = AnyView(detail
|
||||
.font(.caption)
|
||||
.padding(12)
|
||||
.frame(width: 280)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.onHover { [weak self] inside in self?.onHover(inside) })
|
||||
if panel == nil {
|
||||
let panel = DetailPanel(contentRect: .zero, styleMask: [.borderless, .nonactivatingPanel], backing: .buffered, defer: false)
|
||||
panel.isReleasedWhenClosed = false
|
||||
panel.isOpaque = false
|
||||
panel.backgroundColor = .clear
|
||||
panel.hasShadow = true
|
||||
panel.hidesOnDeactivate = false
|
||||
panel.level = parent.level
|
||||
let material = NSVisualEffectView()
|
||||
material.material = .menu
|
||||
material.blendingMode = .behindWindow
|
||||
material.state = .active
|
||||
material.wantsLayer = true
|
||||
material.layer?.cornerRadius = 12
|
||||
material.layer?.masksToBounds = true
|
||||
let host = NSHostingView(rootView: content)
|
||||
host.translatesAutoresizingMaskIntoConstraints = false
|
||||
material.addSubview(host)
|
||||
NSLayoutConstraint.activate([
|
||||
host.leadingAnchor.constraint(equalTo: material.leadingAnchor),
|
||||
host.trailingAnchor.constraint(equalTo: material.trailingAnchor),
|
||||
host.topAnchor.constraint(equalTo: material.topAnchor),
|
||||
host.bottomAnchor.constraint(equalTo: material.bottomAnchor)
|
||||
])
|
||||
panel.contentView = material
|
||||
self.panel = panel
|
||||
self.host = host
|
||||
parent.addChildWindow(panel, ordered: .above)
|
||||
}
|
||||
guard let panel, let host else { return }
|
||||
host.rootView = content
|
||||
panel.appearance = parent.appearance
|
||||
let row = parent.convertToScreen(convert(bounds, to: nil))
|
||||
let size = host.fittingSize
|
||||
panel.setFrame(DetailPlacement.frame(anchor: row, parent: parent.frame,
|
||||
content: CGSize(width: 280, height: max(40, size.height)),
|
||||
visible: screen.visibleFrame), display: true)
|
||||
panel.orderFront(nil)
|
||||
}
|
||||
|
||||
private func hide() {
|
||||
guard let panel else { return }
|
||||
panel.parent?.removeChildWindow(panel)
|
||||
panel.orderOut(nil)
|
||||
panel.contentView = nil
|
||||
panel.close()
|
||||
host = nil
|
||||
self.panel = nil
|
||||
}
|
||||
|
||||
deinit { for token in tokens { NotificationCenter.default.removeObserver(token) } }
|
||||
}
|
||||
|
||||
final class DetailPanel: NSPanel {
|
||||
override var canBecomeKey: Bool { false }
|
||||
override var canBecomeMain: Bool { false }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import SwiftUI
|
||||
|
||||
struct MetricRow<Detail: View>: View {
|
||||
let title: LocalizedStringKey
|
||||
let symbol: String
|
||||
let value: String
|
||||
let usage: Double?
|
||||
let history: [Double?]
|
||||
let accent: Color
|
||||
@ViewBuilder let detail: () -> Detail
|
||||
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
||||
@State private var visible = false
|
||||
@State private var rowHovered = false
|
||||
@State private var detailHovered = false
|
||||
@State private var expanded = false
|
||||
private var inside: Bool { rowHovered || detailHovered }
|
||||
|
||||
private var color: Color {
|
||||
guard let usage else { return .secondary }
|
||||
return usage > 0.95 ? .red : usage >= 0.8 ? .orange : accent
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Button { expanded.toggle() } label: {
|
||||
HStack(spacing: 10) {
|
||||
Image(systemName: symbol)
|
||||
.font(.system(size: 13, weight: .medium))
|
||||
.foregroundStyle(color)
|
||||
.frame(width: 20)
|
||||
Text(title).font(.system(size: 13, weight: .medium))
|
||||
.frame(width: 52, alignment: .leading)
|
||||
MiniTrendChart(values: history, color: color).frame(height: 24)
|
||||
Text(verbatim: value)
|
||||
.font(.system(size: 13, weight: .semibold, design: .rounded))
|
||||
.monospacedDigit()
|
||||
.contentTransition(.numericText())
|
||||
.frame(width: 46, alignment: .trailing)
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.accessibilityLabel(Text(title))
|
||||
.accessibilityValue(Text(verbatim: value))
|
||||
.accessibilityHint(expanded ? Text("detail.expanded") : Text("detail.collapsed"))
|
||||
.padding(10)
|
||||
.background(expanded ? Color.primary.opacity(0.035) : .clear, in: .rect(cornerRadius: 14))
|
||||
.background(HoverDetailPresenter(isPresented: expanded && visible, detail: detail(),
|
||||
onHover: { detailHovered = $0 },
|
||||
onDismiss: { expanded = false; detailHovered = false }))
|
||||
.onHover { rowHovered = $0 }
|
||||
.task(id: inside) {
|
||||
do { try await Task.sleep(for: .milliseconds(inside ? 150 : 120)) }
|
||||
catch { return }
|
||||
guard !Task.isCancelled else { return }
|
||||
expanded = inside
|
||||
}
|
||||
.onAppear { visible = true }
|
||||
.onDisappear { visible = false; rowHovered = false; detailHovered = false; expanded = false }
|
||||
.animation(!visible || reduceMotion ? nil : .spring(duration: 0.3, bounce: 0), value: value)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user