Skip to content

feat: 添加上下文事件驱动的InfoBar提醒 - #2365

Merged
ShadowLemoon merged 2 commits into
mainfrom
feat/show-audio-device-error
Jun 22, 2026
Merged

feat: 添加上下文事件驱动的InfoBar提醒#2365
ShadowLemoon merged 2 commits into
mainfrom
feat/show-audio-device-error

Conversation

@ShadowLemoon

@ShadowLemoon ShadowLemoon commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator
  • feat: 添加上下文事件驱动的InfoBar提醒
  • feat: 音频录制异常时显示通知

Summary by CodeRabbit

发布说明

  • 新功能

    • 新增上下文通知系统,支持信息、成功、警告、错误四种级别的通知。
    • 主窗口已集成通知栏,自动将上下文通知展示为可关闭的提示信息。
  • 改进

    • 音频录制异常时会触发告警通知,并停止相关“声音闪避”功能。
  • 稳定性

    • 优化上下文事件监听/移除的异常处理方式,提升事件管理的可靠性。

@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f7727099-912e-4d70-94de-e82175393a10

📥 Commits

Reviewing files that changed from the base of the PR and between 1706ae8 and 660f93f.

📒 Files selected for processing (1)
  • src/zzz_od/auto_battle/auto_battle_dodge_context.py

📝 Walkthrough

Walkthrough

新增 ContextNotifyEvent 通知事件契约(含四级枚举与四个构造方法),重构 ContextEventItem@dataclass;Qt 主窗口通过 Qt 信号将事件转发到主线程并以 InfoBar 展示;AudioRecorder 新增 error_callback,录制失败时派发 warning 通知。

Changes

上下文通知系统

Layer / File(s) Summary
事件基础结构重构与通知事件契约
src/one_dragon/base/operation/context_event_bus.py, src/one_dragon/base/operation/context_notify_event.py
ContextEventItem 改为 @dataclasscallbacks 类型标注更新为原生 listunlisten_event 改用 contextlib.suppress;新增 ContextNotifyLevelEnum 枚举与 ContextNotifyEvent 数据类,提供 info/success/warning/error 四个构造类方法。
Qt 主窗口通知信号转发与 InfoBar 展示
src/one_dragon_qt/windows/main_app_window_base.py
新增 context_notify_signal 信号,__init__ 中保存 ctx 引用并订阅通知事件;_emit_context_notify 将事件转发至主线程,_show_context_notify 使用 InfoBar.new 在右上角展示 5000ms 可关闭通知。
AudioRecorder 错误回调与 warning 通知派发
src/zzz_od/auto_battle/auto_battle_dodge_context.py
AudioRecorder.__init__ 新增可选 error_callback_record_loop 增加 try/except/finally 捕获 RuntimeError 并调用回调;AutoBattleDodgeContext 传入 _on_audio_record_error,通过 ctx.dispatch_event 派发 ContextNotifyEvent.warning 通知。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 兔兔敲敲键盘忙,
通知事件添新装;
音频出错莫惊慌,
右上角弹窗亮堂堂。
InfoBar 闪烁告知你,
声音闪避暂停档~ 🎵

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.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标题准确概括了主要变更:添加上下文事件驱动的InfoBar提醒功能,与整个changeset的核心目标相符。
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/show-audio-device-error

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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 `@src/one_dragon_qt/windows/main_app_window_base.py`:
- Line 55: The event listener registered on line 55 using
`self.ctx.listen_event(ContextNotifyEvent.EVENT_ID, self._emit_context_notify)`
is never unbound when the window is destroyed, causing a resource leak. In the
`closeEvent` method of either `MainAppWindowBase` or its subclass `AppWindow`,
add explicit event cleanup by calling `self.ctx.unlisten_all_event(self)` or the
corresponding `unlisten_event` method after the existing cleanup calls like
`pip_btn.dispose()` and `overlay_manager.shutdown()`. This ensures consistency
with the resource cleanup pattern used in other UI components throughout the
codebase.

In `@src/zzz_od/auto_battle/auto_battle_dodge_context.py`:
- Around line 89-92: The microphone initialization code that calls
sc.get_microphone() and _mic.recorder() on lines 89-91 is currently positioned
outside the try block. Move these initialization statements into the try block
so that if an error occurs during microphone or recorder initialization, the
_error_callback will be executed and self.running will be properly reset in the
finally block. This ensures proper error handling and state cleanup for
initialization failures, preventing the running state from being left in an
inconsistent state that would block subsequent microphone starts.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4aa00f94-4702-47c6-b5bf-4e6e2cb79fc7

📥 Commits

Reviewing files that changed from the base of the PR and between b145539 and 1706ae8.

📒 Files selected for processing (4)
  • src/one_dragon/base/operation/context_event_bus.py
  • src/one_dragon/base/operation/context_notify_event.py
  • src/one_dragon_qt/windows/main_app_window_base.py
  • src/zzz_od/auto_battle/auto_battle_dodge_context.py

Comment thread src/one_dragon_qt/windows/main_app_window_base.py
Comment thread src/zzz_od/auto_battle/auto_battle_dodge_context.py Outdated
@ShadowLemoon
ShadowLemoon force-pushed the feat/show-audio-device-error branch from 1706ae8 to 660f93f Compare June 22, 2026 08:11
@ShadowLemoon
ShadowLemoon merged commit 660f93f into main Jun 22, 2026
8 checks passed
@ShadowLemoon
ShadowLemoon deleted the feat/show-audio-device-error branch June 22, 2026 08:17
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jun 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant