feat(homepage): 支持自定义主页局部更新#2829
Open
Remygred wants to merge 4 commits into
Open
Conversation
审阅者指南为本地自定义主页新增一个轻量级实时补丁(live patch)机制,用于监听一个 JSON 文件的增量更新,并将其应用到带有特定 Tag 的 UI 元素上,而无需整页刷新。 自定义主页实时补丁应用的时序图sequenceDiagram
actor ExternalTool
participant OSFileSystem
participant PageLaunchRight
participant HomepageLiveWatcher
participant BackgroundThread
participant UIThread
PageLaunchRight->>PageLaunchRight: EnsureHomepageLiveWatcher
PageLaunchRight->>OSFileSystem: WriteHomepageLiveSupportMarker
PageLaunchRight->>HomepageLiveWatcher: FileSystemWatcher(..., CustomLive.json)
HomepageLiveWatcher-->>HomepageLiveWatcher: EnableRaisingEvents = true
PageLaunchRight->>PageLaunchRight: QueueHomepageLivePatchApply
ExternalTool->>OSFileSystem: write CustomLive.json
OSFileSystem-->>HomepageLiveWatcher: Changed/Created/Renamed
HomepageLiveWatcher->>PageLaunchRight: QueueHomepageLivePatchApply
PageLaunchRight->>BackgroundThread: ModBase.RunInNewThread
BackgroundThread-->>BackgroundThread: Thread.Sleep(120)
BackgroundThread->>UIThread: ModBase.RunInUi(ApplyHomepageLivePatchesFromFile)
UIThread->>PageLaunchRight: ApplyHomepageLivePatchesFromFile
PageLaunchRight->>OSFileSystem: ReadHomepageLivePatchFile
PageLaunchRight->>PageLaunchRight: EnumerateHomepageLivePatches
loop patches
PageLaunchRight->>PageLaunchRight: ApplyHomepageLivePatch
PageLaunchRight->>PageLaunchRight: FindElementsByTag
PageLaunchRight->>PageLaunchRight: ApplyHomepageLivePatchToElement
alt childrenXaml present
PageLaunchRight->>PageLaunchRight: ReplacePanelChildren
end
end
文件级变更
可能关联的问题
提示与命令与 Sourcery 交互
自定义你的体验访问你的 控制面板 以:
获取帮助Original review guide in EnglishReviewer's GuideAdds a lightweight live patch mechanism for the local custom homepage that watches a JSON file for incremental updates and applies them to tagged UI elements without reloading the entire page. Sequence diagram for custom homepage live patch applicationsequenceDiagram
actor ExternalTool
participant OSFileSystem
participant PageLaunchRight
participant HomepageLiveWatcher
participant BackgroundThread
participant UIThread
PageLaunchRight->>PageLaunchRight: EnsureHomepageLiveWatcher
PageLaunchRight->>OSFileSystem: WriteHomepageLiveSupportMarker
PageLaunchRight->>HomepageLiveWatcher: FileSystemWatcher(..., CustomLive.json)
HomepageLiveWatcher-->>HomepageLiveWatcher: EnableRaisingEvents = true
PageLaunchRight->>PageLaunchRight: QueueHomepageLivePatchApply
ExternalTool->>OSFileSystem: write CustomLive.json
OSFileSystem-->>HomepageLiveWatcher: Changed/Created/Renamed
HomepageLiveWatcher->>PageLaunchRight: QueueHomepageLivePatchApply
PageLaunchRight->>BackgroundThread: ModBase.RunInNewThread
BackgroundThread-->>BackgroundThread: Thread.Sleep(120)
BackgroundThread->>UIThread: ModBase.RunInUi(ApplyHomepageLivePatchesFromFile)
UIThread->>PageLaunchRight: ApplyHomepageLivePatchesFromFile
PageLaunchRight->>OSFileSystem: ReadHomepageLivePatchFile
PageLaunchRight->>PageLaunchRight: EnumerateHomepageLivePatches
loop patches
PageLaunchRight->>PageLaunchRight: ApplyHomepageLivePatch
PageLaunchRight->>PageLaunchRight: FindElementsByTag
PageLaunchRight->>PageLaunchRight: ApplyHomepageLivePatchToElement
alt childrenXaml present
PageLaunchRight->>PageLaunchRight: ReplacePanelChildren
end
end
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - 我在这里给出了一些整体性的反馈:
- 在
TrySetElementProperty中,解析数值和枚举类型时建议使用CultureInfo.InvariantCulture(以及对应的TryParse变体),以避免在外部工具提供了意外格式时出现依赖区域性的失败或直接抛出异常。 - 当前
FileSystemWatcher的回调是在后台线程里通过Thread.Sleep来做防抖;改为在 UI 线程上使用DispatcherTimer,或使用一个统一的防抖机制,会简化逻辑,并避免每一波变更都额外创建线程。 - 在
DisposeHomepageLiveWatcher和DeleteHomepageLiveSupportMarker中,所有异常都被吞掉了;至少对意料之外的释放/标记失败进行日志记录,会让诊断实时补丁机制的问题更容易,同时不会影响用户可见的行为。
给 AI 代理的提示(Prompt)
Please address the comments from this code review:
## Overall Comments
- In `TrySetElementProperty`, consider using `CultureInfo.InvariantCulture` (and `TryParse` variants) when parsing numeric and enum values to avoid culture-dependent failures or hard exceptions when external tools provide unexpected formats.
- The `FileSystemWatcher` callbacks currently debounce via `Thread.Sleep` in a background thread; using a `DispatcherTimer` or a central debounce mechanism on the UI thread would simplify the logic and avoid extra threads per burst of changes.
- In `DisposeHomepageLiveWatcher` and `DeleteHomepageLiveSupportMarker`, all exceptions are swallowed; logging at least unexpected disposal/marker failures would make diagnosing issues with the live patch mechanism easier without affecting user-facing behavior.帮我变得更有用!请在每条评论上点选 👍 或 👎,我会根据你的反馈改进后续的 Review。
Original comment in English
Hey - I've left some high level feedback:
- In
TrySetElementProperty, consider usingCultureInfo.InvariantCulture(andTryParsevariants) when parsing numeric and enum values to avoid culture-dependent failures or hard exceptions when external tools provide unexpected formats. - The
FileSystemWatchercallbacks currently debounce viaThread.Sleepin a background thread; using aDispatcherTimeror a central debounce mechanism on the UI thread would simplify the logic and avoid extra threads per burst of changes. - In
DisposeHomepageLiveWatcherandDeleteHomepageLiveSupportMarker, all exceptions are swallowed; logging at least unexpected disposal/marker failures would make diagnosing issues with the live patch mechanism easier without affecting user-facing behavior.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `TrySetElementProperty`, consider using `CultureInfo.InvariantCulture` (and `TryParse` variants) when parsing numeric and enum values to avoid culture-dependent failures or hard exceptions when external tools provide unexpected formats.
- The `FileSystemWatcher` callbacks currently debounce via `Thread.Sleep` in a background thread; using a `DispatcherTimer` or a central debounce mechanism on the UI thread would simplify the logic and avoid extra threads per burst of changes.
- In `DisposeHomepageLiveWatcher` and `DeleteHomepageLiveSupportMarker`, all exceptions are swallowed; logging at least unexpected disposal/marker failures would make diagnosing issues with the live patch mechanism easier without affecting user-facing behavior.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Chiloven945
requested changes
May 15, 2026
Contributor
Chiloven945
left a comment
There was a problem hiding this comment.
方法命名规范请遵守 Wiki/技术规范。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
本 PR 为本地自定义主页增加一个轻量的 live patch 机制,让外部辅助程序可以在不刷新整个主页的情况下更新指定控件内容。
主要变化:
Custom.xaml主页启用时监听PCL/CustomLive.json。CustomLive.supported.json,用于让外部程序判断当前启动器是否支持局部更新。Tag匹配目标元素。Text、Title、Info、ToolTip、Visibility、IsEnabled、Opacity。childrenXaml替换目标Panel的子元素。适用场景
该机制适合需要动态更新自定义主页局部内容的场景,例如:
相比直接触发整页刷新,这可以减少主页跳动、折叠状态丢失、滚动位置变化等问题。
Review 反馈处理
根据反馈已补充以下调整:
TrySetElementProperty中数值解析改为使用CultureInfo.InvariantCulture和TryParse,枚举解析改为Enum.TryParse,避免外部工具传入异常格式时受区域设置影响或直接抛出。FileSystemWatcher的变更防抖改为 UI 线程上的DispatcherTimer,避免每轮文件变更额外创建后台线程。DisposeHomepageLiveWatcher与DeleteHomepageLiveSupportMarker不再静默吞掉异常,会将释放 watcher / 删除支持标记失败写入 Developer 日志,方便诊断 live patch 问题。附带修复
HintCustomCommand实际为 bool 配置,现在会按 bool 写入并兼容旧字符串值。验证
已执行:
结果:构建通过,0 个错误。项目现有 warning 仍存在。
Summary by Sourcery
为自定义主页添加实时补丁机制,在无需重新加载整个页面的情况下更新特定控件。
New Features:
Enhancements:
Original summary in English
Summary by Sourcery
Add a live patch mechanism for the custom homepage that updates specific controls without reloading the entire page.
New Features:
Enhancements: