Skip to content

feat(msgbox): 重构消息弹窗服务#3267

Draft
whitecat346 wants to merge 3 commits into
devfrom
refactor/msgbox-service
Draft

feat(msgbox): 重构消息弹窗服务#3267
whitecat346 wants to merge 3 commits into
devfrom
refactor/msgbox-service

Conversation

@whitecat346

@whitecat346 whitecat346 commented Jun 27, 2026

Copy link
Copy Markdown
Member

Important

还在编写阶段,等待其他人把迁移和MVVM部分写完

这个PR提供了一个新的事件驱动的消息弹窗系统,并重构了之前的消息弹窗为MVVM模式。

Summary by Sourcery

引入基于事件驱动、服务化的消息框系统,并将其集成到现有的配置错误处理流程中。

新功能:

  • 添加集中式的 MsgBoxService,提供异步和同步 API,通过基于通道的请求/响应模型显示消息框。
  • 定义核心消息框领域类型,包括请求/响应模型、按钮元数据以及主题枚举。
  • 引入 UI 侧的 MsgBoxActor,在 WPF UI 线程上渲染和管理消息框控件,并支持取消和超时。

改进:

  • 更新配置文件保存错误的处理逻辑,以使用新的消息框系统,并改进显示错误消息的格式。
Original summary in English

Summary by Sourcery

Introduce an event-driven, service-based message box system and integrate it with existing configuration error handling.

New Features:

  • Add a centralized MsgBoxService with async and synchronous APIs for showing message boxes via a channel-based request/response model.
  • Define core message box domain types, including request/response models, button metadata, and theme enumeration.
  • Introduce a UI MsgBoxActor to render and manage message box controls on the WPF UI thread with cancellation and timeout support.

Enhancements:

  • Update configuration file save error handling to use the new message box system and improve the formatting of the displayed error message.

@pcl-ce-automation pcl-ce-automation Bot added 🚧 正在处理 开发人员正在对该内容进行开发、测试或修复,进展中 size: L PR 大小评估:大型 labels Jun 27, 2026
@sourcery-ai

sourcery-ai Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

审阅者指南

引入了一个事件驱动、支持 MVVM 的消息框基础设施,由基于通道的服务和 UI 端 actor 提供支持,并更新了配置保存错误处理逻辑,使其使用新的请求模型和原始字符串字面量。

文件级更改

变更 详情 文件
引入一个基于通道、感知生命周期的消息框服务,支持异步和同步使用。
  • 创建 MsgBoxService,包含一个静态的 Channel<MsgBoxRequest> 和一个以 Guid 为键的待处理请求 ConcurrentDictionary。
  • 实现 ShowAsync,接入超时和外部取消令牌,将请求入队到通道中,并通过 TaskCompletionSource 等待完成。
  • 实现 Show,使用 dispatcher 在 UI 线程上同步阻塞,或在非 UI 线程上回退到 Task.Run 加 ShowAsync。
  • 对 UI 公开一个用于消费的 ChannelReader,并提供 Complete 方法用于 UI 端解析/完成待处理请求。
  • 添加生命周期停止钩子,在关闭期间完成通道并取消所有待处理请求。
PCL.Core/App/Essentials/MsgBoxService.cs
添加 UI 端 actor,用于消费消息框请求并协调 WPF 控件与取消逻辑。
  • 实现 MsgBoxActor,在后台任务中从 MsgBoxService.Reader 读取,并将 UI 工作切换到 WPF dispatcher。
  • 针对每个请求创建并显示 IMsgBoxControl 实例,切换共享背景元素可见性并运行显示/关闭动画。
  • 跟踪每个请求的 CancellationTokenRegistration 实例,以支持超时/外部取消以及由取消触发的控件关闭。
  • 在控件完成时,调用按钮回调,清理注册,带动画关闭,并将完成状态回传给 MsgBoxService。
  • 提供 CancelRequest 逻辑,通过 RequestId 查找控件,并以 Cancelled 响应完成它们。
Plain Craft Launcher 2/Modules/UI/MsgBoxActor.cs
为新的消息框系统定义请求/响应以及 UI 抽象类型。
  • 添加 MsgBoxRequest 记录类型,包含标题、消息、主题、按钮描述、阻塞标记、取消令牌以及可选的超时。
  • 添加 MsgBoxResponse 记录类型,包含 RequestId、可选按钮值及按钮元数据,并提供用于生成已取消响应的工厂方法。
  • 添加 MsgBoxButtonInfo 记录类型,用于描述按钮文本、语义值以及可选的点击回调。
  • 添加 IMsgBoxControl 接口,供 UI 控件实现,包括底层请求、Completed 事件以及动画生命周期方法。
  • 添加 MsgBoxTheme 枚举,包含 Info、Warning 和 Error 变体。
PCL.Core/UI/MsgBox/MsgBoxRequest.cs
PCL.Core/UI/MsgBox/MsgBoxResponse.cs
PCL.Core/UI/MsgBox/MsgBoxButtonInfo.cs
PCL.Core/UI/MsgBox/IMsgBoxControl.cs
PCL.Core/UI/MsgBox/MsgBoxTheme.cs
优化配置保存错误处理逻辑,在继续使用消息框系统的同时,改为使用原始字符串字面量格式化。
  • 将 FileConfigStorage.Sync 中多行错误提示字符串转换为 C# 原始字符串字面量,以获得更清晰的格式和内嵌换行。
  • 重新排序 using 指令,将 PCL.Core 命名空间分组放在 System 命名空间之前,而不改变行为。
