CodexBar 是一个 macOS 菜单栏应用,用于查看本机 Codex 账号状态、额度、Token 用量、详细统计信息
Swift appkitcodexcodex-clideveloper-toolsmacosmacos-appmenu-bar-appopenai-codexproductivityswiftswiftuiusage-tracker
feat: 支持圆形主题扩散并修复面板退场衔接
Bob3ce42f4026a7
diff --git a/CodexBar/App/CodexBarAppDelegate.swift b/CodexBar/App/CodexBarAppDelegate.swiftindex c4ecba5..0823887 100644--- a/CodexBar/App/CodexBarAppDelegate.swift+++ b/CodexBar/App/CodexBarAppDelegate.swift@@ -135,10 +135,14 @@ final class CodexBarAppDelegate: NSObject, NSApplicationDelegate {.receive(on: RunLoop.main).sink { [weak self] theme inguard let self,- theme == appearanceSettings.theme,- NSApplication.shared.appearance?.name != theme.appearance?.name else { return }- NSApplication.shared.appearance = theme.appearance- statusItemController?.applyAppearance(theme.appearance)+ theme == appearanceSettings.theme else { return }+ // 连续选择只应用最终主题及其来源, 即使外观未变也要消费本次圆心+ let origin = appearanceSettings.takeTransitionOrigin()+ guard NSApplication.shared.appearance?.name != theme.appearance?.name else { return }+ appearanceTransition?.performChange(from: origin) {+ NSApplication.shared.appearance = theme.appearance+ statusItemController?.applyAppearance(theme.appearance)+ }}}@@ -197,12 +201,14 @@ final class CodexBarAppDelegate: NSObject, NSApplicationDelegate {}/// 启动时把各开关的初始值记成一条基线, 之后的变更日志都是相对这条基线的增量- /// 排查时先看这条就知道当时的配置, 不必让用户逐项回忆private func logLaunchState() {// 先拼成普通字符串再交给 Logger, 避免在日志 autoclosure 中直接捕获属性let state = LogFields.joined("version=\(Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "-")","build=\(Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "-")",+ "theme=\(appearanceSettings.theme.rawValue)",+ "animations=\(mainPanelSettings.areAnimationsEnabled ? 1 : 0)",+ "taskGlow=\(taskGlowSettings.isEnabled ? 1 : 0)","keepAlive=\(keepAliveController.isEnabled ? 1 : 0)","keepAliveLimit=\(keepAliveController.maximumDuration.loggedHours)","keepAliveBattery=\(keepAliveController.lowBatteryThreshold.rawValue)",@@ -215,6 +221,7 @@ final class CodexBarAppDelegate: NSObject, NSApplicationDelegate {"autoResetLeadTimeSeconds=\(autoResetSettings.leadTime.rawValue)","menuBarQuota=\(menuBarQuotaSettings.selection.rawValue)","mainPanel=\(mainPanelSettings.layout.visibleSections.map(\.rawValue).joined(separator: ","))",+ "usageHeatmapMode=\(mainPanelSettings.usageHeatmapMode.rawValue)","hotKey=\(globalHotKeySettings.shortcut == nil ? 0 : 1)")AppLog.app.notice("App 已启动: \(state, privacy: .public)")diff --git a/CodexBar/Controllers/FallbackPanelController.swift b/CodexBar/Controllers/FallbackPanelController.swiftindex a353b50..9f81779 100644--- a/CodexBar/Controllers/FallbackPanelController.swift+++ b/CodexBar/Controllers/FallbackPanelController.swift@@ -39,6 +39,7 @@ final class FallbackPanelController {func orderOut() {panel?.orderOut(nil)+ AppearanceTransition.dismissSnapshots(in: panel)}func resizeIfVisible(contentHeight: CGFloat) {diff --git a/CodexBar/Controllers/MenuSurfaceFadeCoordinator.swift b/CodexBar/Controllers/MenuSurfaceFadeCoordinator.swiftindex c427988..507d5f7 100644--- a/CodexBar/Controllers/MenuSurfaceFadeCoordinator.swift+++ b/CodexBar/Controllers/MenuSurfaceFadeCoordinator.swift@@ -23,11 +23,13 @@ final class MenuSurfaceFadeCoordinator {func prepareForFadeIn() {contentView?.alphaValue = 0contentView?.window?.alphaValue = 0+ AppearanceTransition.setSnapshotAlpha(in: contentView?.window, to: 0)}func resetAlpha() {contentView?.alphaValue = 1contentView?.window?.alphaValue = 1+ AppearanceTransition.setSnapshotAlpha(in: contentView?.window, to: 1)}func fadeIn(duration: TimeInterval, completion: @escaping () -> Void) {@@ -90,6 +92,7 @@ final class MenuSurfaceFadeCoordinator {context.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)activeMenuSurfaceWindow?.animator().alphaValue = alphacontentView.animator().alphaValue = alpha+ AppearanceTransition.fadeSnapshots(in: activeMenuSurfaceWindow, to: alpha)}}}diff --git a/CodexBar/Controllers/SidePanelPresenter.swift b/CodexBar/Controllers/SidePanelPresenter.swiftindex 0f05bce..cb1abf0 100644--- a/CodexBar/Controllers/SidePanelPresenter.swift+++ b/CodexBar/Controllers/SidePanelPresenter.swift@@ -38,6 +38,7 @@ final class SidePanelDrawerAnimator {CATransaction.setDisableActions(true)layer.removeAnimation(forKey: animationKey)layer.transform = CATransform3DMakeTranslation(translationX, 0, 0)+ AppearanceTransition.setSnapshotTranslation(in: contentViewProvider()?.window, to: layer.transform)CATransaction.commit()}@@ -66,6 +67,7 @@ final class SidePanelDrawerAnimator {animation.timingFunction = CAMediaTimingFunction(name: timing)layer.add(animation, forKey: animationKey)layer.transform = targetTransform+ AppearanceTransition.animateSnapshotTranslation(in: contentViewProvider()?.window, animation: animation, to: targetTransform)CATransaction.commit()}diff --git a/CodexBar/Controllers/SidePanelSupport.swift b/CodexBar/Controllers/SidePanelSupport.swiftindex dc46f1e..f46df00 100644--- a/CodexBar/Controllers/SidePanelSupport.swift+++ b/CodexBar/Controllers/SidePanelSupport.swift@@ -189,6 +189,7 @@ enum SidePanelSupport {let parentWindow = panel.parent ?? menuSurfaceWindowlet shouldRestoreParentKey = panel.isKeyWindowpanel.orderOut(nil)+ AppearanceTransition.dismissSnapshots(in: panel)parentWindow?.removeChildWindow(panel)if shouldRestoreParentKey {restoreMenuSurfaceKeyWindow(parentWindow)diff --git a/CodexBar/Controllers/StatusItemController.swift b/CodexBar/Controllers/StatusItemController.swiftindex 1704b0f..b7f7317 100644--- a/CodexBar/Controllers/StatusItemController.swift+++ b/CodexBar/Controllers/StatusItemController.swift@@ -931,7 +931,11 @@ final class StatusItemController: NSObject, NSMenuDelegate {// 主动关闭先清除宿主身份, 避免同步的关闭回调重入清理流程activeMenuSurface = .noneif popover.isShown {+ let window = popover.contentViewController?.view.window+ window?.alphaValue = 0+ AppearanceTransition.dismissSnapshots(in: window)popover.performClose(nil)+ window?.alphaValue = 1}fallbackPanelController.orderOut()diff --git a/CodexBar/Services/Settings/AppearanceSettings.swift b/CodexBar/Services/Settings/AppearanceSettings.swiftindex 2826661..c1e44d5 100644--- a/CodexBar/Services/Settings/AppearanceSettings.swift+++ b/CodexBar/Services/Settings/AppearanceSettings.swift@@ -4,6 +4,7 @@ import Combine@MainActorfinal class AppearanceSettings: ObservableObject {@Published private(set) var theme: Theme+ private var transitionOrigin: TransitionOrigin?private let defaults: UserDefaultsprivate static let themeKey = "Appearance.theme"@@ -13,15 +14,22 @@ final class AppearanceSettings: ObservableObject {theme = Self.loadTheme(from: defaults)}- func setTheme(_ theme: Theme) {+ func setTheme(_ theme: Theme, from origin: TransitionOrigin? = nil) {guard theme != self.theme else { return }defaults.set(theme.rawValue, forKey: Self.themeKey)+ transitionOrigin = originself.theme = theme}+ func takeTransitionOrigin() -> TransitionOrigin? {+ defer { transitionOrigin = nil }+ return transitionOrigin+ }+func refresh() {let theme = Self.loadTheme(from: defaults)if theme != self.theme {+ transitionOrigin = nilself.theme = theme}}@@ -30,6 +38,11 @@ final class AppearanceSettings: ObservableObject {defaults.string(forKey: themeKey).flatMap(Theme.init(rawValue:)) ?? .system}+ struct TransitionOrigin {+ let screenPoint: CGPoint+ weak var window: NSWindow?+ }+enum Theme: String, CaseIterable {case systemcase lightdiff --git a/CodexBar/Views/Settings/AppSettingsView.swift b/CodexBar/Views/Settings/AppSettingsView.swiftindex a12253f..c66e585 100644--- a/CodexBar/Views/Settings/AppSettingsView.swift+++ b/CodexBar/Views/Settings/AppSettingsView.swift@@ -27,6 +27,7 @@ struct AppSettingsView: View {@State private var notificationAnchorProvider = ScreenFrameProvider()@State private var autoResetAnchorProvider = ScreenFrameProvider()@State private var keepAliveAnchorProvider = ScreenFrameProvider()+ @State private var themeAnchorProvider = ScreenFrameProvider()@State private var rebuildableDates = [String]()@State private var selectedRebuildRange: RebuildDateRange?@State private var isShowingRebuildConfirmation = false@@ -361,13 +362,24 @@ private extension AppSettingsView {title: "settings.appearance.theme.title",selection: Binding(get: { appearanceSettings.theme },- set: { appearanceSettings.setTheme($0) }+ set: { theme in+ let origin = themeAnchorProvider.currentScreenFrame().map {+ AppearanceSettings.TransitionOrigin(+ screenPoint: CGPoint(x: $0.midX, y: $0.midY),+ window: themeAnchorProvider.window+ )+ }+ appearanceSettings.setTheme(theme, from: origin)+ }),options: AppearanceSettings.Theme.allCases,label: { $0.title },width: Metrics.themePickerWidth,alignment: .trailing)+ .background {+ ScreenFrameReader(provider: themeAnchorProvider)+ }}}diff --git a/CodexBar/Views/Shared/AppearanceTransition.swift b/CodexBar/Views/Shared/AppearanceTransition.swiftindex c535765..4745d0c 100644--- a/CodexBar/Views/Shared/AppearanceTransition.swift+++ b/CodexBar/Views/Shared/AppearanceTransition.swift@@ -9,9 +9,56 @@ final class AppearanceTransition {window.childWindows?.contains { $0 is SnapshotPanel } == true}+ static func setSnapshotAlpha(in window: NSWindow?, to alpha: CGFloat) {+ for snapshot in snapshotPanels(in: window) {+ snapshot.alphaValue = alpha+ snapshot.snapshotView.alphaValue = alpha+ }+ }++ /// 复用调用方的动画事务, 保持快照与源窗口的时间和曲线一致+ static func fadeSnapshots(in window: NSWindow?, to alpha: CGFloat) {+ for snapshot in snapshotPanels(in: window) {+ snapshot.animator().alphaValue = alpha+ snapshot.snapshotView.animator().alphaValue = alpha+ }+ }++ static func setSnapshotTranslation(in window: NSWindow?, to transform: CATransform3D) {+ snapshotPanels(in: window).forEach { $0.snapshotView.setTranslation(transform) }+ }++ static func animateSnapshotTranslation(in window: NSWindow?, animation: CABasicAnimation, to transform: CATransform3D) {+ snapshotPanels(in: window).forEach { $0.snapshotView.animateTranslation(animation, to: transform) }+ }++ static func dismissSnapshots(in window: NSWindow?) {+ snapshotPanels(in: window).forEach { $0.dismiss() }+ }++ private static func snapshotPanels(in window: NSWindow?) -> [SnapshotPanel] {+ window?.childWindows?.compactMap { $0 as? SnapshotPanel } ?? []+ }++ static func anchoredOrigin(from screenPoint: CGPoint?, isSourceWindow: Bool, screenFrame: CGRect, mouseLocation: CGPoint) -> CGPoint? {+ let point: CGPoint+ if let screenPoint, isSourceWindow {+ point = screenPoint+ } else if screenFrame.contains(mouseLocation) {+ point = mouseLocation+ } else {+ return nil+ }+ return CGPoint(+ x: (point.x - screenFrame.minX) / screenFrame.width,+ y: (screenFrame.maxY - point.y) / screenFrame.height+ )+ }+private let animationsEnabled: () -> Boolprivate var observation: NSKeyValueObservation?private var pendingSnapshots: [(NSWindow, SnapshotPanel)]?+ private var changeOrigin: AppearanceSettings.TransitionOrigin?init(animationsEnabled: @escaping () -> Bool) {self.animationsEnabled = animationsEnabled@@ -29,6 +76,13 @@ final class AppearanceTransition {}}+ func performChange(from origin: AppearanceSettings.TransitionOrigin?, _ change: () -> Void) {+ let previousOrigin = changeOrigin+ changeOrigin = origin+ defer { changeOrigin = previousOrigin }+ change()+ }+func stop() {observation?.invalidate()observation = nil@@ -41,13 +95,14 @@ final class AppearanceTransition {// 同一轮内连续切换时保留最初画面, 最终外观由 AppKit 决定guard pendingSnapshots == nil else { return }let animated = animationsEnabled()+ let mouseLocation = NSEvent.mouseLocationlet windows = NSApplication.shared.windows.filter {$0.isVisible && !$0.isMiniaturized && !($0 is SnapshotPanel) && !($0 is TaskGlowPanel)}pendingSnapshots = windows.compactMap { window -> (NSWindow, SnapshotPanel)? inlet previous = window.childWindows?.compactMap { $0 as? SnapshotPanel } ?? []previous.forEach { $0.snapshotView.freeze() }- let snapshot = animated ? SnapshotPanel(capturing: window, previous: previous) : nil+ let snapshot = animated ? SnapshotPanel(capturing: window, previous: previous, changeOrigin: changeOrigin, mouseLocation: mouseLocation) : nil// 先接上新快照, 避免连续切换时短暂报告过渡已结束snapshot?.present(over: window)previous.forEach { $0.dismiss() }@@ -85,7 +140,7 @@ final class AppearanceTransition {false}- init?(capturing window: NSWindow, previous: [SnapshotPanel]) {+ init?(capturing window: NSWindow, previous: [SnapshotPanel], changeOrigin: AppearanceSettings.TransitionOrigin?, mouseLocation: CGPoint) {guard let view = Self.sourceView(in: window), !view.bounds.isEmpty,let bitmap = view.bitmapImageRepForCachingDisplay(in: view.bounds) else { return nil }view.cacheDisplay(in: view.bounds, to: bitmap)@@ -95,10 +150,17 @@ final class AppearanceTransition {sourceAppearance = view.effectiveAppearance.bestMatch(from: [.aqua, .darkAqua])let image = NSImage(size: view.bounds.size)image.addRepresentation(bitmap)- snapshotView = SnapshotView(image: image)+ let screenFrame = window.convertToScreen(view.convert(view.bounds, to: nil))+ let origin = AppearanceTransition.anchoredOrigin(+ from: changeOrigin?.screenPoint,+ isSourceWindow: changeOrigin?.window === window,+ screenFrame: screenFrame,+ mouseLocation: mouseLocation+ )+ snapshotView = SnapshotView(image: image, origin: origin)let hasTitlebar = window.styleMask.contains(.titled)super.init(- contentRect: window.convertToScreen(view.convert(view.bounds, to: nil)),+ contentRect: screenFrame,styleMask: hasTitlebar ? [.titled, .fullSizeContentView, .nonactivatingPanel] : [.borderless, .nonactivatingPanel],backing: .buffered,defer: false@@ -190,24 +252,25 @@ final class AppearanceTransition {}}- private final class SnapshotView: NSImageView {+ final class SnapshotView: NSImageView {private let revealMask = CAGradientLayer()+ private let revealOrigin: CGPoint+ private let translationAnimationKey = "appearanceExitTranslation"override var isFlipped: Bool {true}- init(image: NSImage) {+ init(image: NSImage, origin: CGPoint? = nil) {+ revealOrigin = origin ?? CGPoint(x: .random(in: 0.1 ... 0.9), y: .random(in: 0.1 ... 0.9))super.init(frame: NSRect(origin: .zero, size: image.size))self.image = imageimageScaling = .scaleAxesIndependentlyautoresizingMask = [.width, .height]wantsLayer = truerevealMask.colors = [NSColor.clear.cgColor, NSColor.black.cgColor]- revealMask.startPoint = CGPoint(x: 0, y: 0)- revealMask.endPoint = CGPoint(x: 1, y: 1)revealMask.locations = [0, 0]- revealMask.frame = bounds+ updateMaskGeometry()layer?.mask = revealMask}@@ -216,14 +279,42 @@ final class AppearanceTransition {fatalError("init(coder:) has not been implemented")}+ func setTranslation(_ transform: CATransform3D) {+ CATransaction.begin()+ CATransaction.setDisableActions(true)+ layer?.removeAnimation(forKey: translationAnimationKey)+ layer?.transform = transform+ CATransaction.commit()+ }++ func animateTranslation(_ animation: CABasicAnimation, to transform: CATransform3D) {+ layer?.add(animation, forKey: translationAnimationKey)+ layer?.transform = transform+ }+override func layout() {super.layout()CATransaction.begin()CATransaction.setDisableActions(true)- revealMask.frame = bounds+ updateMaskGeometry()CATransaction.commit()}+ private func updateMaskGeometry() {+ guard !bounds.isEmpty else { return }+ revealMask.frame = bounds+ let origin = revealOrigin+ let center = CGPoint(x: origin.x * bounds.width, y: origin.y * bounds.height)+ let radius = hypot(+ max(abs(center.x), abs(bounds.width - center.x)),+ max(abs(center.y), abs(bounds.height - center.y))+ ) + 1+ revealMask.type = .radial+ revealMask.startPoint = origin+ // 径向渐变按横纵半径绘制椭圆, 分别归一化同一半径才能保持圆形并覆盖最远角+ revealMask.endPoint = CGPoint(x: origin.x + radius / bounds.width, y: origin.y + radius / bounds.height)+ }+func freeze() {let locations = revealMask.presentation()?.locations ?? revealMask.locationsCATransaction.begin()@@ -242,10 +333,10 @@ final class AppearanceTransition {func reveal(completion: @escaping @MainActor () -> Void) {let animation = CAKeyframeAnimation(keyPath: "locations")- animation.values = [[0, 0], [0, 0.1], [0.9, 1], [1, 1]]- animation.keyTimes = [0, 0.05, 0.95, 1]- animation.duration = 0.45- animation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)+ animation.values = [[0, 0], [0, 0.06], [0.94, 1], [1, 1]]+ animation.keyTimes = [0, 0.03, 0.97, 1]+ animation.duration = 0.5+ animation.timingFunction = CAMediaTimingFunction(controlPoints: 0.76, 0, 0.24, 1)CATransaction.begin()CATransaction.setDisableActions(true)CATransaction.setCompletionBlock {diff --git a/Config/Version.xcconfig b/Config/Version.xcconfigindex f02f4ac..d67784e 100644--- a/Config/Version.xcconfig+++ b/Config/Version.xcconfig@@ -1,2 +1,2 @@-MARKETING_VERSION = 5.0.6-CURRENT_PROJECT_VERSION = 206+MARKETING_VERSION = 5.0.7+CURRENT_PROJECT_VERSION = 207diff --git a/Tests/App/Presentation/AppearanceTransitionTests.swift b/Tests/App/Presentation/AppearanceTransitionTests.swiftnew file mode 100644index 0000000..89edf70--- /dev/null+++ b/Tests/App/Presentation/AppearanceTransitionTests.swift@@ -0,0 +1,140 @@+import AppKit+import QuartzCore+import Testing++struct AppearanceTransitionTests {+ @Test func unanchoredSnapshotsChooseIndependentOriginsWithinCentralRegion() throws {+ var origins = [CGPoint]()+ for _ in 0 ..< 64 {+ let view = AppearanceTransition.SnapshotView(image: NSImage(size: CGSize(width: 640, height: 240)))+ let mask = try #require(view.layer?.mask as? CAGradientLayer)+ let origin = mask.startPoint+ #expect(mask.type == .radial)+ #expect((0.1 ... 0.9).contains(origin.x))+ #expect((0.1 ... 0.9).contains(origin.y))+ view.setFrameSize(CGSize(width: 240, height: 640))+ view.layout()+ #expect(mask.startPoint == origin)+ origins.append(origin)+ }+ #expect(Set(origins.map(\.x)).count > 1)+ #expect(Set(origins.map(\.y)).count > 1)+ }++ @Test func manualAnchorHasPriorityOnlyInItsSourceWindow() {+ let frame = CGRect(x: 100, y: 200, width: 640, height: 240)+ let origin = CGPoint(x: 580, y: 380)+ let outside = CGPoint.zero+ let inside = CGPoint(x: 420, y: 320)+ #expect(AppearanceTransition.anchoredOrigin(from: origin, isSourceWindow: true, screenFrame: frame, mouseLocation: outside) == CGPoint(x: 0.75, y: 0.25))+ #expect(AppearanceTransition.anchoredOrigin(from: origin, isSourceWindow: true, screenFrame: frame, mouseLocation: inside) == CGPoint(x: 0.75, y: 0.25))+ #expect(AppearanceTransition.anchoredOrigin(from: origin, isSourceWindow: false, screenFrame: frame, mouseLocation: outside) == nil)+ #expect(AppearanceTransition.anchoredOrigin(from: origin, isSourceWindow: false, screenFrame: frame, mouseLocation: inside) == CGPoint(x: 0.5, y: 0.5))+ #expect(AppearanceTransition.anchoredOrigin(from: nil, isSourceWindow: false, screenFrame: frame, mouseLocation: outside) == nil)+ }++ @Test func pointerAnchorUsesPanelCoordinatesWithoutClampingToRandomRegion() {+ let frame = CGRect(x: -900, y: -400, width: 640, height: 240)+ let inside = CGPoint(x: -884, y: -172)+ #expect(AppearanceTransition.anchoredOrigin(from: nil, isSourceWindow: false, screenFrame: frame, mouseLocation: inside) == CGPoint(x: 0.025, y: 0.05))+ for outside in [CGPoint(x: -901, y: -280), CGPoint(x: -259, y: -280), CGPoint(x: -580, y: -401), CGPoint(x: -580, y: -159)] {+ #expect(AppearanceTransition.anchoredOrigin(from: nil, isSourceWindow: false, screenFrame: frame, mouseLocation: outside) == nil)+ }+ }++ @Test func manualRevealHasEqualHorizontalAndVerticalRadiiAfterResizing() throws {+ let view = AppearanceTransition.SnapshotView(+ image: NSImage(size: CGSize(width: 640, height: 240)),+ origin: CGPoint(x: 0.75, y: 0.5)+ )+ for size in [CGSize(width: 640, height: 240), CGSize(width: 240, height: 640)] {+ view.setFrameSize(size)+ view.layout()+ let bitmap = try renderMask(of: view, locations: [0.09, 0.11])+ let centerX = Int(size.width * 0.75)+ let centerY = Int(size.height * 0.5)+ for offset in [-25, 0, 25] {+ #expect(try alpha(in: bitmap, x: centerX + offset, y: centerY) < 0.01)+ #expect(try alpha(in: bitmap, x: centerX, y: centerY + offset) < 0.01)+ }+ #expect(try alpha(in: bitmap, x: centerX - 58, y: centerY) > 0.99)+ #expect(try alpha(in: bitmap, x: centerX, y: centerY - 58) > 0.99)+ }+ }++ @Test(arguments: [CGPoint(x: 0.8, y: 0.2), CGPoint(x: -0.5, y: 1.5)])+ func radialRevealCoversAllCornersIncludingOriginsOutsideWindow(_ origin: CGPoint) throws {+ let view = AppearanceTransition.SnapshotView(+ image: NSImage(size: CGSize(width: 640, height: 240)),+ origin: origin+ )+ let bitmap = try renderMask(of: view, locations: [1, 1])+ for x in [0, 639] {+ for y in [0, 239] {+ #expect(try alpha(in: bitmap, x: x, y: y) < 0.01)+ }+ }+ }++ @Test func interruptedDrawerMovementResetsWithoutRemovingRadialReveal() throws {+ let view = AppearanceTransition.SnapshotView(image: NSImage(size: CGSize(width: 320, height: 240)))+ let layer = try #require(view.layer)+ let mask = try #require(layer.mask as? CAGradientLayer)+ let reveal = CABasicAnimation(keyPath: "locations")+ reveal.fromValue = [0, 0]+ reveal.toValue = [1, 1]+ reveal.duration = 0.5+ mask.add(reveal, forKey: "testReveal")++ for (start, end, duration) in [(0.0, -320.0, 0.12), (-160.0, 0.0, 0.18)] {+ let animation = CABasicAnimation(keyPath: "transform")+ let from = CATransform3DMakeTranslation(start, 0, 0)+ let to = CATransform3DMakeTranslation(end, 0, 0)+ animation.fromValue = from+ animation.toValue = to+ animation.duration = duration+ view.animateTranslation(animation, to: to)++ let keys = try #require(layer.animationKeys())+ #expect(keys.count == 1)+ let key = try #require(keys.first)+ let copied = try #require(layer.animation(forKey: key) as? CABasicAnimation)+ #expect(copied.duration == duration)+ #expect(try CATransform3DEqualToTransform(#require(copied.fromValue as? NSValue).caTransform3DValue, from))+ #expect(try CATransform3DEqualToTransform(#require(copied.toValue as? NSValue).caTransform3DValue, to))+ #expect(CATransform3DEqualToTransform(layer.transform, to))+ }++ view.setTranslation(CATransform3DIdentity)+ #expect(layer.animationKeys()?.isEmpty != false)+ #expect(CATransform3DIsIdentity(layer.transform))+ #expect(mask.animation(forKey: "testReveal") != nil)+ }++ private func renderMask(of view: NSView, locations: [NSNumber]) throws -> NSBitmapImageRep {+ let mask = try #require(view.layer?.mask as? CAGradientLayer)+ mask.locations = locations+ let bitmap = try #require(NSBitmapImageRep(+ bitmapDataPlanes: nil,+ pixelsWide: Int(view.bounds.width),+ pixelsHigh: Int(view.bounds.height),+ bitsPerSample: 8,+ samplesPerPixel: 4,+ hasAlpha: true,+ isPlanar: false,+ colorSpaceName: .deviceRGB,+ bytesPerRow: 0,+ bitsPerPixel: 0+ ))+ let context = try #require(NSGraphicsContext(bitmapImageRep: bitmap))+ context.cgContext.clear(view.bounds)+ context.cgContext.translateBy(x: 0, y: view.bounds.height)+ context.cgContext.scaleBy(x: 1, y: -1)+ mask.render(in: context.cgContext)+ return bitmap+ }++ private func alpha(in bitmap: NSBitmapImageRep, x: Int, y: Int) throws -> CGFloat {+ try #require(bitmap.colorAt(x: x, y: y)).alphaComponent+ }+}diff --git a/Tests/App/Settings/AppearanceSettingsTests.swift b/Tests/App/Settings/AppearanceSettingsTests.swiftindex 9506f58..8e90383 100644--- a/Tests/App/Settings/AppearanceSettingsTests.swift+++ b/Tests/App/Settings/AppearanceSettingsTests.swift@@ -48,4 +48,43 @@ struct AppearanceSettingsTests {#expect(AppearanceSettings.Theme.light.appearance?.name == .aqua)#expect(AppearanceSettings.Theme.dark.appearance?.name == .darkAqua)}++ @Test func manualOriginIsConsumedOnceAndNeverPersisted() throws {+ let preferences = try TestPreferences()+ defer { preferences.remove() }+ let settings = AppearanceSettings(defaults: preferences.defaults)+ let origin = AppearanceSettings.TransitionOrigin(screenPoint: CGPoint(x: 480, y: 360))++ settings.setTheme(.dark, from: origin)+ #expect(settings.takeTransitionOrigin()?.screenPoint == origin.screenPoint)+ #expect(settings.takeTransitionOrigin() == nil)+ #expect(AppearanceSettings(defaults: preferences.defaults).takeTransitionOrigin() == nil)++ settings.setTheme(.dark, from: origin)+ #expect(settings.takeTransitionOrigin() == nil)+ }++ @Test func latestThemeChangeDeterminesOriginBeforeDeferredApplication() throws {+ let preferences = try TestPreferences()+ defer { preferences.remove() }+ let settings = AppearanceSettings(defaults: preferences.defaults)+ let firstOrigin = AppearanceSettings.TransitionOrigin(screenPoint: CGPoint(x: 480, y: 360))+ let lastOrigin = AppearanceSettings.TransitionOrigin(screenPoint: CGPoint(x: 720, y: 420))++ settings.setTheme(.light, from: firstOrigin)+ settings.setTheme(.dark, from: lastOrigin)+ settings.refresh()+ #expect(settings.takeTransitionOrigin()?.screenPoint == lastOrigin.screenPoint)++ settings.setTheme(.light, from: firstOrigin)+ settings.setTheme(.dark)+ #expect(settings.takeTransitionOrigin() == nil)++ settings.setTheme(.light, from: firstOrigin)+ settings.setTheme(.dark, from: lastOrigin)+ preferences.defaults.set("light", forKey: "Appearance.theme")+ settings.refresh()+ #expect(settings.theme == .light)+ #expect(settings.takeTransitionOrigin() == nil)+ }}diff --git a/appcast.xml b/appcast.xmlindex 2dcb5bb..6a932d0 100644--- a/appcast.xml+++ b/appcast.xml@@ -5,6 +5,20 @@<link>https://codexbar.zabrian.app/appcast.xml</link><description>CodexBar appcast feed</description><language>zh-CN</language>+ <item>+ <title>CodexBar.app 5.0.7</title>+ <sparkle:version>207</sparkle:version>+ <sparkle:shortVersionString>5.0.7</sparkle:shortVersionString>+ <sparkle:minimumSystemVersion>15.0</sparkle:minimumSystemVersion>+ <sparkle:minimumAutoupdateVersion>200</sparkle:minimumAutoupdateVersion>+ <sparkle:informationalUpdate><sparkle:belowVersion>200</sparkle:belowVersion></sparkle:informationalUpdate>+ <link xml:lang="en-US">https://codexbar.zabrian.app/notes?lang=en-US#5.0.0-Guide</link>+ <link xml:lang="zh-CN">https://codexbar.zabrian.app/notes?lang=zh-CN#5.0.0-Guide</link>+ <sparkle:releaseNotesLink xml:lang="en-US">https://codexbar.zabrian.app/notes?lang=en-US#5.0.7</sparkle:releaseNotesLink>+ <sparkle:releaseNotesLink xml:lang="zh-CN">https://codexbar.zabrian.app/notes?lang=zh-CN#5.0.7</sparkle:releaseNotesLink>+ <pubDate>Mon, 26 Oct 2026 18:53:05 +0800</pubDate>+ <enclosure url="https://codexbar.zabrian.app/download/CodexBar-v5.0.7.dmg" sparkle:edSignature="4ctM7P/gTxM2FjlMw/5b/SmiliThbtFUqfyKwX+eIgDpQFOTrlzxEgcVvOY7hxd3qKghsP51338dyMAYo4lAAw==" length="10290176" type="application/octet-stream"/>+ </item><item><title>CodexBar.app 5.0.6</title><sparkle:version>206</sparkle:version>