Skip to content

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

feat: 支持自定义主面板布局

Bob05c16f3735e7
diff --git a/CLAUDE.md b/CLAUDE.md
index 25abeeb..f768680 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -303,26 +303,29 @@ Hook 子进程按天写入 `~/Library/Application Support/CodexBar/HookEvents/ev
- 菜单栏按钮左键切换主面板;右键或 Control+点击打开上下文菜单;`⌘,` 打开自定义设置窗口,菜单面板打开时 `⌘L` 打开日志窗口;默认全局快捷键 `⌘⇧W` 由 `GlobalHotKeySettings` 与 `GlobalHotKeyController` 管理
- 主面板是锚定 status item 的 `NSPopover` 弹窗,锚点不可信时回退到 `FallbackPanelController` 提供的屏幕顶部居中 `NSPanel` 面板,处理快捷键、屏幕选择和焦点时要保留这两个分支
- 关闭逻辑统一由 `MenuSurfaceDismissMonitor` 管理,淡出由 `MenuSurfaceFadeCoordinator` 负责
-- 侧边面板都是 borderless nonactivating child panel,热力图详情、重置次数和任务中心挂在主面板上,通知、自动重置和防睡眠选项挂在设置窗口上
+- 主面板的热力图详情、重置次数和任务中心使用 `borderless nonactivating child panel`;设置窗口的主面板布局、通知、自动重置和防睡眠选项使用可获得键盘焦点的 `borderless child panel`
- 设置窗口的子面板占同一位置,展开一个必须先 `hide(immediate: true)` 收掉其余的;动作走 `SettingsOptionsPanelAction` 并带上目标 `SettingsOptionsPanel`,互斥与 `closeAll` 都只写在 `SettingsWindowController.handleOptionsAction` 一处,新增面板不会漏配对
-- 面板控制器只在首次展开时构造,收起动作走 `existingOptionsPanelController` 而不触发构造:它一建就挂上内容变化订阅并常驻到 App 结束,而用户可能一次子面板都没开过
-- 三个设置子面板的顶边对齐各自主开关行,anchor 由设置页的 `ScreenFrameProvider` 随展开动作传出,定位走 `SidePanelSupport.anchoredPosition` 而不是宿主底边
+- 面板控制器只在首次展开时构造,收起动作走 `existingOptionsPanelController` 而不触发构造:`NSHostingController` 与动态面板订阅会常驻到 App 结束,而用户可能一次子面板都没开过
+- 四个设置子面板的顶边对齐各自设置行,anchor 由设置页的 `ScreenFrameProvider` 随展开动作传出,定位走 `SidePanelSupport.anchoredPosition` 而不是宿主底边
- 设置窗口的子面板要传 `clampsToSurfaceBottom: false` 让底边可以探出窗口,否则放不下时会把整个面板上推而错开主开关行;主面板那三个面板走默认的 `true`
- 通知和防睡眠面板的高度会动态变化,前者随音效行增删,后者随 `hasBattery` 增删低电量那一行;自动重置面板只有固定的一行;resize 时要固定顶边向下生长,直接改 size 会保持底边不动而把顶边顶离主开关行
-- 内容变化订阅要保持最小:通知面板订 `notificationSettings` 与 `codexHookSettings` 的 `objectWillChange`,再加 `autoResetSettings.$isEnabled`、`KeepAliveController.$isLowBatteryProtectionEnabled` 与 `$isMaximumDurationEnabled`;自动重置面板只订 `autoResetSettings.objectWillChange`;防睡眠面板只订 `$hasBattery`;订整个防睡眠控制器会让任务每起停一次都白排一轮 resize
+- 内容变化订阅要保持最小:主面板布局固定 5 行、自动重置面板固定 1 行,均不订高度变化;通知面板订 `notificationSettings` 与 `codexHookSettings` 的 `objectWillChange`,再加 `autoResetSettings.$isEnabled`、`KeepAliveController.$isLowBatteryProtectionEnabled` 与 `$isMaximumDurationEnabled`;防睡眠面板只订 `$hasBattery`;订整个防睡眠控制器会让任务每起停一次都白排一轮 resize
- 置灰也会改高度:带音效的行置灰时音效子行跟着收起,所以每个置灰依赖都要有一个对应的订阅源
- 增删行或改行的显示条件时要同步补上对应的订阅源,漏一项会让面板裁掉底部或留下空白
- resize 的竖向夹紧走 `SidePanelSupport.clampedVertically`,与初次展开的 `position` 同一条规则,否则放不下时两边会把面板推向相反的边
-- 子面板入口只在开关开着且依赖就绪时出现,通知看 `NotificationSettings.canShowOptions`,自动重置要求 `AutoResetSettings.isEnabled` 且 `KeepAliveController.helperStatus == .enabled`,防睡眠看 `KeepAliveController.canShowOptions`;这些值只控制入口显隐,不回写用户保存的开关
+- 主面板布局入口始终可用;其他子面板入口只在开关开着且依赖就绪时出现,通知看 `NotificationSettings.canShowOptions`,自动重置要求 `AutoResetSettings.isEnabled` 且 `KeepAliveController.helperStatus == .enabled`,防睡眠看 `KeepAliveController.canShowOptions`;这些值只控制入口显隐,不回写用户保存的开关
- 自动重置或防睡眠的子面板入口条件失效时,`AppSettingsView` 会发送对应的 `close` 动作收起已展开面板;关闭开关时对应设置行不显示状态说明
-- 三个设置子面板都只由滑杆按钮展开,动作只有 `toggle` 与 `close` 两种,开启主开关不自动弹出
+- 四个设置子面板都只由滑杆按钮展开;单个面板的展开和条件失效收起分别使用 `toggle` 与 `close`,切换分页时使用 `closeAll`,开启主开关不自动弹出
+- 设置子面板收起时,`SidePanelSupport.orderOut` 只有在被关闭面板仍是 key window 时才把焦点还给父窗口;如果焦点已经转移到主面板或其他窗口,不得主动抢回
- 侧边面板公共能力集中在 `Controllers/SidePanelSupport.swift` 里,含 `SidePanelDrawerPresenter`、`SidePanelContentHost`、`SidePanelDrawerAnimator`、panel 工厂和定位夹紧;挂在主面板上的那三个面板优先复用 `SidePanelDrawerPresenter` 这一层,不要另起一套
-- 设置窗口的子面板直接复用 `Controllers/SettingsOptionsPanelController.swift`,它在 presenter 之上补齐了装配、两套关闭观察者、顶边对齐定位和高度重算;新增设置子面板只要给它内容工厂与内容变化来源,不要再写一层壳
-- 三个设置子面板的行高与间距从 `SettingsOptionsPanelMetrics` 取,下拉控件共用 `SettingsOptionsPicker`,只有面板宽度和 picker 宽度各自定义,这样三个面板看起来才是同一套控件
+- 设置窗口的子面板直接复用 `Controllers/SettingsOptionsPanelController.swift`,它在 presenter 之上补齐了装配、两套关闭观察者、顶边对齐定位和高度重算;新增设置子面板只要给它内容工厂,动态高度面板再提供内容变化来源,不要另写一层壳
+- 设置子面板的公共内边距、间距与外观度量从 `SettingsOptionsPanelMetrics` 取;通知、自动重置和防睡眠面板的下拉控件共用 `SettingsOptionsPicker`;主面板布局使用独立的 28 点拖拽行高且不使用下拉控件
- 设置子面板的内容工厂必须走 `SettingsOptionsPanelController.makeContentController(_:rebuiltBy:)`,否则首次展开时原生 Switch 只剩一条空轨道;重建信号由它接在内容外面,内容视图不必知道 `SidePanelEntryCue`
- 原因是 thumb 由 `WindowPortal` 投射而不是画在开关上,面板首次布局那一轮 portal 建不起来,而且不会自愈,只有一次内容重建才补得上;第二次展开正常是因为 hosting controller 常驻,复用了已经建好的那份
- 不要再用 `@_optimize(none)` 规避这个漏绘:它当年在通知子面板管用只是因为逼着 body 重算时判定那些行变过,与优化等级无关,换个写法就失效;`SidePanelSupport` 里剩下那一处标注规避的是编译器崩溃,与此无关
-- 主面板任务中心的显隐由 `MainPanelSettings.showsTaskCenter` 与 `codexHookSettings.isEnabled` 共同决定,Hook 未开启时设置页那一行显示为关闭并置灰,不回写用户保存的开关值
+- 主面板的账户、任务中心、额度、Token 用量和底部状态由 `MainPanelSettings.layout` 统一保存顺序与显隐,模型始终保留至少一个区域;Hook 关闭时 `StatusItemController` 调用 `updateHookEnabled(_:)` 持久化关闭任务中心,任务中心原本是唯一可见区域时同步开启账户;设置面板只禁用任务中心开关,不能连带禁用拖拽手柄
+- 主面板布局排序由手柄上的自定义 `DragGesture` 驱动,悬浮副本跟手移动,其他行按预览顺序实时让位,松手后才通过 `setSectionOrder(_:)` 保存最终顺序;不要改回只在落点命中后换位的 `.draggable` 和 `.dropDestination`
+- `SettingsWindowController` 持有窗口组唯一的 `UndoManager`,设置主窗口和四个可聚焦子面板必须共享这一撤销栈,保证焦点切换后 `⌘Z` 与 `⌘⇧Z` 仍然有效;Hook 自动联动不注册为用户操作
- 设置窗口(通用/高级/关于三页)和日志窗口复用 `HostingWindowController` 的行为,可以成为 key window,但不应成为 main window
- 视觉风格统一走 `Views/Shared/LiquidGlassStyle.swift` 这一套,避免引入与系统菜单栏工具不一致的重装饰 UI
diff --git a/CodexBar/Controllers/CodexBarAppDelegate.swift b/CodexBar/Controllers/CodexBarAppDelegate.swift
index 3ad10a1..55f9981 100644
--- a/CodexBar/Controllers/CodexBarAppDelegate.swift
+++ b/CodexBar/Controllers/CodexBarAppDelegate.swift
@@ -148,7 +148,7 @@ final class CodexBarAppDelegate: NSObject, NSApplicationDelegate {
"autoReset=\(autoResetSettings.isEnabled ? 1 : 0)",
"autoResetLeadTimeSeconds=\(autoResetSettings.leadTime.rawValue)",
"menuBarQuota=\(menuBarQuotaSettings.selection.rawValue)",
- "taskCenter=\(mainPanelSettings.showsTaskCenter ? 1 : 0)",
+ "mainPanel=\(mainPanelSettings.layout.visibleSections.map(\.rawValue).joined(separator: ","))",
"hotKey=\(globalHotKeySettings.shortcut == nil ? 0 : 1)"
)
AppLog.app.notice("App 已启动: \(state, privacy: .public)")
diff --git a/CodexBar/Controllers/HostingWindowController.swift b/CodexBar/Controllers/HostingWindowController.swift
index bbf3c3d..d6840a4 100644
--- a/CodexBar/Controllers/HostingWindowController.swift
+++ b/CodexBar/Controllers/HostingWindowController.swift
@@ -4,6 +4,31 @@ import AppKit
@MainActor
final class AuxiliaryHostingWindow: NSWindow {
var allowsKeyFocus = true
+ /// 设置窗口与可获得焦点的子面板共享撤销栈, 避免焦点切换后 Command-Z 失效
+ var sharedUndoManager: UndoManager?
+
+ override var undoManager: UndoManager? {
+ sharedUndoManager ?? super.undoManager
+ }
+
+ @IBAction func undo(_: Any?) {
+ undoManager?.undo()
+ }
+
+ @IBAction func redo(_: Any?) {
+ undoManager?.redo()
+ }
+
+ override func validateUserInterfaceItem(_ item: any NSValidatedUserInterfaceItem) -> Bool {
+ switch item.action {
+ case #selector(undo(_:)):
+ undoManager?.canUndo == true
+ case #selector(redo(_:)):
+ undoManager?.canRedo == true
+ default:
+ super.validateUserInterfaceItem(item)
+ }
+ }
override func makeKey() {
guard allowsKeyFocus else {
diff --git a/CodexBar/Controllers/SettingsOptionsPanelController.swift b/CodexBar/Controllers/SettingsOptionsPanelController.swift
index 4458be0..11946e2 100644
--- a/CodexBar/Controllers/SettingsOptionsPanelController.swift
+++ b/CodexBar/Controllers/SettingsOptionsPanelController.swift
@@ -4,6 +4,7 @@ import SwiftUI
/// 设置窗口右侧的子选项面板, 同一时刻只展开一个
enum SettingsOptionsPanel: CaseIterable, Hashable {
+ case mainPanel
case notification
case autoReset
case keepAlive
@@ -41,7 +42,7 @@ private struct SidePanelEntryRebuildHost<Content: View>: View {
}
/// 设置窗口右侧子选项面板的公共装配
-/// 各子面板只差内容视图和高度变化的来源, 定位 关闭 高度重算这套脚手架全在这里
+/// 各子面板只差内容视图, 动态高度面板再提供变化来源, 定位 关闭 高度重算这套脚手架全在这里
/// 与重置次数面板不同: 内容是交互控件, 用常驻 hosting controller + ObservableObject 驱动更新, 不替换 rootView
@MainActor
final class SettingsOptionsPanelController {
@@ -74,20 +75,21 @@ final class SettingsOptionsPanelController {
initialPanelSize: CGSize,
willShow: (() -> Void)? = nil,
contentControllerProvider: @escaping (SidePanelEntryCue) -> NSViewController,
- contentChanges: AnyPublisher<Void, Never>
+ contentChanges: AnyPublisher<Void, Never>? = nil
) {
self.animationKey = animationKey
self.initialPanelSize = initialPanelSize
self.willShow = willShow
self.contentControllerProvider = contentControllerProvider
- // 内容行数随开关增删, 高度得跟着重算
- // 订阅整个 ObservableObject 而不是逐个 @Published: 那种列表漏一项就会让面板裁掉底部或留下空白
- // 而多余的触发在面板收着时被 scheduleResize 的守卫挡掉, 展开时也只是一次尺寸相同的空转
- contentChanges
- .sink { [weak self] in
- self?.scheduleResize()
- }
- .store(in: &cancellables)
+ // 只有内容行数会动态增删的面板才传变化源
+ // 面板收着时由 scheduleResize 的守卫过滤变化
+ if let contentChanges {
+ contentChanges
+ .sink { [weak self] in
+ self?.scheduleResize()
+ }
+ .store(in: &cancellables)
+ }
}
/// sizingOptions 必须是 preferredContentSize: 面板的高度重算靠的就是它提交的 fitting size
@@ -168,6 +170,7 @@ final class SettingsOptionsPanelController {
// 只有刚构造出来的那一次需要重建, hosting controller 之后常驻, portal 已经建好
let needsEntryRebuild = panel == nil
let panel = ensurePanel()
+ (panel as? KeyableBorderlessPanel)?.sharedUndoManager = window.undoManager
// 这里不必先布局: 下面 measuredPanelSize 走的 validFittingSize 第一句就是 layoutSubtreeIfNeeded
// 而中间两句只碰设置窗口那棵树, 不会把面板弄脏
let windowSurfaceFrame = SidePanelSupport.contentScreenFrame(for: contentView, in: window) ?? window.frame
diff --git a/CodexBar/Controllers/SettingsWindowController.swift b/CodexBar/Controllers/SettingsWindowController.swift
index 658447b..c7dbc2c 100644
--- a/CodexBar/Controllers/SettingsWindowController.swift
+++ b/CodexBar/Controllers/SettingsWindowController.swift
@@ -19,7 +19,8 @@ final class SettingsWindowController: HostingWindowController {
private let keepAliveController: KeepAliveController
private let onSyncChanged: (Bool) -> Void
private let onRebuildWorkflowData: WorkflowSyncScheduler.RebuildHandler
- /// 只在真的要展开时构造: 控制器一建就挂上内容变化订阅并常驻到 App 结束, 而用户可能一次子面板都没开过
+ private let mainPanelUndoManager = UndoManager()
+ /// 只在真的要展开时构造: hosting controller 与动态面板订阅会常驻到 App 结束, 而用户可能一次子面板都没开过
private var optionsPanelControllers: [SettingsOptionsPanel: SettingsOptionsPanelController] = [:]
init(
@@ -88,6 +89,7 @@ final class SettingsWindowController: HostingWindowController {
hostingController.sizingOptions = []
let window = AuxiliaryHostingWindow(contentViewController: hostingController)
+ window.sharedUndoManager = mainPanelUndoManager
window.title = String(localized: "settings.window.title")
window.styleMask = [.titled, .closable, .miniaturizable]
window.contentMinSize = Metrics.minimumContentSize
@@ -143,6 +145,8 @@ final class SettingsWindowController: HostingWindowController {
_ panel: SettingsOptionsPanel
) -> SettingsOptionsPanelController {
switch panel {
+ case .mainPanel:
+ makeMainPanelOptionsPanelController()
case .notification:
SettingsOptionsPanelController(
animationKey: "CodexBar.notificationOptionsDrawerTransform",
@@ -190,9 +194,7 @@ final class SettingsWindowController: HostingWindowController {
),
rebuiltBy: entryCue
)
- },
- contentChanges: autoResetSettings.objectWillChange
- .eraseToAnyPublisher()
+ }
)
case .keepAlive:
SettingsOptionsPanelController(
@@ -215,6 +217,26 @@ final class SettingsWindowController: HostingWindowController {
}
}
+ private func makeMainPanelOptionsPanelController() -> SettingsOptionsPanelController {
+ SettingsOptionsPanelController(
+ animationKey: "CodexBar.mainPanelOptionsDrawerTransform",
+ initialPanelSize: MainPanelOptionsView.initialPanelSize,
+ willShow: { [mainPanelSettings] in
+ mainPanelSettings.refresh()
+ },
+ contentControllerProvider: { [mainPanelSettings, codexHookSettings, mainPanelUndoManager] entryCue in
+ SettingsOptionsPanelController.makeContentController(
+ MainPanelOptionsView(
+ settings: mainPanelSettings,
+ codexHookSettings: codexHookSettings,
+ undoManager: mainPanelUndoManager
+ ),
+ rebuiltBy: entryCue
+ )
+ }
+ )
+ }
+
/// 子面板占设置窗口右侧同一位置, 展开一个必须先收掉其余的
/// 收旧面板用 immediate, 否则滑回与滑出在同一处交叠
/// 互斥规则只写在这里, 再加一个面板也不会漏掉某一对
diff --git a/CodexBar/Controllers/SidePanelSupport.swift b/CodexBar/Controllers/SidePanelSupport.swift
index c7e8de6..5d4fa3b 100644
--- a/CodexBar/Controllers/SidePanelSupport.swift
+++ b/CodexBar/Controllers/SidePanelSupport.swift
@@ -17,6 +17,32 @@ final class NonactivatingSidePanel: NSPanel {
/// 可获得键盘焦点的无边框面板, 用于含交互控件的子面板和 fallback 面板
@MainActor
final class KeyableBorderlessPanel: NSPanel {
+ /// 设置子面板使用宿主窗口注入的撤销栈, 保持 responder chain 行为一致
+ var sharedUndoManager: UndoManager?
+
+ override var undoManager: UndoManager? {
+ sharedUndoManager ?? super.undoManager
+ }
+
+ @IBAction func undo(_: Any?) {
+ undoManager?.undo()
+ }
+
+ @IBAction func redo(_: Any?) {
+ undoManager?.redo()
+ }
+
+ override func validateUserInterfaceItem(_ item: any NSValidatedUserInterfaceItem) -> Bool {
+ switch item.action {
+ case #selector(undo(_:)):
+ undoManager?.canUndo == true
+ case #selector(redo(_:)):
+ undoManager?.canRedo == true
+ default:
+ super.validateUserInterfaceItem(item)
+ }
+ }
+
override var canBecomeKey: Bool {
true
}
@@ -146,9 +172,9 @@ final class SidePanelDrawerAnimator {
// MARK: - 展开与收起
-/// 重置次数; 通知子选项和并发任务中心三类"一次性展开"抽屉面板共用的显隐状态机
-/// 负责 generation 竞态防护; 入退场动画和 child window 挂载/卸载
-/// (热力图详情面板因带切边与延迟隐藏, 状态机不同, 不走这里)
+/// 重置次数 设置子选项和并发任务中心三类一次性展开抽屉面板共用的显隐状态机
+/// 负责 generation 竞态防护 入退场动画和 child window 挂载与卸载
+/// 热力图详情面板带切边与延迟隐藏 状态机不同 因此不走这里
@MainActor
final class SidePanelDrawerPresenter {
private let makesKey: Bool
@@ -475,9 +501,12 @@ enum SidePanelSupport {
static func orderOut(_ panel: NSPanel, menuSurfaceWindow: NSWindow?) {
let parentWindow = panel.parent ?? menuSurfaceWindow
+ let shouldRestoreParentKey = panel.isKeyWindow
panel.orderOut(nil)
parentWindow?.removeChildWindow(panel)
- restoreMenuSurfaceKeyWindow(parentWindow)
+ if shouldRestoreParentKey {
+ restoreMenuSurfaceKeyWindow(parentWindow)
+ }
}
static func restoreMenuSurfaceKeyWindow(_ menuSurfaceWindow: NSWindow?) {
diff --git a/CodexBar/Controllers/StatusItemController.swift b/CodexBar/Controllers/StatusItemController.swift
index aa592eb..6565cce 100644
--- a/CodexBar/Controllers/StatusItemController.swift
+++ b/CodexBar/Controllers/StatusItemController.swift
@@ -445,6 +445,7 @@ final class StatusItemController: NSObject, NSMenuDelegate {
observeViewModel()
observeWorkflowSyncState()
codexHookSettings.refresh()
+ observeMainPanelHookState()
viewModel.startAutoRefresh()
}
@@ -538,10 +539,10 @@ final class StatusItemController: NSObject, NSMenuDelegate {
let isTaskCenterVisible = Publishers.CombineLatest(
codexHookSettings.$isEnabled,
- mainPanelSettings.$showsTaskCenter
+ mainPanelSettings.$layout
)
- .map { isHookEnabled, showsTaskCenter in
- isHookEnabled && showsTaskCenter
+ .map { isHookEnabled, layout in
+ isHookEnabled && layout.isVisible(.activity)
}
.removeDuplicates()
@@ -598,10 +599,20 @@ final class StatusItemController: NSObject, NSMenuDelegate {
}
.store(in: &cancellables)
- mainPanelSettings.$showsTaskCenter
- .filter { !$0 }
- .sink { [weak self] _ in
- self?.activityCenterPanelController.hide(immediate: true)
+ mainPanelSettings.$layout
+ .sink { [weak self] layout in
+ guard let self else {
+ return
+ }
+ if !layout.isVisible(.activity) {
+ activityCenterPanelController.hide(immediate: true)
+ }
+ if !layout.isVisible(.quota) {
+ resetCreditsPanelController.hide(immediate: true)
+ }
+ if !layout.isVisible(.usage) {
+ heatmapDetailPanelController.hide(immediate: true)
+ }
}
.store(in: &cancellables)
}
@@ -635,6 +646,15 @@ final class StatusItemController: NSObject, NSMenuDelegate {
.store(in: &cancellables)
}
+ private func observeMainPanelHookState() {
+ codexHookSettings.$isEnabled
+ .removeDuplicates()
+ .sink { [weak self] isEnabled in
+ self?.mainPanelSettings.updateHookEnabled(isEnabled)
+ }
+ .store(in: &cancellables)
+ }
+
private func observeGlobalHotKeySettings() {
globalHotKeySettings.$shortcut
.removeDuplicates()
diff --git a/CodexBar/Resources/Localizable.xcstrings b/CodexBar/Resources/Localizable.xcstrings
index e41f109..5b8a1b7 100644
--- a/CodexBar/Resources/Localizable.xcstrings
+++ b/CodexBar/Resources/Localizable.xcstrings
@@ -3617,6 +3617,102 @@
}
}
},
+ "settings.main-panel.layout.title" : {
+ "localizations" : {
+ "en" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Main Panel Layout"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "主面板布局"
+ }
+ }
+ }
+ },
+ "settings.main-panel.section.account" : {
+ "localizations" : {
+ "en" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Account"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "账户"
+ }
+ }
+ }
+ },
+ "settings.main-panel.section.activity" : {
+ "localizations" : {
+ "en" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Tasks"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "任务"
+ }
+ }
+ }
+ },
+ "settings.main-panel.section.quota" : {
+ "localizations" : {
+ "en" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Quota"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "额度"
+ }
+ }
+ }
+ },
+ "settings.main-panel.section.status" : {
+ "localizations" : {
+ "en" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Status"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "状态"
+ }
+ }
+ }
+ },
+ "settings.main-panel.section.usage" : {
+ "localizations" : {
+ "en" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Usage"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "用量"
+ }
+ }
+ }
+ },
"settings.menu-bar-quota.title" : {
"localizations" : {
"en" : {
@@ -3985,22 +4081,6 @@
}
}
},
- "settings.task-center.show-in-menu" : {
- "localizations" : {
- "en" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Show Task Center in Menu"
- }
- },
- "zh-Hans" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "主面板任务中心"
- }
- }
- }
- },
"settings.window.title" : {
"localizations" : {
"en" : {
diff --git a/CodexBar/Services/Settings/MainPanelSettings.swift b/CodexBar/Services/Settings/MainPanelSettings.swift
index 342a19f..a918c80 100644
--- a/CodexBar/Services/Settings/MainPanelSettings.swift
+++ b/CodexBar/Services/Settings/MainPanelSettings.swift
@@ -2,44 +2,220 @@ import Combine
import Foundation
import os
-/// 主面板内容偏好
+nonisolated enum MainPanelSection: String, CaseIterable, Identifiable, Sendable {
+ case account
+ case activity
+ case quota
+ case usage
+ case status
+
+ var id: Self {
+ self
+ }
+}
+
+nonisolated struct MainPanelLayout: Equatable, Sendable {
+ let orderedSections: [MainPanelSection]
+ let hiddenSections: Set<MainPanelSection>
+
+ init(
+ orderedSections: [MainPanelSection],
+ hiddenSections: Set<MainPanelSection>
+ ) {
+ var seenSections = Set<MainPanelSection>()
+ var normalizedOrder = orderedSections.filter { seenSections.insert($0).inserted }
+ normalizedOrder.append(
+ contentsOf: MainPanelSection.allCases.filter { seenSections.insert($0).inserted }
+ )
+
+ var normalizedHiddenSections = hiddenSections
+ if normalizedHiddenSections.count == normalizedOrder.count,
+ let firstSection = normalizedOrder.first {
+ normalizedHiddenSections.remove(firstSection)
+ }
+
+ self.orderedSections = normalizedOrder
+ self.hiddenSections = normalizedHiddenSections
+ }
+
+ var visibleSections: [MainPanelSection] {
+ orderedSections.filter { !hiddenSections.contains($0) }
+ }
+
+ func isVisible(_ section: MainPanelSection) -> Bool {
+ !hiddenSections.contains(section)
+ }
+
+ func disablingActivitySection() -> MainPanelLayout {
+ var hiddenSections = hiddenSections
+ hiddenSections.insert(.activity)
+
+ if orderedSections.allSatisfy(hiddenSections.contains) {
+ hiddenSections.remove(.account)
+ }
+
+ return MainPanelLayout(
+ orderedSections: orderedSections,
+ hiddenSections: hiddenSections
+ )
+ }
+}
+
+/// 主面板区域顺序与显隐偏好
@MainActor
final class MainPanelSettings: ObservableObject {
- @Published private(set) var showsTaskCenter: Bool
+ @Published private(set) var layout: MainPanelLayout
private let defaults: UserDefaults
+ private var isHookEnabled: Bool?
init(defaults: UserDefaults = .standard) {
self.defaults = defaults
- showsTaskCenter = Self.loadShowsTaskCenter(from: defaults)
+ layout = Self.loadLayout(from: defaults)
}
func refresh() {
- let showsTaskCenter = Self.loadShowsTaskCenter(from: defaults)
- guard showsTaskCenter != self.showsTaskCenter else {
+ let loadedLayout = Self.loadLayout(from: defaults)
+ guard isHookEnabled == false else {
+ publish(loadedLayout)
+ return
+ }
+
+ let updatedLayout = loadedLayout.disablingActivitySection()
+ if updatedLayout == loadedLayout {
+ publish(updatedLayout)
+ } else {
+ saveAndPublish(updatedLayout)
+ }
+ }
+
+ func updateHookEnabled(_ isEnabled: Bool) {
+ isHookEnabled = isEnabled
+ guard !isEnabled else {
+ return
+ }
+
+ let updatedLayout = layout.disablingActivitySection()
+ guard updatedLayout != layout else {
+ return
+ }
+
+ AppLog.settings.notice("Hook 关闭已同步主面板任务中心")
+ saveAndPublish(updatedLayout)
+ }
+
+ func setSection(
+ _ section: MainPanelSection,
+ isVisible: Bool,
+ undoManager: UndoManager
+ ) {
+ guard section != .activity || !isVisible || isHookEnabled == true else {
+ return
+ }
+ guard layout.isVisible(section) != isVisible else {
+ return
+ }
+ guard isVisible || layout.visibleSections.count > 1 else {
return
}
- self.showsTaskCenter = showsTaskCenter
+ var hiddenSections = layout.hiddenSections
+ if isVisible {
+ hiddenSections.remove(section)
+ } else {
+ hiddenSections.insert(section)
+ }
+
+ AppLog.settings.notice(
+ "主面板区域显隐变更: section=\(section.rawValue, privacy: .public); visible=\(isVisible ? 1 : 0)"
+ )
+ applyUndoableLayout(
+ MainPanelLayout(
+ orderedSections: layout.orderedSections,
+ hiddenSections: hiddenSections
+ ),
+ undoManager: undoManager
+ )
}
- func setShowsTaskCenter(_ showsTaskCenter: Bool) {
- guard showsTaskCenter != self.showsTaskCenter else {
+ func setSectionOrder(
+ _ orderedSections: [MainPanelSection],
+ undoManager: UndoManager
+ ) {
+ let updatedLayout = MainPanelLayout(
+ orderedSections: orderedSections,
+ hiddenSections: layout.hiddenSections
+ )
+ guard updatedLayout != layout else {
return
}
- AppLog.settings.notice("主面板任务中心变更: enabled=\(showsTaskCenter ? 1 : 0)")
- defaults.set(showsTaskCenter, forKey: Self.showsTaskCenterKey)
- self.showsTaskCenter = showsTaskCenter
+ AppLog.settings.notice(
+ "主面板区域顺序变更: order=\(Self.orderLogValue(for: updatedLayout), privacy: .public)"
+ )
+ applyUndoableLayout(updatedLayout, undoManager: undoManager)
}
- private static func loadShowsTaskCenter(from defaults: UserDefaults) -> Bool {
- guard defaults.object(forKey: showsTaskCenterKey) != nil else {
- return true
+ private func applyUndoableLayout(
+ _ requestedLayout: MainPanelLayout,
+ undoManager: UndoManager
+ ) {
+ let updatedLayout = isHookEnabled == false
+ ? requestedLayout.disablingActivitySection()
+ : requestedLayout
+ guard updatedLayout != layout else {
+ return
}
- return defaults.bool(forKey: showsTaskCenterKey)
+ let previousLayout = layout
+ saveAndPublish(updatedLayout)
+ undoManager.registerUndo(withTarget: self) { [weak undoManager] settings in
+ guard let undoManager else {
+ return
+ }
+
+ settings.applyUndoableLayout(previousLayout, undoManager: undoManager)
+ }
+ undoManager.setActionName(String(localized: "settings.main-panel.layout.title"))
+ }
+
+ private func saveAndPublish(_ layout: MainPanelLayout) {
+ defaults.set(
+ layout.orderedSections.map(\.rawValue),
+ forKey: Self.sectionOrderKey
+ )
+ defaults.set(
+ layout.hiddenSections.map(\.rawValue).sorted(),
+ forKey: Self.hiddenSectionsKey
+ )
+ publish(layout)
+ }
+
+ private func publish(_ layout: MainPanelLayout) {
+ guard layout != self.layout else {
+ return
+ }
+
+ self.layout = layout
+ }
+
+ private static func loadLayout(from defaults: UserDefaults) -> MainPanelLayout {
+ let orderedSections = defaults.stringArray(forKey: sectionOrderKey)?
+ .compactMap(MainPanelSection.init(rawValue:)) ?? MainPanelSection.allCases
+ let hiddenSections = Set(
+ defaults.stringArray(forKey: hiddenSectionsKey)?
+ .compactMap(MainPanelSection.init(rawValue:)) ?? []
+ )
+ return MainPanelLayout(
+ orderedSections: orderedSections,
+ hiddenSections: hiddenSections
+ )
+ }
+
+ private static func orderLogValue(for layout: MainPanelLayout) -> String {
+ layout.orderedSections.map(\.rawValue).joined(separator: ",")
}
- private static let showsTaskCenterKey = "MainPanel.showsTaskCenter"
+ private static let sectionOrderKey = "MainPanel.sectionOrder"
+ private static let hiddenSectionsKey = "MainPanel.hiddenSections"
}
diff --git a/CodexBar/Views/Menu/CodexStatusMenuSections.swift b/CodexBar/Views/Menu/CodexStatusMenuSections.swift
index ed4e519..62c2a0b 100644
--- a/CodexBar/Views/Menu/CodexStatusMenuSections.swift
+++ b/CodexBar/Views/Menu/CodexStatusMenuSections.swift
@@ -16,6 +16,7 @@ struct AccountCard: View {
let plan: String?
let isRefreshing: Bool
let onRefresh: () -> Void
+ @Environment(\.colorScheme) private var colorScheme
@State private var isEmailBlurred = false
var body: some View {
@@ -47,7 +48,9 @@ struct AccountCard: View {
if let plan {
Text(plan.uppercased())
.font(.caption2.weight(.bold))
- .foregroundStyle(Self.planBadgeTint(for: plan))
+ .foregroundStyle(
+ Self.planBadgeTint(for: plan, colorScheme: colorScheme)
+ )
.lineLimit(1)
}
}
@@ -59,20 +62,26 @@ struct AccountCard: View {
}
}
- private static func planBadgeTint(for plan: String) -> Color {
+ private static func planBadgeTint(for plan: String, colorScheme: ColorScheme) -> Color {
let normalizedPlan = plan.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()
- return planTintRules.first { rule in
+ let rule = planTintRules.first { rule in
rule.keywords.contains { normalizedPlan.contains($0) }
- }?.tint ?? .cyan
+ }
+ let hex = if colorScheme == .dark {
+ rule?.colors.dark ?? 0x67E8F9
+ } else {
+ rule?.colors.light ?? 0x0E7490
+ }
+ return Color(hex: hex)
}
- private static let planTintRules: [(keywords: [String], tint: Color)] = [
- (["enterprise"], Color(hex: 0x15803D)),
- (["team", "business"], Color(hex: 0xD97706)),
- (["pro"], Color(hex: 0xC026D3)),
- (["plus"], Color(hex: 0x2563EB)),
- (["edu"], Color(hex: 0x0891B2)),
- (["free"], Color(hex: 0x64748B))
+ private static let planTintRules: [(keywords: [String], colors: (light: Int, dark: Int))] = [
+ (["enterprise"], (0x52677F, 0xA7AFBA)),
+ (["team", "business"], (0x147B82, 0x82B3B5)),
+ (["pro"], (0x147B82, 0x82B3B5)),
+ (["plus"], (0x256FA3, 0x89A9C2)),
+ (["edu"], (0x9B5F12, 0xC7A96B)),
+ (["free"], (0x167A5E, 0x7FB5A4))
]
}
diff --git a/CodexBar/Views/Menu/CodexStatusMenuView.swift b/CodexBar/Views/Menu/CodexStatusMenuView.swift
index 8c4f44d..57cb6c2 100644
--- a/CodexBar/Views/Menu/CodexStatusMenuView.swift
+++ b/CodexBar/Views/Menu/CodexStatusMenuView.swift
@@ -35,7 +35,7 @@ struct CodexStatusMenuView: View {
.liquidGlassSurface(cornerRadius: Metrics.surfaceCornerRadius, isOuterSurface: true)
.animation(Metrics.statusAnimation, value: viewModel.loadState)
.animation(Metrics.statusAnimation, value: codexHookSettings.isEnabled)
- .animation(Metrics.statusAnimation, value: mainPanelSettings.showsTaskCenter)
+ .animation(Metrics.statusAnimation, value: mainPanelSettings.layout)
.animation(Metrics.statusAnimation, value: syncSettings.isEnabled)
.animation(Metrics.statusAnimation, value: syncSettings.isSyncing)
.animation(Metrics.statusAnimation, value: syncSettings.hasSyncFailure)
@@ -52,6 +52,42 @@ private extension CodexStatusMenuView {
@ViewBuilder
var content: some View {
+ let visibleSections = mainPanelSettings.layout.visibleSections
+ let dataPlaceholderSection = dataPlaceholderSection(in: visibleSections)
+
+ ForEach(visibleSections) { section in
+ sectionView(section, dataPlaceholderSection: dataPlaceholderSection)
+ }
+
+ if !hasRenderableContent(
+ in: visibleSections,
+ dataPlaceholderSection: dataPlaceholderSection
+ ) {
+ EmptyDataPanel()
+ }
+ }
+
+ @ViewBuilder
+ func sectionView(
+ _ section: MainPanelSection,
+ dataPlaceholderSection: MainPanelSection?
+ ) -> some View {
+ switch section {
+ case .account:
+ accountSection
+ case .activity:
+ activitySection
+ case .quota:
+ quotaSection(dataPlaceholderSection: dataPlaceholderSection)
+ case .usage:
+ usageSection(dataPlaceholderSection: dataPlaceholderSection)
+ case .status:
+ statusSection
+ }
+ }
+
+ @ViewBuilder
+ var accountSection: some View {
if let snapshot = viewModel.snapshot {
AccountCard(
title: snapshot.accountLabel,
@@ -60,10 +96,6 @@ private extension CodexStatusMenuView {
isRefreshing: viewModel.isRefreshing,
onRefresh: { viewModel.refresh(trigger: .manual) }
)
-
- activityCard
-
- dataSection(snapshot)
} else {
// 展示用户可处理的账户主链路状态, 其余错误只进日志
StatusAccountCard(
@@ -71,14 +103,12 @@ private extension CodexStatusMenuView {
isRefreshing: viewModel.isRefreshing,
onRefresh: { viewModel.refresh(trigger: .manual) }
)
- activityCard
- EmptyDataPanel()
}
}
@ViewBuilder
- var activityCard: some View {
- if codexHookSettings.isEnabled, mainPanelSettings.showsTaskCenter {
+ var activitySection: some View {
+ if codexHookSettings.isEnabled {
CodexActivityCard(
activityMonitor: activityMonitor,
presentationState: activityCenterPresentationState,
@@ -97,36 +127,85 @@ private extension CodexStatusMenuView {
}
@ViewBuilder
- func dataSection(_ snapshot: CodexQuotaSnapshot) -> some View {
- if snapshot.limits.isEmpty, snapshot.usage == nil {
+ func quotaSection(dataPlaceholderSection: MainPanelSection?) -> some View {
+ if let snapshot = viewModel.snapshot, !snapshot.limits.isEmpty {
+ QuotaLimitsSection(
+ limits: snapshot.limits,
+ credits: snapshot.credits,
+ resetCreditsAvailableCount: snapshot.resetCreditsAvailableCount,
+ resetCreditExpirationDates: snapshot.resetCreditExpirationDates,
+ isStale: snapshot.isRateLimitsStale,
+ onResetCreditsTap: onResetCreditsTap
+ )
+ } else if dataPlaceholderSection == .quota {
EmptyDataPanel()
- } else {
- if !snapshot.limits.isEmpty {
- QuotaLimitsSection(
- limits: snapshot.limits,
- credits: snapshot.credits,
- resetCreditsAvailableCount: snapshot.resetCreditsAvailableCount,
- resetCreditExpirationDates: snapshot.resetCreditExpirationDates,
- isStale: snapshot.isRateLimitsStale,
- onResetCreditsTap: onResetCreditsTap
- )
- }
+ }
+ }
- if let usage = snapshot.usage {
- UsageSummaryView(
- usage: usage,
- workflow: workflowViewModel.snapshot,
- showsWorkflow: codexHookSettings.isEnabled,
- isStale: snapshot.isUsageStale,
- onHoverContextChange: onUsageHeatmapHoverChange
- )
- }
+ @ViewBuilder
+ func usageSection(dataPlaceholderSection: MainPanelSection?) -> some View {
+ if let snapshot = viewModel.snapshot, let usage = snapshot.usage {
+ UsageSummaryView(
+ usage: usage,
+ workflow: workflowViewModel.snapshot,
+ showsWorkflow: codexHookSettings.isEnabled,
+ isStale: snapshot.isUsageStale,
+ onHoverContextChange: onUsageHeatmapHoverChange
+ )
+ } else if dataPlaceholderSection == .usage {
+ EmptyDataPanel()
+ }
+ }
+
+ @ViewBuilder
+ var statusSection: some View {
+ if let snapshot = viewModel.snapshot {
+ updatedAtRow(for: snapshot)
+ .padding(.horizontal, MenuMetrics.panelPadding)
+ .padding(.vertical, 7)
+ .liquidGlassSurface(cornerRadius: MenuMetrics.panelCornerRadius)
+ }
+ }
+
+ func dataPlaceholderSection(in visibleSections: [MainPanelSection]) -> MainPanelSection? {
+ let visibleDataSections = visibleSections.filter { section in
+ section == .quota || section == .usage
+ }
+ guard !visibleDataSections.isEmpty,
+ !visibleDataSections.contains(where: hasData(for:)) else {
+ return nil
+ }
+
+ return visibleDataSections.first
+ }
+
+ func hasData(for section: MainPanelSection) -> Bool {
+ switch section {
+ case .quota:
+ viewModel.snapshot?.limits.isEmpty == false
+ case .usage:
+ viewModel.snapshot?.usage != nil
+ case .account, .activity, .status:
+ false
}
+ }
- updatedAtRow(for: snapshot)
- .padding(.horizontal, MenuMetrics.panelPadding)
- .padding(.vertical, 7)
- .liquidGlassSurface(cornerRadius: MenuMetrics.panelCornerRadius)
+ func hasRenderableContent(
+ in visibleSections: [MainPanelSection],
+ dataPlaceholderSection: MainPanelSection?
+ ) -> Bool {
+ visibleSections.contains { section in
+ switch section {
+ case .account:
+ true
+ case .activity:
+ codexHookSettings.isEnabled
+ case .quota, .usage:
+ hasData(for: section) || dataPlaceholderSection == section
+ case .status:
+ viewModel.snapshot != nil
+ }
+ }
}
func updatedAtRow(for snapshot: CodexQuotaSnapshot) -> some View {
diff --git a/CodexBar/Views/Settings/AppSettingsView.swift b/CodexBar/Views/Settings/AppSettingsView.swift
index 6e2a6e2..f3bcb07 100644
--- a/CodexBar/Views/Settings/AppSettingsView.swift
+++ b/CodexBar/Views/Settings/AppSettingsView.swift
@@ -157,7 +157,6 @@ private extension AppSettingsView {
static let tabVerticalPadding: CGFloat = 7
static let tabContentSpacing = padding
static let windowChromeHeight = padding * 2 + tabBarHeight + tabContentSpacing
- static let optionsButtonSize: CGFloat = 22
static let menuBarQuotaPickerWidth: CGFloat = 72
static let syncStatusRowHeight: CGFloat = 16
static let syncStatusValueWidth: CGFloat = 160
@@ -239,6 +238,8 @@ private extension AppSettingsView {
var generalSettingsPage: some View {
VStack(alignment: .leading, spacing: Metrics.sectionSpacing) {
VStack(alignment: .leading, spacing: Metrics.rowSpacing) {
+ mainPanelLayoutRow
+ LiquidGlassDivider()
launchAtLoginRow
LiquidGlassDivider()
automaticUpdateCheckRow
@@ -258,8 +259,6 @@ private extension AppSettingsView {
VStack(alignment: .leading, spacing: Metrics.rowSpacing) {
codexHookRow
LiquidGlassDivider()
- taskCenterRow
- LiquidGlassDivider()
notificationRow
LiquidGlassDivider()
autoResetRow
@@ -384,19 +383,12 @@ private extension AppSettingsView {
menuBarQuotaSettings.selection != .off
}
- /// Hook 未开启时显示为关闭并置灰, 不修改持久化的 showsTaskCenter
- var taskCenterRow: some View {
- let isDisplayedOn = codexHookSettings.isEnabled && mainPanelSettings.showsTaskCenter
-
- return SettingsToggleRow(
- icon: "list.bullet.rectangle",
- title: "settings.task-center.show-in-menu",
- isOn: Binding(
- get: { isDisplayedOn },
- set: { mainPanelSettings.setShowsTaskCenter($0) }
- ),
- isEnabled: codexHookSettings.isEnabled && !codexHookSettings.isUpdating
- )
+ var mainPanelLayoutRow: some View {
+ MainPanelLayoutSettingsRow { anchorProvider in
+ onOptionsAction(
+ .toggle(panel: .mainPanel, anchorProvider: anchorProvider)
+ )
+ }
}
// MARK: - 高级页各行
@@ -439,7 +431,7 @@ private extension AppSettingsView {
}
)
) {
- optionsButton(isAvailable: canShowOptions) {
+ SettingsOptionsButton(isAvailable: canShowOptions) {
onOptionsAction(
.toggle(
panel: .autoReset,
@@ -513,7 +505,7 @@ private extension AppSettingsView {
),
isEnabled: codexHookSettings.isOperable && !codexHookSettings.isUpdating
) {
- optionsButton(isAvailable: canShowKeepAliveOptions) {
+ SettingsOptionsButton(isAvailable: canShowKeepAliveOptions) {
onOptionsAction(
.toggle(panel: .keepAlive, anchorProvider: keepAliveAnchorProvider)
)
@@ -536,20 +528,6 @@ private extension AppSettingsView {
}
}
- /// 子面板入口共用的滑杆按钮; 依赖没就绪时只隐藏入口, 不回写用户保存的开关
- func optionsButton(isAvailable: Bool, action: @escaping () -> Void) -> some View {
- Button(action: action) {
- Image(systemName: "slider.horizontal.3")
- }
- .buttonStyle(.plain)
- .controlSize(.small)
- .foregroundStyle(.tint)
- .frame(width: Metrics.optionsButtonSize, height: Metrics.optionsButtonSize)
- .opacity(isAvailable ? 1 : 0)
- .disabled(!isAvailable)
- .animation(Metrics.statusAnimation, value: isAvailable)
- }
-
@ViewBuilder
func settingsStatusCaptionRow(_ caption: SettingsStatusCaption?) -> some View {
if let caption {
@@ -883,7 +861,7 @@ private extension AppSettingsView {
set: { notificationSettings.setEnabled($0) }
)
) {
- optionsButton(isAvailable: notificationSettings.canShowOptions) {
+ SettingsOptionsButton(isAvailable: notificationSettings.canShowOptions) {
onOptionsAction(
.toggle(panel: .notification, anchorProvider: notificationAnchorProvider)
)
diff --git a/CodexBar/Views/Settings/MainPanelOptionsView.swift b/CodexBar/Views/Settings/MainPanelOptionsView.swift
new file mode 100644
index 0000000..05d0267
--- /dev/null
+++ b/CodexBar/Views/Settings/MainPanelOptionsView.swift
@@ -0,0 +1,288 @@
+import Foundation
+import SwiftUI
+
+/// 通用设置页中的主面板布局入口, 自己持有定位锚点
+struct MainPanelLayoutSettingsRow: View {
+ let onOptionsTap: (ScreenFrameProvider) -> Void
+ @State private var anchorProvider = ScreenFrameProvider()
+
+ var body: some View {
+ HStack(spacing: SettingsRowMetrics.spacing) {
+ Image(systemName: "rectangle.3.group")
+ .frame(width: SettingsRowMetrics.iconWidth)
+ .foregroundStyle(.tint)
+
+ Text("settings.main-panel.layout.title")
+
+ Spacer()
+
+ SettingsOptionsButton {
+ onOptionsTap(anchorProvider)
+ }
+ }
+ .background {
+ ScreenFrameReader(provider: anchorProvider)
+ }
+ }
+}
+
+/// 主面板布局子选项, 拖放调整区域顺序并控制显隐
+struct MainPanelOptionsView: View {
+ @ObservedObject var settings: MainPanelSettings
+ @ObservedObject var codexHookSettings: CodexHookSettings
+ let undoManager: UndoManager
+ @State private var dragState: SectionDragState?
+ @State private var dragTranslation: CGFloat = 0
+
+ var body: some View {
+ ZStack(alignment: .topLeading) {
+ VStack(spacing: 0) {
+ ForEach(Array(displayedSections.enumerated()), id: \.element) { index, section in
+ if index > 0 {
+ LiquidGlassDivider()
+ }
+
+ sectionRow(section)
+ .opacity(dragState?.section == section ? 0 : 1)
+ }
+ }
+ .animation(Metrics.reorderAnimation, value: displayedSections)
+
+ if let dragState {
+ sectionRow(dragState.section)
+ .frame(maxWidth: .infinity)
+ .liquidGlassSurface(cornerRadius: Metrics.draggedCornerRadius)
+ .shadow(
+ color: .black.opacity(Metrics.draggedShadowOpacity),
+ radius: Metrics.draggedShadowRadius,
+ y: Metrics.draggedShadowY
+ )
+ .offset(
+ y: CGFloat(dragState.originIndex) * Metrics.rowStride
+ + dragTranslation
+ )
+ .allowsHitTesting(false)
+ .zIndex(1)
+ }
+ }
+ .padding(.horizontal, Metrics.horizontalPadding)
+ .padding(.vertical, Metrics.verticalPadding)
+ .frame(width: Metrics.panelWidth, alignment: .topLeading)
+ .sidePanelChrome(cornerRadius: Metrics.cornerRadius)
+ .onDisappear {
+ dragState = nil
+ dragTranslation = 0
+ }
+ }
+
+ static var initialPanelSize: CGSize {
+ CGSize(
+ width: Metrics.panelWidth,
+ height: Metrics.verticalPadding * 2
+ + Metrics.rowHeight * CGFloat(MainPanelSection.allCases.count)
+ + Metrics.dividerHeight * CGFloat(MainPanelSection.allCases.count - 1)
+ )
+ }
+
+ private func sectionRow(_ section: MainPanelSection) -> some View {
+ let isAvailable = section != .activity || codexHookSettings.isEnabled
+ let isVisible = isAvailable && settings.layout.isVisible(section)
+ let visibleSectionCount = settings.layout.visibleSections.filter { visibleSection in
+ visibleSection != .activity || codexHookSettings.isEnabled
+ }.count
+ let canToggle = isAvailable && (!isVisible || visibleSectionCount > 1)
+
+ return HStack(spacing: Metrics.controlSpacing) {
+ Image(systemName: "line.3.horizontal")
+ .font(.caption.weight(.medium))
+ .foregroundStyle(.tertiary)
+ .frame(width: Metrics.dragHandleWidth, height: Metrics.rowHeight)
+ .contentShape(Rectangle())
+ .gesture(sectionDragGesture(for: section))
+
+ Image(systemName: section.symbolName)
+ .foregroundStyle(.tint)
+ .frame(width: Metrics.sectionIconWidth)
+
+ Text(section.title)
+ .font(.caption)
+ .foregroundStyle(.secondary)
+
+ Spacer(minLength: 8)
+
+ Toggle(
+ section.title,
+ isOn: Binding(
+ get: {
+ (section != .activity || codexHookSettings.isEnabled)
+ && settings.layout.isVisible(section)
+ },
+ set: {
+ settings.setSection(
+ section,
+ isVisible: $0,
+ undoManager: undoManager
+ )
+ }
+ )
+ )
+ .labelsHidden()
+ .toggleStyle(.switch)
+ .controlSize(.mini)
+ .disabled(!canToggle)
+ }
+ .frame(height: Metrics.rowHeight)
+ .padding(.horizontal, Metrics.rowHorizontalPadding)
+ }
+
+ private var displayedSections: [MainPanelSection] {
+ dragState?.displayedSections ?? settings.layout.orderedSections
+ }
+
+ private func sectionDragGesture(for section: MainPanelSection) -> some Gesture {
+ DragGesture(
+ minimumDistance: Metrics.dragMinimumDistance,
+ coordinateSpace: .global
+ )
+ .onChanged { value in
+ updateDrag(section: section, translation: value.translation.height)
+ }
+ .onEnded { _ in
+ finishDrag(section: section)
+ }
+ }
+
+ private func updateDrag(section: MainPanelSection, translation: CGFloat) {
+ if dragState?.section != section || dragState?.isSettling == true {
+ beginDrag(section)
+ }
+ guard var dragState, dragState.section == section else {
+ return
+ }
+
+ dragTranslation = translation
+ let indexOffset = Int((translation / Metrics.rowStride).rounded())
+ let targetIndex = min(
+ max(dragState.originIndex + indexOffset, 0),
+ dragState.initialSections.count - 1
+ )
+ guard targetIndex != dragState.targetIndex else {
+ return
+ }
+
+ dragState.targetIndex = targetIndex
+ self.dragState = dragState
+ }
+
+ private func beginDrag(_ section: MainPanelSection) {
+ let initialSections = settings.layout.orderedSections
+ guard let originIndex = initialSections.firstIndex(of: section) else {
+ return
+ }
+
+ dragTranslation = 0
+ dragState = SectionDragState(
+ section: section,
+ originIndex: originIndex,
+ targetIndex: originIndex,
+ initialSections: initialSections
+ )
+ }
+
+ private func finishDrag(section: MainPanelSection) {
+ guard var dragState, dragState.section == section else {
+ return
+ }
+
+ settings.setSectionOrder(
+ dragState.displayedSections,
+ undoManager: undoManager
+ )
+ dragState.isSettling = true
+ self.dragState = dragState
+ let dragID = dragState.id
+ withAnimation(
+ Metrics.settleAnimation,
+ completionCriteria: .logicallyComplete
+ ) {
+ dragTranslation = CGFloat(dragState.targetIndex - dragState.originIndex)
+ * Metrics.rowStride
+ } completion: {
+ guard self.dragState?.id == dragID else {
+ return
+ }
+
+ self.dragState = nil
+ dragTranslation = 0
+ }
+ }
+
+ private enum Metrics {
+ static let panelWidth: CGFloat = 270
+ static let horizontalPadding = SettingsOptionsPanelMetrics.horizontalPadding
+ static let verticalPadding = SettingsOptionsPanelMetrics.verticalPadding
+ static let rowHeight: CGFloat = 28
+ static let dividerHeight: CGFloat = 1
+ static let rowStride = rowHeight + dividerHeight
+ static let controlSpacing = SettingsOptionsPanelMetrics.controlSpacing
+ static let dragHandleWidth: CGFloat = 16
+ static let sectionIconWidth: CGFloat = 18
+ static let rowHorizontalPadding: CGFloat = 2
+ static let dragMinimumDistance: CGFloat = 2
+ static let draggedCornerRadius: CGFloat = 7
+ static let draggedShadowOpacity = 0.24
+ static let draggedShadowRadius: CGFloat = 7
+ static let draggedShadowY: CGFloat = 3
+ static let reorderAnimation = Animation.smooth(duration: 0.18)
+ static let settleAnimation = Animation.smooth(duration: 0.14)
+ static let cornerRadius = SettingsOptionsPanelMetrics.cornerRadius
+ }
+}
+
+private struct SectionDragState {
+ let id = UUID()
+ let section: MainPanelSection
+ let originIndex: Int
+ var targetIndex: Int
+ let initialSections: [MainPanelSection]
+ var isSettling = false
+
+ var displayedSections: [MainPanelSection] {
+ var sections = initialSections
+ sections.remove(at: originIndex)
+ sections.insert(section, at: targetIndex)
+ return sections
+ }
+}
+
+private extension MainPanelSection {
+ var title: LocalizedStringResource {
+ switch self {
+ case .account:
+ "settings.main-panel.section.account"
+ case .activity:
+ "settings.main-panel.section.activity"
+ case .quota:
+ "settings.main-panel.section.quota"
+ case .usage:
+ "settings.main-panel.section.usage"
+ case .status:
+ "settings.main-panel.section.status"
+ }
+ }
+
+ var symbolName: String {
+ switch self {
+ case .account:
+ "person.fill"
+ case .activity:
+ "list.bullet.rectangle"
+ case .quota:
+ "gauge.with.dots.needle.50percent"
+ case .usage:
+ "chart.bar.xaxis"
+ case .status:
+ "clock"
+ }
+ }
+}
diff --git a/CodexBar/Views/Settings/SettingsToggleRow.swift b/CodexBar/Views/Settings/SettingsToggleRow.swift
index 800524d..9b8d0a8 100644
--- a/CodexBar/Views/Settings/SettingsToggleRow.swift
+++ b/CodexBar/Views/Settings/SettingsToggleRow.swift
@@ -4,6 +4,34 @@ import SwiftUI
enum SettingsRowMetrics {
static let iconWidth: CGFloat = 18
static let spacing: CGFloat = 10
+ static let optionsButtonSize: CGFloat = 22
+}
+
+/// 设置窗口子面板入口共用的滑杆按钮
+struct SettingsOptionsButton: View {
+ let isAvailable: Bool
+ let action: () -> Void
+
+ init(isAvailable: Bool = true, action: @escaping () -> Void) {
+ self.isAvailable = isAvailable
+ self.action = action
+ }
+
+ var body: some View {
+ Button(action: action) {
+ Image(systemName: "slider.horizontal.3")
+ }
+ .buttonStyle(.plain)
+ .controlSize(.small)
+ .foregroundStyle(.tint)
+ .frame(
+ width: SettingsRowMetrics.optionsButtonSize,
+ height: SettingsRowMetrics.optionsButtonSize
+ )
+ .opacity(isAvailable ? 1 : 0)
+ .disabled(!isAvailable)
+ .animation(.codexStatus, value: isAvailable)
+ }
}
/// 设置窗口右侧子选项面板共用的度量
diff --git a/Config/Version.xcconfig b/Config/Version.xcconfig
index 158eca1..081151c 100644
--- a/Config/Version.xcconfig
+++ b/Config/Version.xcconfig
@@ -1,2 +1,2 @@
-MARKETING_VERSION = 3.6.4
-CURRENT_PROJECT_VERSION = 71
+MARKETING_VERSION = 3.6.5
+CURRENT_PROJECT_VERSION = 72
diff --git a/Docs/DeveloperGuide/ui-and-lifecycle.md b/Docs/DeveloperGuide/ui-and-lifecycle.md
index 2f07b8b..a3cf4da 100644
--- a/Docs/DeveloperGuide/ui-and-lifecycle.md
+++ b/Docs/DeveloperGuide/ui-and-lifecycle.md
@@ -216,18 +216,27 @@ hover 类型的热力图面板在打开其他面板前可以渐隐,点击类
设置窗口的高度随当前 tab 内容变化,但固定上边缘并限制到屏幕 visible frame。固定上边缘可以减少切换 tab 时整窗上下漂移,让标题栏保持稳定视觉锚点。
-通知、自动重置和防睡眠的二级设置面板按需创建。控制器一旦创建就会长期订阅内容高度变化,如果 App 启动时预建所有面板,从未使用的 UI 也会一直参与更新。
+主面板布局、通知、自动重置和防睡眠的二级设置面板按需创建。控制器一旦创建就会长期持有内容及必要的高度变化订阅,如果 App 启动时预建所有面板,从未使用的 UI 也会一直参与更新。
+
+这四个设置子面板包含交互控件,因此使用可获得键盘焦点的 `KeyableBorderlessPanel`。主面板的热力图、Reset Credits 和活动中心详情使用不会激活的 `NonactivatingSidePanel`。收起设置子面板时,`SidePanelSupport.orderOut` 只在该子面板仍是 key window 时恢复父窗口焦点;如果焦点已经主动转移到主面板或其他窗口,则不能再抢回,否则新打开的交互表面可能因失焦立即关闭。
自动重置与防睡眠从关闭切换为开启时,`AppSettingsView` 使用 `HelperFeatureConfirmation` 显示统一确认框。确认框按 `KeepAliveController.HelperStatus` 组合 Helper 提示与对应功能说明,用户确认后才调用设置对象写入开启状态。已开启设置行在 `.requiresApproval` 状态显示 `打开系统设置` 按钮。
二级设置入口使用各自的可用性结论:
+- 主面板布局入口始终可用
- 通知读取 `NotificationSettings.canShowOptions`
- 自动重置要求 `AutoResetSettings.isEnabled` 且 `KeepAliveController.helperStatus == .enabled`
- 防睡眠读取 `KeepAliveController.canShowOptions`
入口条件失效时设置页发送对应的 `close` 动作,避免不可用的子面板继续显示。主开关关闭时,自动重置和防睡眠设置行不显示状态说明。
+`MainPanelSettings` 使用稳定区域标识保存账户、任务中心、额度、Token 用量和底部状态的顺序与显隐。布局归一化会去重、忽略无效值、补齐缺失区域,并保证至少保留一个可见区域。`StatusItemController` 在读取到 Hook 关闭状态后调用 `updateHookEnabled(_:)`,持久化关闭任务中心;如果任务中心原本是唯一可见区域,则同时开启账户区域。设置面板只禁用任务中心开关,拖拽手柄仍保持可用。其他数据链路的临时可用性只影响当次渲染。
+
+布局排序使用手柄上的自定义 `DragGesture`。拖动项通过悬浮副本跟随指针,其他行在跨过半行距离时按视图内预览顺序实时让位,松手后才调用 `setSectionOrder(_:)` 一次性持久化最终顺序。不要改回系统 `.draggable` 和 `.dropDestination`,它们只能在落点命中后换位,无法提供连续排序动画。
+
+`SettingsWindowController` 持有这一窗口组唯一的 `UndoManager`。设置主窗口通过 `AuxiliaryHostingWindow` 暴露它,四个设置子面板展示时从父窗口取得同一实例,因此焦点位于设置主窗口或任一子面板时,`⌘Z` 和 `⌘⇧Z` 都作用于同一份布局历史。Hook 状态变化引起的任务中心自动关闭不进入用户撤销历史。
+
### 120 ms 焦点恢复不是业务延迟
菜单关闭时 `AuxiliaryHostingWindow` 暂时把 `allowsKeyFocus` 设为 false。关闭完成后等待约 120 ms 再恢复。
@@ -308,7 +317,9 @@ app-server 状态默认每 60 秒刷新。面板打开时会安排约 160 ms 的
- 全局快捷键在状态栏锚点有效和无效场景都能打开面板
- 从通知点击激活 App 并打开面板
- 设置窗口首次打开、关闭和再次打开时焦点正确
-- 通知、自动重置和防睡眠子面板互斥,顶边对齐对应设置行,内容变化后高度正确
+- 主面板布局、通知、自动重置和防睡眠子面板互斥,顶边对齐对应设置行,内容变化后高度正确
+- 设置子面板展开时从菜单栏打开主面板,主面板保持打开,设置子面板收起且不把焦点抢回设置窗口
+- 主面板区域拖动时悬浮行跟随指针,跨过半行后其他行实时让位,松手后平滑落位并只保存最终顺序;拖拽和显隐操作可以通过 `⌘Z` 逐步撤销并通过 `⌘⇧Z` 重做,焦点在设置主窗口或任一设置子面板时均有效;重启后保持配置,最后一个可见区域无法关闭;Hook 关闭时任务中心自动关闭、开关置灰但仍可拖动,任务中心为唯一可见区域时账户自动开启,自动联动不进入用户撤销历史
- 上下文菜单打开设置或日志时没有焦点丢失
- 多显示器和不同菜单栏位置下 fallback panel 位于鼠标屏幕
- 快捷键冲突后原快捷键仍可用
diff --git a/Docs/UserGuide/main-panel.md b/Docs/UserGuide/main-panel.md
index d0aac68..cd5fd6c 100644
--- a/Docs/UserGuide/main-panel.md
+++ b/Docs/UserGuide/main-panel.md
@@ -21,6 +21,12 @@ CodexBar 用图标、状态点和可选额度条同时表达账户、任务和
额度数据来自缓存时,图标和进度条会降低透明度,表示当前看到的不是最新快照。
+## 自定义布局
+
+在 `设置 > 通用 > 主面板布局` 中,可以拖动调整 `账户`、`任务`、`额度`、`用量` 和 `状态` 5 个区域的顺序,也可以分别控制是否显示。
+
+主面板至少保留一个区域。Hook 未开启时,`任务` 区域自动关闭且开关置灰,但仍可拖动调整位置;如果该区域原本是唯一显示区域,`账户` 区域会自动开启。重新开启 Hook 后,可以再手动开启 `任务` 区域。拖拽排序或切换区域显隐后,可以使用 `⌘Z` 按操作顺序撤销,并使用 `⌘⇧Z` 重做。
+
## 账户区域
- 展示当前登录账户或账户类型
diff --git a/Docs/UserGuide/settings.md b/Docs/UserGuide/settings.md
index 62642e8..f2cca15 100644
--- a/Docs/UserGuide/settings.md
+++ b/Docs/UserGuide/settings.md
@@ -10,6 +10,7 @@
| 设置 | 作用 | 默认或初始状态 |
| --- | --- | --- |
+| 主面板布局 | 调整主面板 5 个区域的顺序和显隐 | 账户、任务、额度、用量、状态;Hook 未开启时任务关闭 |
| 开机自动启动 | 通过 macOS 登录项自动启动 CodexBar | 跟随当前系统登录项状态 |
| 自动检查更新 | 由 Sparkle 定期检查可用更新 | 跟随 Sparkle 当前设置 |
| 菜单栏额度指示 | 在菜单栏图标旁显示所选额度窗口剩余比例 | 主额度 |
@@ -22,6 +23,19 @@
- 再次开启时恢复上次选择
- 缓存额度会降低显示透明度
+### 主面板布局
+
+点击设置行右侧的选项按钮,可以配置 `账户`、`任务`、`额度`、`用量` 和 `状态` 5 个区域:
+
+- 拖动区域调整显示顺序
+- 使用开关控制区域是否显示
+- 至少需要保留一个区域
+- 拖拽排序或切换显隐后,可以使用 `⌘Z` 按操作顺序撤销,并使用 `⌘⇧Z` 重做
+
+`任务` 区域与 CodexBar Hook 联动。Hook 未开启时,该区域自动关闭,其开关置灰且无法开启,但仍可拖动调整位置。重新开启 Hook 后,该区域保持关闭,可以再手动开启。
+
+隐藏区域只影响主面板展示,不会停止额度刷新、Hook 统计、通知、防睡眠或同步。
+
### 全局快捷键
- 录制结果至少需要两个修饰键
@@ -35,7 +49,6 @@
| 设置 | 作用 | 默认状态 |
| --- | --- | --- |
| CodexBar Hook | 安装并校验 Codex 事件 handler | 未安装时关闭 |
-| 主面板任务中心 | 控制活动卡片和任务中心是否显示 | 开启,Hook 关闭时不可用 |
| 系统通知 | 控制 CodexBar 本地通知和任务触觉反馈 | 关闭 |
| 自动重置 | 按所选提前量在过期前使用尚未消费的重置次数重置 Codex 额度 | 关闭,提前 30 分钟 |
| 防止系统睡眠 | 根据实时 Codex 任务自动切换系统睡眠 | 关闭 |
@@ -50,14 +63,6 @@
完整说明见 [实时任务与 CodexBar Hook](activity-and-hook.md)
-### 主面板任务中心
-
-关闭后,主面板不再显示活动卡片和任务中心入口。
-
-这个设置不会关闭 Hook,不会停止 Hook 统计、通知或防睡眠。
-
-Hook 关闭时该选项会显示为关闭并置灰,保存的选择不会被覆盖。
-
### 系统通知子选项
| 选项 | 默认值 | 其他可选值或说明 |
diff --git a/Docs/UserGuide/troubleshooting.md b/Docs/UserGuide/troubleshooting.md
index b244f52..b3eea48 100644
--- a/Docs/UserGuide/troubleshooting.md
+++ b/Docs/UserGuide/troubleshooting.md
@@ -56,7 +56,7 @@ Hook 配置位于 `$CODEX_HOME/hooks.json`,未设置 `CODEX_HOME` 时位于 `~
## 实时任务没有出现
1. 确认 CodexBar Hook 已开启且没有错误提示
-2. 确认 `主面板任务中心` 已开启
+2. 确认 `通用 > 主面板布局` 中的 `任务` 区域已开启
3. 新建一轮 Codex 任务以产生实时事件
4. 打开设置窗口触发一次 Hook 重新校验
diff --git a/Docs/en/DeveloperGuide/ui-and-lifecycle.md b/Docs/en/DeveloperGuide/ui-and-lifecycle.md
index 7d1a705..20adf63 100644
--- a/Docs/en/DeveloperGuide/ui-and-lifecycle.md
+++ b/Docs/en/DeveloperGuide/ui-and-lifecycle.md
@@ -216,18 +216,27 @@ Context-menu actions wait until menu tracking finishes before running, avoiding
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.
-Secondary panels for notifications, Automatic Reset, and sleep prevention are created on demand. Once created, a controller subscribes to content-height updates for its lifetime. Prebuilding every panel at app launch would keep unused UI participating in updates.
+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.
+
+These four settings child panels contain interactive controls, so they use a keyable `KeyableBorderlessPanel`. The main panel's Heatmap, Reset Credits, and Task Center details use a nonactivating `NonactivatingSidePanel`. When a settings child panel closes, `SidePanelSupport.orderOut` restores focus to its parent only if that child panel is still the key window. If focus has already moved intentionally to the main panel or another window, it must not be taken back, or the newly opened interaction surface may close immediately after losing focus.
When Automatic Reset or Prevent System Sleep changes from off to on, `AppSettingsView` presents a shared confirmation through `HelperFeatureConfirmation`. It combines guidance from `KeepAliveController.HelperStatus` with the feature description and writes enabled state only after user confirmation. An enabled settings row in `.requiresApproval` shows `Open System Settings`.
Each secondary-settings entry uses its own availability decision:
+- Main Panel Layout is always available
- Notifications reads `NotificationSettings.canShowOptions`
- Automatic Reset requires `AutoResetSettings.isEnabled` and `KeepAliveController.helperStatus == .enabled`
- Sleep prevention reads `KeepAliveController.canShowOptions`
When a condition becomes false, Settings sends the corresponding `close` action so an unavailable child panel does not remain visible. Automatic Reset and sleep-prevention rows show no status explanation while their main switches are off.
+`MainPanelSettings` stores the order and visibility of Account, Task Center, Quota, Token Usage, and Footer Status with stable section identifiers. Layout normalization removes duplicates, ignores invalid values, appends missing sections, and keeps at least one section visible. After reading a disabled Hook state, `StatusItemController` calls `updateHookEnabled(_:)` to persist Task Center as hidden. If Task Center was the only visible section, Account is enabled at the same time. The settings panel disables only the Task Center switch, so its drag handle remains available. Temporary availability of other data sources affects only the current rendering.
+
+Layout sorting uses a custom `DragGesture` on each handle. A floating copy follows the pointer, while the other rows make room using a view-local preview order whenever the drag crosses half a row. Only after release does the view call `setSectionOrder(_:)` once to persist the final order. Do not replace this with system `.draggable` and `.dropDestination`, which reorder only after a drop target is hit and cannot provide continuous sorting animation.
+
+`SettingsWindowController` owns the only `UndoManager` for this window group. The Settings window exposes it through `AuxiliaryHostingWindow`, and each of the four settings child panels obtains the same instance from its parent when shown. `Command-Z` and `Command-Shift-Z` therefore operate on one layout history while focus is in either the Settings window or any child panel. Automatic Task Center changes caused by Hook state do not enter the user's undo history.
+
### The 120 ms Focus Recovery Is Not Business Delay
While the menu closes, `AuxiliaryHostingWindow` temporarily sets `allowsKeyFocus` to false. It waits about 120 ms after closing before restoring it.
@@ -308,7 +317,9 @@ 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
-- 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
+- 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
- Opening Settings or Logs from the context menu does not lose focus
- On multiple displays and with different menu bar locations, the fallback panel appears on the pointer's screen
- The old shortcut still works after a new shortcut conflicts
diff --git a/Docs/en/UserGuide/main-panel.md b/Docs/en/UserGuide/main-panel.md
index b70467a..c5d8725 100644
--- a/Docs/en/UserGuide/main-panel.md
+++ b/Docs/en/UserGuide/main-panel.md
@@ -21,6 +21,12 @@ Hover over the menu bar icon to see the current task state, project name, elapse
When rate-limit data comes from cache, the icon and progress bar become translucent to indicate that the visible data is not the latest snapshot.
+## Layout Customization
+
+In `Settings > General > Main Panel Layout`, you can drag the `Account`, `Tasks`, `Quota`, `Usage`, and `Status` sections into a different order and control each section's visibility.
+
+The main panel always keeps at least one section visible. When Hook is disabled, the `Tasks` section turns off automatically and its switch is disabled, but the row remains draggable. If it was the only visible section, `Account` is enabled automatically. After Hook is enabled again, you can turn `Tasks` on manually. After reordering sections or changing their visibility, press `Command-Z` to undo changes in order and `Command-Shift-Z` to redo them.
+
## Account
- Shows the signed-in account or account type
diff --git a/Docs/en/UserGuide/settings.md b/Docs/en/UserGuide/settings.md
index 2a84b90..49661a8 100644
--- a/Docs/en/UserGuide/settings.md
+++ b/Docs/en/UserGuide/settings.md
@@ -10,6 +10,7 @@ Settings contains three pages: `General`, `Advanced`, and `About`.
| Setting | Effect | Default or initial state |
| --- | --- | --- |
+| Main Panel Layout | Reorders and shows or hides the five main-panel sections | Account, Tasks, Quota, Usage, and Status; the Tasks section is off while Hook is disabled |
| Launch at Login | Starts CodexBar automatically through macOS Login Items | Follows the current system Login Item state |
| Automatically Check for Updates | Lets Sparkle check periodically for updates | Follows the current Sparkle setting |
| Menu Bar Quota Indicator | Shows the remaining percentage for a selected rate-limit window beside the menu bar icon | Primary rate limit |
@@ -22,6 +23,19 @@ Settings contains three pages: `General`, `Advanced`, and `About`.
- Turning it on again restores the previous selection
- Cached rate-limit data is shown with reduced opacity
+### Main Panel Layout
+
+Click the options button on the settings row to configure the `Account`, `Tasks`, `Quota`, `Usage`, and `Status` sections:
+
+- Drag sections to change their display order
+- Use each switch to show or hide a section
+- Keep at least one section visible
+- Press `Command-Z` to undo section reordering or visibility changes in order, and `Command-Shift-Z` to redo them
+
+The `Tasks` section follows CodexBar Hook. When Hook is disabled, this section turns off automatically and its switch is disabled, but the row remains draggable. After Hook is enabled again, the section remains off until you turn it on manually.
+
+Hiding a section affects only the main-panel presentation. It does not stop rate-limit refreshes, Hook metrics, notifications, sleep prevention, or sync.
+
### Global Shortcut
- A recorded shortcut must contain at least two modifier keys
@@ -35,7 +49,6 @@ Settings contains three pages: `General`, `Advanced`, and `About`.
| Setting | Effect | Default |
| --- | --- | --- |
| CodexBar Hook | Installs and validates the Codex event handler | Off when not installed |
-| Show Task Center in Menu | Controls whether the activity card and Task Center appear | On; unavailable while Hook is off |
| System Notifications | Controls CodexBar local notifications and task haptic feedback | Off |
| Automatic Reset | Uses unredeemed reset credits at the selected lead time before expiration | Off; 30 minutes early |
| Prevent System Sleep | Manages system sleep automatically based on live Codex tasks | Off |
@@ -50,14 +63,6 @@ Enabling and validating it requires the current app-server to be `0.145.0` or la
See [Live Tasks and CodexBar Hook](activity-and-hook.md) for details.
-### Show Task Center in Menu
-
-When this setting is off, the main panel no longer shows the activity card or the Task Center entry.
-
-It does not disable the Hook or stop Hook metrics, notifications, or sleep prevention.
-
-When the Hook is off, this option appears off and disabled without overwriting your saved choice.
-
### System Notification Options
| Option | Default | Other choices or notes |
diff --git a/Docs/en/UserGuide/troubleshooting.md b/Docs/en/UserGuide/troubleshooting.md
index 52c2b9b..9214db6 100644
--- a/Docs/en/UserGuide/troubleshooting.md
+++ b/Docs/en/UserGuide/troubleshooting.md
@@ -56,7 +56,7 @@ If CodexBar reports an incomplete Hook after an upgrade, turn the Hook off and o
## Live Tasks Do Not Appear
1. Confirm that CodexBar Hook is enabled with no error
-2. Confirm that `Show Task Center in Menu` is enabled
+2. Confirm that `Tasks` is enabled under `General > Main Panel Layout`
3. Start a new Codex task to generate live events
4. Open Settings to trigger Hook validation again
diff --git a/appcast.xml b/appcast.xml
index cb76f91..5cfdd58 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.5</title>
+ <sparkle:version>72</sparkle:version>
+ <sparkle:shortVersionString>3.6.5</sparkle:shortVersionString>
+ <sparkle:minimumSystemVersion>15.0</sparkle:minimumSystemVersion>
+ <sparkle:releaseNotesLink>https://codexbar.zabrian.app/notes#3.6.5</sparkle:releaseNotesLink>
+ <pubDate>Sun, 23 Aug 2026 15:17:36 +0800</pubDate>
+ <enclosure url="https://codexbar.zabrian.app/download/CodexBar-v3.6.5.dmg" sparkle:edSignature="cOmTpbtv/9G6uuafebi1dnABglrn37tN6KcsM68RR+lkTW+hTKnh1PJQ2nkQTfnty83JIqa+RMr8T8RKJpgVAw==" length="7164758" type="application/octet-stream"/>
+ </item>
<item>
<title>CodexBar.app 3.6.4</title>
<sparkle:version>71</sparkle:version>