Skip to content

修复硬件采集兼容性并优化任务栏显示屏选择#413

Open
mengstill wants to merge 3 commits intoDiorser:masterfrom
mengstill:fix/hardware-taskbar-stability
Open

修复硬件采集兼容性并优化任务栏显示屏选择#413
mengstill wants to merge 3 commits intoDiorser:masterfrom
mengstill:fix/hardware-taskbar-stability

Conversation

@mengstill
Copy link
Copy Markdown

改动说明\n\n这次提交主要处理了两类问题:\n\n1. 修复部分机器上 CPU/GPU 硬件采集异常的问题\n- 将 LibreHardwareMonitorLib 升级到

Copilot AI review requested due to automatic review settings April 23, 2026 07:33
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

该 PR 旨在提升硬件采集在部分机器上的兼容性,并重构任务栏小组件的“显示屏选择”逻辑,以支持多屏/多实例显示,同时补充诊断能力与发布/安装相关配置。

Changes:

  • 为 LibreHardwareMonitor 的 Computer.Open() 增加兼容模式兜底,并加入可开关的硬件树诊断日志输出。
  • 任务栏小组件从单实例改为按目标屏幕创建多个 TaskbarForm,并在设置页改为多选式屏幕选择 UI。
  • 增加 Inno Setup 安装脚本、调整发布为单文件相关 csproj 配置,并升级 LibreHardwareMonitorLib 版本。

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/UI/TaskbarForm.cs 构造函数增加目标屏幕参数,并将目标设备透传给业务助手
src/UI/Settings/TaskbarPage.cs 新增“显示屏选择”分组与多选屏幕逻辑,替代原 combo 选择
src/UI/MainForm_Transparent.cs 由单个任务栏窗体改为按设备名管理多个任务栏窗体
src/UI/Helpers/TaskbarWinHelper.cs 调整二屏任务栏句柄查找的回退行为
src/UI/Helpers/TaskbarBizHelper.cs 以构造参数固定目标屏幕,避免运行时依赖全局配置
src/System/HardwareServices/SensorMap.cs 新增环境变量开关的硬件诊断日志输出
src/System/HardwareMonitor.cs Computer.Open() 包装为安全打开并在特定异常下兼容执行
src/Core/Settings.cs 新增多屏选择相关配置字段
src/Core/Actions/SettingsChanger.cs 合并设置时对 TaskbarMonitorDevices 做深拷贝
resources/lang/*.json 增加显示屏选择相关多语言文案
build/LiteMonitor.iss 新增 Inno Setup 安装脚本
LiteMonitor.csproj 发布单文件相关配置 + 升级 LibreHardwareMonitorLib 引用版本

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


// ==== 任务栏显示 ====
private TaskbarForm? _taskbar;
private readonly Dictionary<string, TaskbarForm> _taskbars = new();
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

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

这里使用了大小写敏感的 Dictionary,但上面 staleKeys/desiredDevices 的比较是 OrdinalIgnoreCase;如果配置里的 DeviceName 大小写不一致,会出现旧 key 不会被移除且 TryGetValue 取不到,导致同一屏幕创建多个 TaskbarForm。建议把 _taskbars 初始化为 new Dictionary<string, TaskbarForm>(StringComparer.OrdinalIgnoreCase),并确保所有 key 使用同一规范化形式。

Suggested change
private readonly Dictionary<string, TaskbarForm> _taskbars = new();
private readonly Dictionary<string, TaskbarForm> _taskbars = new(StringComparer.OrdinalIgnoreCase);

Copilot uses AI. Check for mistakes.
Comment on lines 215 to +218
if (screen.Bounds.Contains(r.Location) || screen.Bounds.IntersectsWith(r))
return hWnd;
}
return FindWindow("Shell_TrayWnd", null);
return IntPtr.Zero;
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

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

FindSecondaryTaskbar 找不到二屏任务栏时现在返回 IntPtr.Zero;上层仍会创建并 Show TaskbarForm,但由于 AttachToTaskbar 直接 return,窗口可能以普通无边框窗体的形式浮在屏幕左上角/不可预期位置。建议在 FindHandles/ToggleTaskbar 层面检测二屏无任务栏(例如 Windows 未开启“在所有显示器上显示任务栏”)时:要么回退到主任务栏,要么不要创建该 device 的 TaskbarForm 并给出提示。

Copilot uses AI. Check for mistakes.
};
RegisterRefresh(() => chkAuto.Checked = GetSelectedDevices().Count == 0);
_monitorChecks.Add(chkAuto);
group.AddItem(new LiteSettingsItem(LanguageManager.T("Menu.TaskbarMonitor"), chkAuto));
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

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

自动模式的这一行当前使用了标题 Menu.TaskbarMonitor,右侧只有一个“Enable”复选框,界面上看不出这是“Auto”。建议把该条目的 label 改为 Menu.Auto(或新增明确的“Auto mode”文案),避免用户误解这一行的含义。

Suggested change
group.AddItem(new LiteSettingsItem(LanguageManager.T("Menu.TaskbarMonitor"), chkAuto));
group.AddItem(new LiteSettingsItem(strAuto, chkAuto));

Copilot uses AI. Check for mistakes.
Comment on lines +169 to +176
Config.TaskbarMonitorDevices.Clear();
Config.TaskbarMonitorDevice = "";
Config.TaskbarShowOnAllScreens = false;

foreach (var check in _monitorChecks.Where(x => !ReferenceEquals(x, chkAuto)))
{
if (check.Checked) check.Checked = false;
}
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

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

TaskbarShowOnAllScreens 在该页面逻辑里只会被置为 false(自动/单屏选择时都会清掉),但代码里没有任何地方能把它设为 true;同时语言包新增了 TaskbarAllScreens 也没有被使用。建议:要么在这里补一个“Show On All Screens”的开关并与 TaskbarMonitorDevices/Auto 互斥;要么删除 TaskbarShowOnAllScreens 分支与对应文案,避免死配置项。

Copilot uses AI. Check for mistakes.
Comment on lines +326 to +330
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, "hardware_diagnostic.log"), sb.ToString(), Encoding.UTF8);
}
catch
{
}
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

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

诊断日志写入位置使用 AppContext.BaseDirectory:应用安装到 Program Files 时通常没有写权限,开启 LITEMONITOR_DIAG=1 也可能无法生成日志且异常被吞掉。建议改为写到用户可写目录(如 %LOCALAPPDATA%/LiteMonitor%TEMP%),并至少在 catch 中输出 Debug/Trace 信息方便定位。

Copilot uses AI. Check for mistakes.
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