CodexBar 是一个 macOS 菜单栏应用,用于查看本机 Codex 账号状态、额度、Token 用量、详细统计信息
Swift appkitcodexcodex-clideveloper-toolsmacosmacos-appmenu-bar-appopenai-codexproductivityswiftswiftuiusage-tracker
fix: 修复快捷键弹窗窗口层级
Bobdce281345722
diff --git a/CodexBar.xcodeproj/project.pbxproj b/CodexBar.xcodeproj/project.pbxprojindex 1a8fa5b..2fe24e7 100644--- a/CodexBar.xcodeproj/project.pbxproj+++ b/CodexBar.xcodeproj/project.pbxproj@@ -275,7 +275,7 @@"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";CODE_SIGN_STYLE = Automatic;COMBINE_HIDPI_IMAGES = YES;- CURRENT_PROJECT_VERSION = 19;+ CURRENT_PROJECT_VERSION = 20;DEVELOPMENT_TEAM = 4KJ362VJW5;ENABLE_APP_INTENTS_METADATA_GENERATION = NO;ENABLE_APP_SANDBOX = NO;@@ -290,7 +290,7 @@"$(inherited)","@executable_path/../Frameworks",);- MARKETING_VERSION = 2.4.3;+ MARKETING_VERSION = 2.4.4;PRODUCT_BUNDLE_IDENTIFIER = app.zabrian.codexbar;PRODUCT_NAME = "$(TARGET_NAME)";REGISTER_APP_GROUPS = YES;@@ -312,7 +312,7 @@"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";CODE_SIGN_STYLE = Automatic;COMBINE_HIDPI_IMAGES = YES;- CURRENT_PROJECT_VERSION = 19;+ CURRENT_PROJECT_VERSION = 20;DEVELOPMENT_TEAM = 4KJ362VJW5;ENABLE_APP_INTENTS_METADATA_GENERATION = NO;ENABLE_APP_SANDBOX = NO;@@ -327,7 +327,7 @@"$(inherited)","@executable_path/../Frameworks",);- MARKETING_VERSION = 2.4.3;+ MARKETING_VERSION = 2.4.4;PRODUCT_BUNDLE_IDENTIFIER = app.zabrian.codexbar;PRODUCT_NAME = "$(TARGET_NAME)";PROVISIONING_PROFILE_SPECIFIER = "";diff --git a/CodexBar/Controllers/HostingWindowController.swift b/CodexBar/Controllers/HostingWindowController.swiftindex 949e07d..e986ab4 100644--- a/CodexBar/Controllers/HostingWindowController.swift+++ b/CodexBar/Controllers/HostingWindowController.swift@@ -1,5 +1,18 @@import AppKit+@MainActor+final class AuxiliaryHostingWindow: NSWindow {+ var allowsKeyFocus = true++ override var canBecomeKey: Bool {+ allowsKeyFocus+ }++ override var canBecomeMain: Bool {+ false+ }+}+// 承载 SwiftUI 内容的单窗口控制器基类, 统一懒创建、居中与窗口管理逻辑@MainActorclass HostingWindowController {@@ -48,9 +61,14 @@ class HostingWindowController {window.deminiaturize(nil)}- NSApplication.shared.activate()- window.makeKeyAndOrderFront(nil)+ (window as? AuxiliaryHostingWindow)?.allowsKeyFocus = truewindow.orderFrontRegardless()+ NSRunningApplication.current.activate(options: [])+ window.makeKeyAndOrderFront(nil)+ }++ func setAllowsKeyFocus(_ allowsKeyFocus: Bool) {+ (window as? AuxiliaryHostingWindow)?.allowsKeyFocus = allowsKeyFocus}func center(_ window: NSWindow) {diff --git a/CodexBar/Controllers/LogWindowController.swift b/CodexBar/Controllers/LogWindowController.swiftindex 9e432d9..206583a 100644--- a/CodexBar/Controllers/LogWindowController.swift+++ b/CodexBar/Controllers/LogWindowController.swift@@ -16,7 +16,7 @@ final class LogWindowController: HostingWindowController {override func makeWindow() -> NSWindow {let hostingController = NSHostingController(rootView: LogView(store: store))- let window = NSWindow(contentViewController: hostingController)+ let window = AuxiliaryHostingWindow(contentViewController: hostingController)window.title = "CodexBar 日志"window.styleMask = [.titled, .closable, .miniaturizable, .resizable]window.contentMinSize = Metrics.minimumContentSizediff --git a/CodexBar/Controllers/PopoverDismissMonitor.swift b/CodexBar/Controllers/PopoverDismissMonitor.swiftindex cfe30f5..e107b28 100644--- a/CodexBar/Controllers/PopoverDismissMonitor.swift+++ b/CodexBar/Controllers/PopoverDismissMonitor.swift@@ -155,8 +155,9 @@ final class PopoverDismissMonitor {return}- NSApplication.shared.activate()- popoverWindow.makeKey()+ popoverWindow.orderFrontRegardless()+ NSRunningApplication.current.activate(options: [])+ popoverWindow.makeKeyAndOrderFront(nil)}private func removeEventMonitor(_ monitor: inout Any?) {diff --git a/CodexBar/Controllers/SettingsWindowController.swift b/CodexBar/Controllers/SettingsWindowController.swiftindex 5995c2b..7eda423 100644--- a/CodexBar/Controllers/SettingsWindowController.swift+++ b/CodexBar/Controllers/SettingsWindowController.swift@@ -33,7 +33,7 @@ final class SettingsWindowController: HostingWindowController {)hostingController.sizingOptions = [.preferredContentSize]- let window = NSWindow(contentViewController: hostingController)+ let window = AuxiliaryHostingWindow(contentViewController: hostingController)window.title = "CodexBar 设置"window.styleMask = [.titled, .closable, .miniaturizable]window.contentMinSize = Metrics.minimumContentSizediff --git a/CodexBar/Controllers/StatusItemController.swift b/CodexBar/Controllers/StatusItemController.swiftindex f43610a..5bc1bd5 100644--- a/CodexBar/Controllers/StatusItemController.swift+++ b/CodexBar/Controllers/StatusItemController.swift@@ -64,6 +64,7 @@ private final class StatusItemController: NSObject {private var cancellables = Set<AnyCancellable>()private var isShowingErrorImage: Bool?private var registeredHotKeyShortcut: GlobalHotKeyShortcut?+ private var auxiliaryWindowFocusRestoreTask: Task<Void, Never>?private static let normalImage = makeStatusImage("person.fill.checkmark")private static let errorImage = makeStatusImage("person.fill.xmark")@@ -106,6 +107,8 @@ private final class StatusItemController: NSObject {func uninstall() {closePopover(animated: false)+ auxiliaryWindowFocusRestoreTask?.cancel()+ setAuxiliaryWindowKeyFocus(true)globalHotKeyController.uninstall()cancellables.removeAll()NSStatusBar.system.removeStatusItem(statusItem)@@ -356,13 +359,16 @@ private final class StatusItemController: NSObject {}guard animated else {+ suspendAuxiliaryWindowKeyFocus()finishPopoverClose(hidesDetailPanel: false)return}+ suspendAuxiliaryWindowKeyFocus()popoverState = .closinglet didStartFadeOut = popoverFadeCoordinator.fadeOut(duration: Metrics.fadeOutDuration) { [weak self] inself?.popoverState = .hidden+ self?.scheduleAuxiliaryWindowKeyFocusRestore()}if !didStartFadeOut {@@ -384,6 +390,31 @@ private final class StatusItemController: NSObject {popoverVisibility.isVisible = falsepopoverFadeCoordinator.resetAlpha()popoverState = .hidden+ scheduleAuxiliaryWindowKeyFocusRestore()+ }++ private func suspendAuxiliaryWindowKeyFocus() {+ auxiliaryWindowFocusRestoreTask?.cancel()+ auxiliaryWindowFocusRestoreTask = nil+ setAuxiliaryWindowKeyFocus(false)+ }++ private func scheduleAuxiliaryWindowKeyFocusRestore() {+ auxiliaryWindowFocusRestoreTask?.cancel()+ auxiliaryWindowFocusRestoreTask = Task { @MainActor [weak self] in+ try? await Task.sleep(for: .milliseconds(Metrics.auxiliaryWindowKeyFocusRestoreDelayMilliseconds))+ guard let self, !Task.isCancelled else {+ return+ }++ self.setAuxiliaryWindowKeyFocus(true)+ self.auxiliaryWindowFocusRestoreTask = nil+ }+ }++ private func setAuxiliaryWindowKeyFocus(_ allowsKeyFocus: Bool) {+ settingsWindowController.setAllowsKeyFocus(allowsKeyFocus)+ logWindowController.setAllowsKeyFocus(allowsKeyFocus)}private func scheduleDeferredRefresh() {@@ -423,6 +454,7 @@ private final class StatusItemController: NSObject {private enum Metrics {static let fadeInDuration: TimeInterval = 0.24static let fadeOutDuration: TimeInterval = 0.18+ static let auxiliaryWindowKeyFocusRestoreDelayMilliseconds: UInt64 = 120}private enum PopoverState {diff --git a/appcast.xml b/appcast.xmlindex 63bd8dd..f24b40c 100644--- a/appcast.xml+++ b/appcast.xml@@ -7,6 +7,15 @@<link>https://codexbar.zabrian.app/appcast.xml</link><description>CodexBar appcast feed</description><language>zh-CN</language>+ <item>+ <title>CodexBar.app 2.4.4</title>+ <sparkle:version>20</sparkle:version>+ <sparkle:shortVersionString>2.4.4</sparkle:shortVersionString>+ <sparkle:minimumSystemVersion>15.0</sparkle:minimumSystemVersion>+ <sparkle:releaseNotesLink>https://codexbar.zabrian.app/notes#2.4.4</sparkle:releaseNotesLink>+ <pubDate>Tue, 23 Jun 2026 00:21:01 +0800</pubDate>+ <enclosure url="https://codexbar.zabrian.app/download/CodexBar-v2.4.4.dmg" sparkle:edSignature="86Arq3i4v0VziTt0/t7g6vLjiLNMA4NpT39mp1E4gA+s+u5Md6MDITfZGlDUeCGBskLhNofYoHGn1h/a/UJpDg==" length="3023619" type="application/octet-stream"/>+ </item><item><title>CodexBar.app 2.4.3</title><sparkle:version>19</sparkle:version>@@ -43,15 +52,6 @@<pubDate>Sun, 21 Jun 2026 22:32:31 +0800</pubDate><enclosure url="https://codexbar.zabrian.app/download/CodexBar-v2.4.0.dmg" sparkle:edSignature="h375ImnKqMc1M+q26ouBl/wlEMoaoMC2vSBHqFEIu106ShDdr2UaKF/6i9ms10qiItyNVDjspv6bQFVIlJ0qBA==" length="2887904" type="application/octet-stream"/></item>- <item>- <title>CodexBar.app 2.3.2</title>- <sparkle:version>15</sparkle:version>- <sparkle:shortVersionString>2.3.2</sparkle:shortVersionString>- <sparkle:minimumSystemVersion>15.0</sparkle:minimumSystemVersion>- <sparkle:releaseNotesLink>https://codexbar.zabrian.app/notes#2.3.2</sparkle:releaseNotesLink>- <pubDate>Sun, 21 Jun 2026 15:00:26 +0800</pubDate>- <enclosure url="https://codexbar.zabrian.app/download/CodexBar-v2.3.2.dmg" sparkle:edSignature="bfK4ho9NjcsCywJjT7aZltj6WDdZH3i4dvygfW2QL2+K+dO16OhsFWwTacV5MXPYDEpcCWSWZtWknZngv0p5Ag==" length="2850099" type="application/octet-stream"/>- </item><item><title>CodexBar.app 2.3.0</title><sparkle:version>13</sparkle:version>