PCL.Core/App/Configuration/Storage/FileConfigStorage.cs

技巧与命令

与 Sourcery 交互

  • 触发新审阅: 在 pull request 上评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 从审阅评论生成 GitHub issue: 在某条审阅评论下回复,要求 Sourcery 从该评论创建 issue。你也可以直接在审阅评论中回复 @sourcery-ai issue 来从该评论创建 issue。
  • 生成 pull request 标题: 在 pull request 标题中任意位置写入 @sourcery-ai,即可随时生成标题。你也可以在 pull request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 pull request 摘要: 在 pull request 正文任意位置写入 @sourcery-ai summary,即可在你想要的位置生成 PR 摘要。你也可以在 pull request 中评论 @sourcery-ai summary 来(重新)生成摘要。
  • 生成审阅者指南: 在 pull request 中评论 @sourcery-ai guide,即可随时(重新)生成审阅者指南。
  • 解决所有 Sourcery 评论: 在 pull request 中评论 @sourcery-ai resolve,将标记解决所有 Sourcery 评论。如果你已经处理完所有评论且不想再看到它们,这会很有用。
  • 撤销所有 Sourcery 审阅: 在 pull request 中评论 @sourcery-ai dismiss,将撤销所有现有的 Sourcery 审阅。特别适合你想从一次全新的审阅开始时——别忘了评论 @sourcery-ai review 来触发新的审阅!

自定义你的体验

访问你的 控制面板 以:

  • 启用或禁用审阅功能,例如 Sourcery 自动生成的 pull request 摘要、审阅者指南等。
  • 更改审阅语言。
  • 添加、移除或编辑自定义审阅指令。
  • 调整其他审阅设置。

获取帮助

Original review guide in English

Reviewer's Guide

Introduces an event-driven, MVVM-ready message box infrastructure backed by a channel-based service and a UI-side actor, and updates config save error handling to use the new request model and raw string literals.

File-Level Changes

Change Details Files
Introduce a channel-backed, lifecycle-aware message box service for async and sync usage.
  • Create MsgBoxService with a static Channel and a ConcurrentDictionary of pending requests keyed by Guid.
  • Implement ShowAsync that wires timeout and external cancellation tokens, enqueues requests into the channel, and awaits completion via TaskCompletionSource.
  • Implement Show that uses the dispatcher to synchronously block on UI thread or falls back to Task.Run plus ShowAsync for non-UI threads.
  • Expose a ChannelReader for UI consumption and a Complete method for UI to resolve pending requests.
  • Add lifecycle stop hook to complete the channel and cancel all pending requests during shutdown.
PCL.Core/App/Essentials/MsgBoxService.cs
Add UI-side actor to consume message box requests and coordinate WPF controls and cancellation.
  • Implement MsgBoxActor that reads from MsgBoxService.Reader in a background task and marshals UI work to the WPF dispatcher.
  • Create and show IMsgBoxControl instances per request, toggling a shared background element visibility and running show/close animations.
  • Track per-request CancellationTokenRegistration instances to support timeout/external cancellation and cancellation-triggered closing of controls.
  • On control completion, invoke button callbacks, clean up registrations, close with animation, and report completion back to MsgBoxService.
  • Provide CancelRequest logic to locate controls by RequestId and complete them with a Cancelled response.
Plain Craft Launcher 2/Modules/UI/MsgBoxActor.cs
Define the request/response and UI abstraction types for the new message box system.
  • Add MsgBoxRequest record with title, message, theme, button descriptors, blocking flag, cancellation token, and optional timeout.
  • Add MsgBoxResponse record with RequestId, optional button value, and button metadata plus a factory for cancelled responses.
  • Add MsgBoxButtonInfo record describing button text, semantic value, and an optional click callback.
  • Add IMsgBoxControl interface for UI controls, including the underlying request, a Completed event, and animation lifecycle methods.
  • Add MsgBoxTheme enum with Info, Warning, and Error variants.
PCL.Core/UI/MsgBox/MsgBoxRequest.cs
PCL.Core/UI/MsgBox/MsgBoxResponse.cs
PCL.Core/UI/MsgBox/MsgBoxButtonInfo.cs
PCL.Core/UI/MsgBox/IMsgBoxControl.cs
PCL.Core/UI/MsgBox/MsgBoxTheme.cs
Refine config save error handling to use raw string literal formatting while still leveraging the message box system.
  • Convert the multi-line error hint string in FileConfigStorage.Sync to a C# raw string literal for clearer formatting and embedded newlines.
  • Reorder using directives to group PCL.Core namespaces before System namespaces without changing behavior.
PCL.Core/App/Configuration/Storage/FileConfigStorage.cs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@whitecat346 whitecat346 changed the title feat(msgbox); 添加新的消息弹窗服务 feat(msgbox): 重构消息弹窗服务 Jun 27, 2026
@pcl-ce-automation pcl-ce-automation Bot added size: XXL PR 大小评估:巨型 and removed size: L PR 大小评估:大型 labels Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: XXL PR 大小评估:巨型 🚧 正在处理 开发人员正在对该内容进行开发、测试或修复,进展中

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants