Skip to content

Improve menu ticker and portfolio UI#2

Closed
1254455745 wants to merge 6 commits into
TNT-Likely:mainfrom
1254455745:improve-menu-and-portfolio-ui
Closed

Improve menu ticker and portfolio UI#2
1254455745 wants to merge 6 commits into
TNT-Likely:mainfrom
1254455745:improve-menu-and-portfolio-ui

Conversation

@1254455745
Copy link
Copy Markdown

@1254455745 1254455745 commented May 31, 2026

Summary

  • reorganize menu bar ticker display settings and add per-mode width options
  • improve portfolio table sizing and holdings popover layout
  • stabilize popover position while ticker content width changes
  • improve quote refresh behavior and clean up Swift warnings

Test

  • make build

Summary by CodeRabbit

发行说明

  • New Features

    • 新增更多 Ticker 显示偏好:显示应用图标、行情代码/名称、方向箭头;为滚动/轮播/紧凑/紧凑无代码等模式提供可调宽度与自动宽度开关
    • 菜单栏/轮播/紧凑/最小视图支持可配置总宽度、动画失效刷新与更灵活布局
    • 弹窗定位支持可选锚点宽度,增加弹窗关闭回调与状态栏长度锁定
    • 持仓视图突出今日盈亏并引入自适应列宽表格
  • Bug Fixes

    • 行情获取与刷新更严格,空结果/错误更易被发现并处理
    • 通知与权限回调改为在主线程/主 Actor 上更新,提升状态一致性

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 31, 2026

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

此 PR 为 Ticker 增加可配置显示与布局选项、扩展持久化键与偏好迁移,重构 MenuBar 视图以支持可选图标/可选宽度与动画失效,更新 Popover 行为与 Renderer,并修正/现代化部分基础设施并发与内存访问模式。

变更

Ticker 显示与布局可配置化

Layer / File(s) Summary
存储键与配置模型定义
PanBar/Data/Persistence/Repositories/SettingsRepository.swift, PanBar/Infrastructure/TickerPreferences.swift, project.yml
新增 SettingsRepository 的 ticker key;TickerPreferences 扩展多项 @Published 偏好(图标、代码/名称显示、模式专属菜单宽度与 autoWidth、方向箭头),包含宽度钳制、历史迁移与默认回写;新增/调整 TickerDisplayMode;设置 project.yml 的 Xcode 版本。
基础设施并发与安全性改进
PanBar/Domain/Services/PortfolioService.swift, PanBar/Infrastructure/HotkeyBinding.swift, PanBar/Infrastructure/NotificationService.swift, PanBar/Infrastructure/QuoteRefresher.swift, PanBar/Infrastructure/Updater.swift
PortfolioService 对空结果由静默回退改为显式抛错;HotkeyBinding 使用 withMemoryRebound 替代 unsafeBitCast;NotificationService 回调改为 Task { @mainactor ... };QuoteRefresher 增加互斥、调整写入语义;Updater 调整后台任务中的 await 用法。
MenuBar 视图协议与实现
PanBar/MenuBar/MenuBarTickerView.swift, PanBar/MenuBar/TickerView.swift, PanBar/MenuBar/CarouselTickerView.swift, PanBar/MenuBar/CompactTickerView.swift, PanBar/MenuBar/MinimalTickerView.swift
MenuBarTickerView 协议新增 showsIconpreferredTotalWidthinvalidateAnimation();各视图组件增加相应属性并重构 totalWidth/leadingTextX 与绘制逻辑,Compact 支持方向箭头显示,均新增动画失效/停止接入点。
Popover 与 Renderer 支持
PanBar/Popover/PopoverController.swift, PanBar/MenuBar/TickerRenderer.swift
PopoverController 新增 onClose 回调、didClose 主 actor 处理与 show(relativeTo:anchorWidth:),用于 popover 宽度/关闭生命周期管理;TickerRenderer 新增 showsQuoteCode/showsQuoteName 开关并在空 items 时返回空 NSAttributedString
MenuBar 状态栏综合控制
PanBar/MenuBar/StatusItemController.swift
引入 popover 长度锁定机制、在 init 中绑定 onClose 并在视图切换前调用 invalidateAnimation(),合并 .scroll/.scrollNoCode 渲染路径,抽离 carousel 项目组装并调整汇总项顺序。
UI 展示细节
PanBar/Popover/Views/HoldingsTab.swift, PanBar/Popover/Views/SummaryCards.swift, PanBar/Settings/Panes/PortfolioPane.swift, PanBar/Settings/Panes/TickerPane.swift
HoldingsTab 增加今日盈亏与 allTime 列、重构右侧布局;SummaryCards 调整卡片顺序;PortfolioPane 实现按列宽计算的伪表格并用 GeometryReader 布局;TickerPane 改为基于 displayMode 的分支,增加模式专属宽度與 autoWidth 控件及 quote 内容显示开关与方向箭头配置。

