feat(menubar): 实现趋势面板外侧详情与三语外观设置
接入有界趋势、平滑滚动、菜单式外侧详情、底部操作与三语文案,装配独立外观设置和 Dock 生命周期。 合并跟随系统外观刷新、自选颜色入口与色块绘制修复,保留用户确认的配色联动、重启保存及滚动验收。 多场景视觉与长期资源验证边界仍记录于 docs。
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import Foundation
|
||||
import AppKit
|
||||
import CoreGraphics
|
||||
|
||||
@main struct PresentationChecks {
|
||||
@MainActor static func main() {
|
||||
let screen = CGRect(x: 0, y: 0, width: 1440, height: 900)
|
||||
let parent = CGRect(x: 400, y: 400, width: 320, height: 240)
|
||||
let anchor = CGRect(x: 410, y: 600, width: 300, height: 40)
|
||||
let size = CGSize(width: 280, height: 180)
|
||||
let right = DetailPlacement.frame(anchor: anchor, parent: parent, content: size, visible: screen)
|
||||
precondition(right.minX == parent.maxX + 4 && right.maxY == anchor.maxY)
|
||||
let edgeParent = CGRect(x: 1100, y: 400, width: 320, height: 240)
|
||||
let left = DetailPlacement.frame(anchor: anchor, parent: edgeParent, content: size, visible: screen)
|
||||
precondition(left.maxX == edgeParent.minX - 4)
|
||||
for visible in [screen, CGRect(x: -1440, y: -200, width: 1440, height: 900), CGRect(x: 0, y: 0, width: 200, height: 100)] {
|
||||
let result = DetailPlacement.frame(anchor: anchor, parent: parent, content: size, visible: visible)
|
||||
precondition(visible.contains(result))
|
||||
}
|
||||
let highAnchor = CGRect(x: 400, y: 1100, width: 300, height: 40)
|
||||
precondition(DetailPlacement.frame(anchor: highAnchor, parent: parent, content: size, visible: screen).maxY == screen.maxY)
|
||||
let lowAnchor = CGRect(x: 400, y: -200, width: 300, height: 40)
|
||||
precondition(DetailPlacement.frame(anchor: lowAnchor, parent: parent, content: size, visible: screen).minY == screen.minY)
|
||||
precondition(AppAppearance.system.resolved(systemIsDark: true) == .dark)
|
||||
precondition(AppAppearance.system.resolved(systemIsDark: false) == .light)
|
||||
precondition(AppAppearance.light.resolved(systemIsDark: true) == .light)
|
||||
precondition(AppAppearance.dark.resolved(systemIsDark: false) == .dark)
|
||||
precondition(SystemAppearanceObserver.isDark(globalDomain: ["AppleInterfaceStyle": "Dark"]))
|
||||
precondition(!SystemAppearanceObserver.isDark(globalDomain: [:]))
|
||||
_ = NSApplication.shared
|
||||
let swatch = CustomColorWell.SwatchButton(frame: CGRect(x: 0, y: 0, width: 44, height: 26))
|
||||
var clicked = false
|
||||
swatch.open = { clicked = true }
|
||||
precondition(swatch.acceptsFirstMouse(for: nil))
|
||||
swatch.performClick(nil)
|
||||
precondition(clicked)
|
||||
swatch.swatchColor = NSColor(srgbRed: 0.2, green: 0.5, blue: 0.9, alpha: 1)
|
||||
let bitmap = NSBitmapImageRep(bitmapDataPlanes: nil, pixelsWide: 44, pixelsHigh: 26,
|
||||
bitsPerSample: 8, samplesPerPixel: 4, hasAlpha: true,
|
||||
isPlanar: false, colorSpaceName: .deviceRGB, bytesPerRow: 0, bitsPerPixel: 0)!
|
||||
NSGraphicsContext.saveGraphicsState()
|
||||
NSGraphicsContext.current = NSGraphicsContext(bitmapImageRep: bitmap)
|
||||
NSColor.clear.setFill()
|
||||
swatch.bounds.fill(using: .copy)
|
||||
swatch.draw(swatch.bounds)
|
||||
NSGraphicsContext.restoreGraphicsState()
|
||||
let center = bitmap.colorAt(x: 22, y: 13)!.usingColorSpace(.sRGB)!
|
||||
precondition(abs(center.redComponent - 0.2) < 0.02)
|
||||
precondition(abs(center.greenComponent - 0.5) < 0.02)
|
||||
precondition(abs(center.blueComponent - 0.9) < 0.02)
|
||||
precondition(bitmap.colorAt(x: 0, y: 0)!.alphaComponent == 0)
|
||||
let global = NSApp.appearance
|
||||
let window = NSWindow(contentRect: .zero, styleMask: .borderless, backing: .buffered, defer: true)
|
||||
window.isReleasedWhenClosed = false
|
||||
for choice in [AppAppearance.light, .system, .dark, .system] {
|
||||
WindowAppearance.apply(choice, to: window)
|
||||
if choice == .system {
|
||||
precondition(window.appearance == nil)
|
||||
precondition(window.effectiveAppearance.bestMatch(from: [.aqua, .darkAqua]) == NSApp.effectiveAppearance.bestMatch(from: [.aqua, .darkAqua]))
|
||||
} else {
|
||||
precondition(window.appearance?.name == choice.windowAppearance?.name)
|
||||
}
|
||||
precondition(NSApp.appearance === global)
|
||||
}
|
||||
window.close()
|
||||
print("PASS: outward placement, edge fallback, negative screen origins, vertical limits, explicit/system window appearance reset, independent system resolution, native swatch target/action")
|
||||
}
|
||||
}
|
||||
+28
-2
@@ -15,9 +15,35 @@
|
||||
|
||||
```bash
|
||||
swiftc -module-cache-path /private/tmp/kymo-check-cache \
|
||||
kymo/Core/Models/MetricsSnapshot.swift kymo/Core/Monitors/*.swift \
|
||||
kymo/Core/Services/*.swift kymoTests/SamplingChecks.swift -o /private/tmp/kymo-sampling-checks
|
||||
kymo/Core/Models/*.swift kymo/Core/Monitors/*.swift \
|
||||
kymo/Core/Services/*.swift kymo/Core/Extensions/*.swift kymoTests/SamplingChecks.swift -o /private/tmp/kymo-sampling-checks
|
||||
/private/tmp/kymo-sampling-checks
|
||||
```
|
||||
|
||||
此检查不证明应用沙盒权限、SwiftUI 展示、暂停按钮交互或长期性能达标。
|
||||
|
||||
B 阶段补充检查覆盖历史容量与缺失值、格式化边界、外观持久化和无效设置恢复。
|
||||
|
||||
## 呈现边界检查
|
||||
|
||||
以下检查定位与非显示窗口的外观覆盖清除,不验证鼠标交互或屏幕截图:
|
||||
|
||||
```bash
|
||||
swiftc -module-cache-path /private/tmp/kymo-check-cache \
|
||||
kymo/Core/Services/AppearancePreferences.swift \
|
||||
kymo/UI/Components/AppearanceStyle.swift kymo/UI/Components/DetailPlacement.swift \
|
||||
kymo/Features/Settings/CustomColorPicker.swift kymo/Features/Settings/CustomColorWell.swift \
|
||||
kymoTests/PresentationChecks.swift -o /private/tmp/kymo-presentation-checks
|
||||
/private/tmp/kymo-presentation-checks
|
||||
```
|
||||
|
||||
## 趋势滚动边界检查
|
||||
|
||||
```bash
|
||||
swiftc -module-cache-path /private/tmp/kymo-check-cache \
|
||||
kymo/Core/Models/*.swift kymo/UI/Charts/TrendScroll.swift \
|
||||
kymoTests/TrendScrollChecks.swift -o /private/tmp/kymo-trend-checks
|
||||
/private/tmp/kymo-trend-checks
|
||||
```
|
||||
|
||||
覆盖追加识别、缺失值、未满及满 60 点时的起止位置;不证明实际动画手感。
|
||||
|
||||
@@ -15,6 +15,37 @@ import Foundation
|
||||
let wrap = CPUMonitor.calculate(current: [[2, 0, 5, 0]], previous: [[UInt32.max, 0, 0, 0]])!
|
||||
precondition(abs(wrap.usage - 3.0 / 8) < 0.000001)
|
||||
|
||||
var history = MetricHistory()
|
||||
for index in 0..<100 {
|
||||
var item = MetricsSnapshot()
|
||||
item.date = Date(timeIntervalSince1970: Double(index))
|
||||
history.append(item)
|
||||
}
|
||||
precondition(history.samples.count == MetricHistory.capacity)
|
||||
precondition(history.samples.first?.date == Date(timeIntervalSince1970: 40))
|
||||
precondition(history.samples.last?.date == Date(timeIntervalSince1970: 99))
|
||||
precondition(history.samples.allSatisfy { $0.cpu == nil })
|
||||
precondition(MetricFormat.percent(nil) == "--")
|
||||
precondition(MetricFormat.percent(.nan) == "--")
|
||||
precondition(MetricFormat.percent(0.126) == "13%")
|
||||
precondition(MetricFormat.percent(1.2) == "100%")
|
||||
precondition(MetricFormat.bytes(nil) == "--")
|
||||
precondition(MetricFormat.bytes(1_000_000_000) == "1.0 GB")
|
||||
let suite = "kymo-checks-" + UUID().uuidString
|
||||
let defaults = UserDefaults(suiteName: suite)!
|
||||
defer { defaults.removePersistentDomain(forName: suite) }
|
||||
let preferences = AppearancePreferences(defaults: defaults)
|
||||
precondition(preferences.appearance == .system && preferences.accent == .system)
|
||||
preferences.appearance = .dark
|
||||
preferences.accent = .custom
|
||||
preferences.red = 0.75
|
||||
let restored = AppearancePreferences(defaults: defaults)
|
||||
precondition(restored.appearance == .dark && restored.accent == .custom && restored.red == 0.75)
|
||||
defaults.set("invalid", forKey: "appearance")
|
||||
defaults.set(2.0, forKey: "accent.red")
|
||||
let recovered = AppearancePreferences(defaults: defaults)
|
||||
precondition(recovered.appearance == .system && recovered.red == 1)
|
||||
print("PASS: bounded history, missing samples, format boundaries, appearance persistence and invalid defaults")
|
||||
let sampler = SystemSampler()
|
||||
let initial = await sampler.sample()
|
||||
precondition(initial.cpu == nil)
|
||||
@@ -35,8 +66,10 @@ import Foundation
|
||||
store.togglePause()
|
||||
precondition(store.isPaused)
|
||||
let pausedDate = store.snapshot.date
|
||||
let pausedHistoryCount = store.history.samples.count
|
||||
try await Task.sleep(for: .milliseconds(2200))
|
||||
precondition(store.snapshot.date == pausedDate)
|
||||
precondition(store.history.samples.count == pausedHistoryCount)
|
||||
store.togglePause()
|
||||
try await waitUntil { store.snapshot.date > pausedDate }
|
||||
precondition(!store.isPaused && store.snapshot.date > pausedDate)
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import Foundation
|
||||
|
||||
@main struct TrendScrollChecks {
|
||||
static func main() {
|
||||
precondition(!TrendScroll.isAppend(from: [], to: [0.2]))
|
||||
precondition(TrendScroll.isAppend(from: [0.2, nil], to: [0.2, nil, 0.4]))
|
||||
precondition(!TrendScroll.isAppend(from: [0.2], to: [0.4, 0.5]))
|
||||
let full: [Double?] = (0..<MetricHistory.capacity).map { Double($0) / 100 }
|
||||
precondition(TrendScroll.isAppend(from: full, to: Array(full.dropFirst()) + [nil]))
|
||||
for count in [3, MetricHistory.capacity + 1] {
|
||||
let start = TrendScroll.position(index: count - 2, count: count, progress: 0, scrolling: true)
|
||||
let end = TrendScroll.position(index: count - 1, count: count, progress: 1, scrolling: true)
|
||||
precondition(abs(start - 1) < 0.000001 && abs(end - 1) < 0.000001)
|
||||
let middle = TrendScroll.position(index: count - 2, count: count, progress: 0.5, scrolling: true)
|
||||
precondition(middle < start && abs(start - middle - 0.5 / 59) < 0.000001)
|
||||
}
|
||||
precondition(TrendScroll.position(index: 0, count: 61, progress: 1, scrolling: true) < 0)
|
||||
print("PASS: append detection, missing samples, partial/full history scroll geometry")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user