feat(settings): 默认启用短动效并提供独立减弱动画选项

This commit is contained in:
2026-11-04 11:53:17 +08:00
parent 40a7a55edf
commit f18f6652ff
23 changed files with 443 additions and 34 deletions
@@ -24,16 +24,19 @@ import Observation
private let visibility: (Bool) -> Void
private let menuTitle: (String) -> String
private let openSettings: () -> Void
private let reducedMotion: () -> Bool
private var showingStatusMenu = false
private var isHiding = false
init<Content: View>(installStatusItem: Bool = true, visibility: @escaping (Bool) -> Void,
menuTitle: @escaping (String) -> String = { $0 },
openSettings: @escaping () -> Void = {},
reducedMotion: @escaping () -> Bool = { false },
@ViewBuilder content: @escaping (PanelPresentation) -> Content) {
self.visibility = visibility
self.menuTitle = menuTitle
self.openSettings = openSettings
self.reducedMotion = reducedMotion
self.content = {
let host = NSHostingView(rootView: content($0))
// The controller owns the fixed panel frame; content must not negotiate window limits.
@@ -112,7 +115,12 @@ import Observation
return window.convertToScreen(button.convert(button.bounds, to: nil)).contains(screenPoint)
}
private func applyWindowMotion() {
panel.animationBehavior = reducedMotion() || NSWorkspace.shared.accessibilityDisplayShouldReduceMotion ? .none : .default
}
func show() {
applyWindowMotion()
guard !panel.isVisible else { panel.makeKeyAndOrderFront(nil); return }
place()
presentation.isOpen = true
@@ -136,6 +144,7 @@ import Observation
isHiding = true
defer { isHiding = false }
presentation.isOpen = false
applyWindowMotion()
panel.orderOut(nil)
#if DEBUG || KYMO_AUDIT
if let content = panel.contentView { lastHiddenContent = content }
@@ -75,6 +75,9 @@ struct MenuPanelView: View {
}
.background(Color("PanelBackground"), in: .rect(cornerRadius: 18))
.clipShape(.rect(cornerRadius: 18))
.environment(\.metricAnimationsEnabled, MetricMotionPolicy.enabled(
reduced: preferences.reduceMotion, systemReduced: reduceMotion, visible: metrics.isPanelVisible,
paused: metrics.isPaused, sleeping: metrics.isSystemSleeping || metrics.isDisplaySleeping))
.modifier(AppearanceStyle(preferences: preferences))
}
+15 -1
View File
@@ -30,7 +30,10 @@ import AppKit
windowNumber: controller.panel.isVisible ? controller.panel.windowNumber : nil,
hoveredPlots: views.filter { $0.input?.hoveredIndex != nil }.count, nativePlots: views.count,
pointerInsidePanel: controller.panel.isVisible && controller.panel.frame.contains(NSEvent.mouseLocation),
plotBounds: views.map { [Double($0.bounds.width), Double($0.bounds.height)] })
plotBounds: views.map { [Double($0.bounds.width), Double($0.bounds.height)] },
animatedPlots: views.filter { $0.input?.animates == true }.count)
if event == "open1.10", ProcessInfo.processInfo.environment["KYMO_AUDIT_CAPTURE"] == "1",
let content = controller.panel.contentView { capture(content) }
}
func wait(_ seconds: Int) async { try? await Task.sleep(for: .seconds(seconds)) }
// Pin the test window so unrelated focus changes cannot invalidate a measurement.
@@ -59,6 +62,17 @@ import AppKit
NSApp.terminate(nil)
}
}
/// Captures only our own hosted panel, never the desktop. Excluded from normal Release.
private static func capture(_ content: NSView) {
guard content.bounds.width > 0, content.bounds.height > 0,
content.bounds.width * content.bounds.height <= 1_100_000,
let bitmap = content.bitmapImageRepForCachingDisplay(in: content.bounds) else { return }
content.cacheDisplay(in: content.bounds, to: bitmap)
guard let png = bitmap.representation(using: .png, properties: [:]),
let data = try? JSONSerialization.data(withJSONObject: ["event": "audit.capture", "png": png.base64EncodedString()]) else { return }
try? FileHandle.standardOutput.write(contentsOf: data + Data([10]))
}
/// Uses real connection lifecycle but injects local callbacks; peer auth is tested separately by RPCs.
private static func checkRequestCompletion() async {
for _ in 0..<20 {
@@ -62,12 +62,16 @@ struct AppearanceSettingsView: View {
.tint(.primary)
}
}
Section {
Toggle("motion.reduce", isOn: $preferences.reduceMotion)
Text("motion.help").font(.callout).foregroundStyle(.secondary)
}
Section {
Toggle("sampling.backgroundEnabled", isOn: $sampling.backgroundEnabled)
LabeledContent("sampling.background") {
IntervalControl(milliseconds: $sampling.backgroundMilliseconds)
}.disabled(!sampling.backgroundEnabled)
Text("sampling.backgroundHelp").font(.callout).foregroundStyle(.secondary)
Text("sampling.recordingHelp").font(.callout).foregroundStyle(.secondary)
}
}
.formStyle(.grouped)