预期评审工作量

🎯 4 (Complex) | ⏱️ ~60 minutes

彩诗

🐰 新宽度新开关闪耀,
图标代码随意调,
scrollNoCode 静悄登场,
动画失效更干净,
偏好迁移与面板齐奏,欢欣跳跃🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 标题清晰准确地总结了变更的核心内容:改进菜单栏 ticker 和投资组合界面。标题与多个文件涉及的 UI 改进相符,包括 ticker 显示选项、菜单宽度控制和 holdings 布局优化。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
PanBar/Popover/PopoverController.swift (1)

49-57: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

didClose 观察者未正确释放,存在回调泄漏风险。

这里使用的是 block-based observer,但没有保存并移除返回 token;removeObserver(self) 不会移除该观察者。建议保存 token 并在 deinit 显式移除。

建议修复
 final class PopoverController {
+    private var didCloseObserver: NSObjectProtocol?
@@
-        NotificationCenter.default.addObserver(
+        didCloseObserver = NotificationCenter.default.addObserver(
             forName: NSPopover.didCloseNotification,
             object: popover,
             queue: .main
         ) { [weak self] _ in
             Task { `@MainActor` in
                 self?.handlePopoverClosed()
             }
         }
@@
     deinit {
         if let m = eventMonitor { NSEvent.removeMonitor(m) }
-        NotificationCenter.default.removeObserver(self)
+        if let token = didCloseObserver {
+            NotificationCenter.default.removeObserver(token)
+        }
     }

Also applies to: 60-63

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@PanBar/Popover/PopoverController.swift` around lines 49 - 57, The block-based
NotificationCenter observer for NSPopover.didCloseNotification is not stored or
removed causing a leak; capture the returned observer token (e.g., a property
like popoverDidCloseObserver: NSObjectProtocol?) when calling
NotificationCenter.default.addObserver(forName:object:queue:using:) and call
NotificationCenter.default.removeObserver(popoverDidCloseObserver!) (or
nil-check) in deinit (and do the same for the other observer at lines 60-63),
ensuring the closure still calls self?.handlePopoverClosed() via Task {
`@MainActor` in … } while storing/removing the token to prevent callback
retention.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@PanBar/Infrastructure/TickerPreferences.swift`:
- Around line 167-171: Init currently assigns directly to
menuBarWidth/scrollMenuBarWidth/carouselMenuBarWidth/compactMenuBarWidth which
bypasses their didSet clamp-and-persist logic; instead, read raw values from
repo into local Ints inside init(repo:), then pass those values through the same
clamping+persist path (either by calling a new private helper like
applyMenuBarWidths(menu:,scroll:,carousel:,compact:) or by invoking existing
setter methods you add such as setMenuBarWidth(_:), setScrollMenuBarWidth(_:),
setCarouselMenuBarWidth(_:), setCompactMenuBarWidth(_:)), so that the clamp
logic and repo.set(...) for SettingsRepository.Keys.ticker* are executed for
stored (possibly out-of-range) values.

In `@PanBar/MenuBar/TickerRenderer.swift`:
- Around line 33-35: The guard that returns an empty NSAttributedString when
items.isEmpty causes the status item to collapse; instead return a minimal
placeholder string so the menu bar item remains visible. In TickerRenderer (the
method that builds the attributed title where you currently check `guard
!items.isEmpty else { return NSAttributedString() }`), replace the empty return
with an NSAttributedString containing a single placeholder character (e.g. "—"
or a localized "no data" string) using the same attributes/style used for normal
items so sizing and accessibility remain consistent.

In `@PanBar/MenuBar/TickerView.swift`:
- Around line 43-49: The early return for empty attributed text causes
preferredTotalWidth to be ignored when content is briefly empty; reorder the
checks in the width calculation so that if preferredTotalWidth is non-nil it is
returned (max(40, preferredTotalWidth)) before the empty-content branch that
returns leadingTextX + 4; update the same logic in TickerView (the shown method
using attributed, preferredTotalWidth, leadingTextX, visibleTextWidth) and
mirror the fix in CarouselTickerView and CompactTickerView to prevent
menu-bar/anchor jitter.

---

Outside diff comments:
In `@PanBar/Popover/PopoverController.swift`:
- Around line 49-57: The block-based NotificationCenter observer for
NSPopover.didCloseNotification is not stored or removed causing a leak; capture
the returned observer token (e.g., a property like popoverDidCloseObserver:
NSObjectProtocol?) when calling
NotificationCenter.default.addObserver(forName:object:queue:using:) and call
NotificationCenter.default.removeObserver(popoverDidCloseObserver!) (or
nil-check) in deinit (and do the same for the other observer at lines 60-63),
ensuring the closure still calls self?.handlePopoverClosed() via Task {
`@MainActor` in … } while storing/removing the token to prevent callback
retention.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 01278719-cc55-43eb-a9cc-1c277c85f332

📥 Commits

Reviewing files that changed from the base of the PR and between e5af229 and a543996.

📒 Files selected for processing (21)
  • PanBar/Data/Persistence/Repositories/SettingsRepository.swift
  • PanBar/Domain/Services/PortfolioService.swift
  • PanBar/Infrastructure/HotkeyBinding.swift
  • PanBar/Infrastructure/NotificationService.swift
  • PanBar/Infrastructure/QuoteRefresher.swift
  • PanBar/Infrastructure/TickerPreferences.swift
  • PanBar/Infrastructure/Updater.swift
  • PanBar/MenuBar/CarouselTickerView.swift
  • PanBar/MenuBar/CompactTickerView.swift
  • PanBar/MenuBar/MenuBarTickerView.swift
  • PanBar/MenuBar/MinimalTickerView.swift
  • PanBar/MenuBar/StatusItemController.swift
  • PanBar/MenuBar/TickerRenderer.swift
  • PanBar/MenuBar/TickerView.swift
  • PanBar/Popover/PopoverController.swift
  • PanBar/Popover/Views/HoldingsTab.swift
  • PanBar/Popover/Views/SummaryCards.swift
  • PanBar/Resources/Localizable.xcstrings
  • PanBar/Settings/Panes/PortfolioPane.swift
  • PanBar/Settings/Panes/TickerPane.swift
  • project.yml

Comment thread PanBar/Infrastructure/TickerPreferences.swift Outdated
Comment on lines 33 to 35
guard !items.isEmpty else {
return NSAttributedString(
string: L("ticker.empty", comment: "no quotes"),
attributes: [
.font: font,
.foregroundColor: NSColor.secondaryLabelColor
]
)
return NSAttributedString()
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

空数据直接返回空文本会导致菜单栏入口“消失”。

建议保留最小占位文本(例如 或本地化 no-data),避免无图标场景下状态栏项宽度过小、用户难以发现和点击。

建议修复
     func render(items: [TickerItem]) -> NSAttributedString {
         guard !items.isEmpty else {
-            return NSAttributedString()
+            return NSAttributedString(
+                string: "—",
+                attributes: [
+                    .font: font,
+                    .foregroundColor: NSColor.white.withAlphaComponent(0.55)
+                ]
+            )
         }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
guard !items.isEmpty else {
return NSAttributedString(
string: L("ticker.empty", comment: "no quotes"),
attributes: [
.font: font,
.foregroundColor: NSColor.secondaryLabelColor
]
)
return NSAttributedString()
}
guard !items.isEmpty else {
return NSAttributedString(
string: "",
attributes: [
.font: font,
.foregroundColor: NSColor.white.withAlphaComponent(0.55)
]
)
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@PanBar/MenuBar/TickerRenderer.swift` around lines 33 - 35, The guard that
returns an empty NSAttributedString when items.isEmpty causes the status item to
collapse; instead return a minimal placeholder string so the menu bar item
remains visible. In TickerRenderer (the method that builds the attributed title
where you currently check `guard !items.isEmpty else { return
NSAttributedString() }`), replace the empty return with an NSAttributedString
containing a single placeholder character (e.g. "—" or a localized "no data"
string) using the same attributes/style used for normal items so sizing and
accessibility remain consistent.

Comment thread PanBar/MenuBar/TickerView.swift Outdated
@TNT-Likely
Copy link
Copy Markdown
Owner

@pullfrog 干活

@TNT-Likely
Copy link
Copy Markdown
Owner

@1254455745 拆一下pr 太多了review不过来

@1254455745 1254455745 closed this May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants