Skip to content

CodexBar 是一个 macOS 菜单栏应用,用于查看本机 Codex 账号状态、额度、Token 用量、详细统计信息

fix: 修复设置窗口首次打开高度

Bob5fab24ee90a8
diff --git a/CLAUDE.md b/CLAUDE.md
index f768680..126621e 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -326,6 +326,7 @@ Hook 子进程按天写入 `~/Library/Application Support/CodexBar/HookEvents/ev
- 主面板的账户、任务中心、额度、Token 用量和底部状态由 `MainPanelSettings.layout` 统一保存顺序与显隐,模型始终保留至少一个区域;Hook 关闭时 `StatusItemController` 调用 `updateHookEnabled(_:)` 持久化关闭任务中心,任务中心原本是唯一可见区域时同步开启账户;设置面板只禁用任务中心开关,不能连带禁用拖拽手柄
- 主面板布局排序由手柄上的自定义 `DragGesture` 驱动,悬浮副本跟手移动,其他行按预览顺序实时让位,松手后才通过 `setSectionOrder(_:)` 保存最终顺序;不要改回只在落点命中后换位的 `.draggable` 和 `.dropDestination`
- `SettingsWindowController` 持有窗口组唯一的 `UndoManager`,设置主窗口和四个可聚焦子面板必须共享这一撤销栈,保证焦点切换后 `⌘Z` 与 `⌘⇧Z` 仍然有效;Hook 自动联动不注册为用户操作
+- 设置窗口高度跟随当前 tab 的完整内容,只在内容超过屏幕可见高度时允许滚动;首次构造时 SwiftUI 可能早于 `HostingWindowController.window` 赋值上报高度,`SettingsWindowController` 必须缓存最近测量并在窗口就绪后应用,不能用初始高度或延迟掩盖
- 设置窗口(通用/高级/关于三页)和日志窗口复用 `HostingWindowController` 的行为,可以成为 key window,但不应成为 main window
- 视觉风格统一走 `Views/Shared/LiquidGlassStyle.swift` 这一套,避免引入与系统菜单栏工具不一致的重装饰 UI
diff --git a/CodexBar/Controllers/SettingsWindowController.swift b/CodexBar/Controllers/SettingsWindowController.swift
index c7dbc2c..a8025c8 100644
--- a/CodexBar/Controllers/SettingsWindowController.swift
+++ b/CodexBar/Controllers/SettingsWindowController.swift
@@ -22,6 +22,8 @@ final class SettingsWindowController: HostingWindowController {
private let mainPanelUndoManager = UndoManager()
/// 只在真的要展开时构造: hosting controller 与动态面板订阅会常驻到 App 结束, 而用户可能一次子面板都没开过
private var optionsPanelControllers: [SettingsOptionsPanel: SettingsOptionsPanelController] = [:]
+ /// 首次构造窗口时 SwiftUI 可能先于 window 赋值上报高度 因此必须保留最近一次测量
+ private var preferredContentHeight: CGFloat?
init(
viewModel: CodexStatusViewModel,
@@ -98,7 +100,9 @@ final class SettingsWindowController: HostingWindowController {
}
override func prepareForDisplay(_ window: NSWindow) {
- window.setContentSize(clampedContentSize(window.contentLayoutRect.size, for: window))
+ var targetContentSize = window.contentLayoutRect.size
+ targetContentSize.height = preferredContentHeight ?? targetContentSize.height
+ window.setContentSize(clampedContentSize(targetContentSize, for: window))
positionForTabResizing(window)
}
@@ -106,7 +110,8 @@ final class SettingsWindowController: HostingWindowController {
static let minimumContentSize = NSSize(width: 420, height: 240)
static let initialContentSize = NSSize(width: 430, height: 270)
static let maximumFallbackContentSize = NSSize(width: 560, height: 720)
- static let maximumPreferredContentHeight: CGFloat = 500
+ /// 只用于首次定位的稳定顶边基准 不限制页面自适应高度
+ static let topEdgeReferenceContentHeight: CGFloat = 500
static let screenInset: CGFloat = 80
}
@@ -261,18 +266,18 @@ final class SettingsWindowController: HostingWindowController {
}
private func resizeContentHeight(_ height: CGFloat) {
+ guard height.isFinite, height > 0 else {
+ return
+ }
+
+ preferredContentHeight = height
guard let window else {
return
}
- let currentContentSize = window.contentLayoutRect.size
- let targetContentSize = clampedContentSize(
- NSSize(
- width: currentContentSize.width,
- height: min(height, Metrics.maximumPreferredContentHeight)
- ),
- for: window
- )
+ var targetContentSize = window.contentLayoutRect.size
+ targetContentSize.height = height
+ targetContentSize = clampedContentSize(targetContentSize, for: window)
let targetFrameHeight = window.frameRect(
forContentRect: NSRect(origin: .zero, size: targetContentSize)
).height
@@ -295,16 +300,16 @@ final class SettingsWindowController: HostingWindowController {
}
let visibleFrame = screen.visibleFrame
- let maximumContentHeight = min(
+ let referenceContentHeight = min(
maximumContentSize(for: window).height,
- Metrics.maximumPreferredContentHeight
+ Metrics.topEdgeReferenceContentHeight
)
let maximumFrameHeight = window.frameRect(
forContentRect: NSRect(
origin: .zero,
size: NSSize(
width: window.contentLayoutRect.width,
- height: maximumContentHeight
+ height: referenceContentHeight
)
)
).height
@@ -344,10 +349,9 @@ final class SettingsWindowController: HostingWindowController {
minimum: Metrics.minimumContentSize.width,
maximum: Metrics.maximumFallbackContentSize.width
),
- height: clampedContentDimension(
- screen.visibleFrame.height - Metrics.screenInset,
- minimum: Metrics.minimumContentSize.height,
- maximum: Metrics.maximumFallbackContentSize.height
+ height: max(
+ Metrics.minimumContentSize.height,
+ screen.visibleFrame.height - Metrics.screenInset
)
)
}
diff --git a/Config/Version.xcconfig b/Config/Version.xcconfig
index 081151c..7909287 100644
--- a/Config/Version.xcconfig
+++ b/Config/Version.xcconfig
@@ -1,2 +1,2 @@
-MARKETING_VERSION = 3.6.5
-CURRENT_PROJECT_VERSION = 72
+MARKETING_VERSION = 3.6.6
+CURRENT_PROJECT_VERSION = 73
diff --git a/Docs/DeveloperGuide/ui-and-lifecycle.md b/Docs/DeveloperGuide/ui-and-lifecycle.md
index a3cf4da..1ca55b4 100644
--- a/Docs/DeveloperGuide/ui-and-lifecycle.md
+++ b/Docs/DeveloperGuide/ui-and-lifecycle.md
@@ -214,7 +214,9 @@ hover 类型的热力图面板在打开其他面板前可以渐隐,点击类
- 优先在 status item 所在屏幕居中,再退到 window screen 或 main screen
- miniaturized 窗口先 deminiaturize 再激活
-设置窗口的高度随当前 tab 内容变化,但固定上边缘并限制到屏幕 visible frame。固定上边缘可以减少切换 tab 时整窗上下漂移,让标题栏保持稳定视觉锚点。
+设置窗口的高度随当前 tab 的完整内容变化,但固定上边缘并限制到屏幕 visible frame。内容未超过屏幕限制时,窗口应完整容纳当前页面且不产生滚动条;只有内容物理上放不进可见区域时,`ScrollView` 才作为安全降级。固定上边缘可以减少切换 tab 时整窗上下漂移,让标题栏保持稳定视觉锚点。
+
+首次构造窗口时,SwiftUI 可能在 `HostingWindowController` 保存 `window` 之前就上报页面高度。`SettingsWindowController` 会先缓存最近一次有效测量,并在窗口就绪后应用;否则唯一一次高度回调会被丢弃,窗口停留在初始尺寸,直到切换 tab 再次触发测量。
主面板布局、通知、自动重置和防睡眠的二级设置面板按需创建。控制器一旦创建就会长期持有内容及必要的高度变化订阅,如果 App 启动时预建所有面板,从未使用的 UI 也会一直参与更新。
@@ -317,6 +319,7 @@ app-server 状态默认每 60 秒刷新。面板打开时会安排约 160 ms 的
- 全局快捷键在状态栏锚点有效和无效场景都能打开面板
- 从通知点击激活 App 并打开面板
- 设置窗口首次打开、关闭和再次打开时焦点正确
+- 冷启动后首次打开设置时通用页直接使用完整内容高度;切换三个 tab 时窗口高度自适应,屏幕空间充足时均不显示滚动条
- 主面板布局、通知、自动重置和防睡眠子面板互斥,顶边对齐对应设置行,内容变化后高度正确
- 设置子面板展开时从菜单栏打开主面板,主面板保持打开,设置子面板收起且不把焦点抢回设置窗口
- 主面板区域拖动时悬浮行跟随指针,跨过半行后其他行实时让位,松手后平滑落位并只保存最终顺序;拖拽和显隐操作可以通过 `⌘Z` 逐步撤销并通过 `⌘⇧Z` 重做,焦点在设置主窗口或任一设置子面板时均有效;重启后保持配置,最后一个可见区域无法关闭;Hook 关闭时任务中心自动关闭、开关置灰但仍可拖动,任务中心为唯一可见区域时账户自动开启,自动联动不进入用户撤销历史
diff --git a/Docs/en/DeveloperGuide/ui-and-lifecycle.md b/Docs/en/DeveloperGuide/ui-and-lifecycle.md
index 20adf63..53b7ef6 100644
--- a/Docs/en/DeveloperGuide/ui-and-lifecycle.md
+++ b/Docs/en/DeveloperGuide/ui-and-lifecycle.md
@@ -214,7 +214,9 @@ Context-menu actions wait until menu tracking finishes before running, avoiding
- Placement prefers centering on the status item's screen, then falls back to the window screen or main screen
- A minimized window is deminiaturized before activation
-Settings-window height follows the current tab while pinning the top edge and constraining the window to the visible screen frame. The pinned top prevents the entire window from drifting vertically between tabs and keeps the title bar as a stable visual anchor.
+Settings-window height follows the complete content of the current tab while pinning the top edge and constraining the window to the visible screen frame. When the content fits within that screen limit, the window must contain the entire page without a scrollbar; `ScrollView` is only a safety fallback when the content physically cannot fit in the visible area. The pinned top prevents the entire window from drifting vertically between tabs and keeps the title bar as a stable visual anchor.
+
+During initial construction, SwiftUI may report the page height before `HostingWindowController` stores `window`. `SettingsWindowController` caches the latest valid measurement and applies it once the window is ready. Otherwise, the only height callback can be discarded, leaving the window at its initial size until a tab switch triggers another measurement.
Secondary panels for main-panel layout, notifications, Automatic Reset, and sleep prevention are created on demand. Once created, a controller retains its content and any required content-height subscriptions for its lifetime. Prebuilding every panel at app launch would keep unused UI participating in updates.
@@ -317,6 +319,7 @@ Release scripts require Developer ID, signing, and notarization credentials and
- The global shortcut opens the panel with both valid and invalid status-bar anchors
- Clicking a notification activates the app and opens the panel
- Focus is correct when opening Settings for the first time, closing it, and reopening it
+- On the first Settings open after a cold launch, General immediately uses its full content height; switching among all three tabs adapts the window height, with no scrollbar when screen space is sufficient
- Main Panel Layout, Notification, Automatic Reset, and sleep-prevention child panels remain mutually exclusive, align their top edges with their setting rows, and resize correctly when content changes
- With a settings child panel open, opening the main panel from the menu bar keeps the main panel open, closes the settings child panel, and does not steal focus back to Settings
- While reordering the main panel, the floating row follows the pointer, other rows make room after the drag crosses half a row, and release settles smoothly while persisting only the final order; reordering and visibility changes can be undone step by step with `Command-Z` and redone with `Command-Shift-Z` while either the Settings window or any settings child panel has focus; the result persists across relaunches; the last visible section cannot be hidden; disabling Hook turns Task Center off and disables its switch without blocking drag, enables Account if Task Center was the only visible section, and does not enter automatic Hook changes into user undo history
diff --git a/appcast.xml b/appcast.xml
index 5cfdd58..dd27e92 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 3.6.6</title>
+ <sparkle:version>73</sparkle:version>
+ <sparkle:shortVersionString>3.6.6</sparkle:shortVersionString>
+ <sparkle:minimumSystemVersion>15.0</sparkle:minimumSystemVersion>
+ <sparkle:releaseNotesLink>https://codexbar.zabrian.app/notes#3.6.6</sparkle:releaseNotesLink>
+ <pubDate>Sun, 23 Aug 2026 16:36:33 +0800</pubDate>
+ <enclosure url="https://codexbar.zabrian.app/download/CodexBar-v3.6.6.dmg" sparkle:edSignature="ot+67YOUAs+3NtNFDKxi1obrsVnbQtaBLFs9S+UVqlaUtXRxDOq0hWsghVo/CeK81PQk7hd9QPiUV+/q0XypCw==" length="7165228" type="application/octet-stream"/>
+ </item>
<item>
<title>CodexBar.app 3.6.5</title>
<sparkle:version>72</sparkle:version>