refactor: decouple hardware logic from UI#78
Open
shihuaidexianyu wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR advances the “decouple hardware logic from UI” refactor by introducing a small service/model layer (hardware control, GPU ops, presets/config, hardware monitor parsing) and rewiring Program.* UI/event code to call those services instead of directly handling registry/process/GPU UI side-effects.
Changes:
- Added service-layer wrappers (
HardwareControlService,GpuService,PresetService,AppSettingsService) and supporting models (OperationResult,PresetSettings,HardwareMonitorSnapshot,MonitorSettings). - Extracted the
--hwmonitorchild-process lifecycle + parsing intoHardwareMonitorService, withProgramsubscribing via events. - Added a lightweight non-framework test runner project covering the new models/services.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/OmenSuperHub.Tests/Program.cs | Adds a simple console-based test runner for new service/model logic. |
| Tests/OmenSuperHub.Tests/OmenSuperHub.Tests.csproj | New test project compiling selected app sources via linked files. |
| Program.Services.cs | Centralizes service instances + shared helpers (preset capture/apply, GPU warning UI, monitor snapshot handler). |
| Program.Menu.cs | Switches UI menu actions to call the new services instead of direct hardware/GPU helpers. |
| Program.cs | Replaces inline hwmonitor process management with HardwareMonitorService usage and initializes services. |
| Program.Config.cs | Routes registry/preset logic through AppSettingsService + PresetService; routes hardware calls through HardwareControlService. |
| OmenSuperHub.csproj | Adds compilation entries for the new services/models and Program.Services.cs. |
| App/Services/PresetService.cs | Encapsulates preset field loading and built-in preset defaults creation. |
| App/Services/HardwareMonitorService.cs | New service managing the --hwmonitor subprocess and emitting parsed snapshots. |
| App/Services/HardwareControlService.cs | Wrapper around OmenHardware static APIs. |
| App/Services/GpuService.cs | Wrapper around GpuAppManager GPU operations. |
| App/Services/AppSettingsService.cs | Encapsulates registry key access and typed value reads. |
| App/Models/PresetSettings.cs | Data container for preset fields plus cloning. |
| App/Models/OperationResult.cs | Standard success/failure result type for service operations. |
| App/Models/MonitorSettings.cs | Normalizes monitor refresh rate and maps to interval. |
| App/Models/HardwareMonitorSnapshot.cs | Parses invariant-culture hwmonitor output into a typed snapshot. |
| App/GpuAppManager.cs | Removes WinForms UI dependencies for GPU operations; returns OperationResult for UI to decide presentation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+10
to
+14
| private StreamWriter _input; | ||
| private bool _stopping; | ||
| private bool _cpuEnabled; | ||
| private bool _gpuEnabled; | ||
| private int _intervalMs = 1000; |
Comment on lines
+33
to
+36
| public void Start(bool cpuEnabled, bool gpuEnabled, int intervalMs) { | ||
| _cpuEnabled = cpuEnabled; | ||
| _gpuEnabled = gpuEnabled; | ||
| _intervalMs = intervalMs > 0 ? intervalMs : 1000; |
Comment on lines
+38
to
+52
| if (IsRunning) | ||
| return; | ||
|
|
||
| _process = new Process { | ||
| StartInfo = new ProcessStartInfo { | ||
| FileName = _executablePath, | ||
| Arguments = "--hwmonitor", | ||
| UseShellExecute = false, | ||
| RedirectStandardInput = true, | ||
| RedirectStandardOutput = true, | ||
| RedirectStandardError = true, | ||
| CreateNoWindow = true, | ||
| WindowStyle = ProcessWindowStyle.Hidden | ||
| } | ||
| }; |
Comment on lines
+67
to
+71
| } catch (Exception ex) { | ||
| _input = null; | ||
| _process = null; | ||
| OnError("Start failed: " + ex.Message); | ||
| } |
Comment on lines
+101
to
+105
| public void Dispose() { | ||
| Stop(); | ||
| if (_process != null) | ||
| _process.Dispose(); | ||
| } |
Comment on lines
+123
to
+135
| private void OnExited(object sender, EventArgs e) { | ||
| if (_stopping) { | ||
| _stopping = false; | ||
| return; | ||
| } | ||
|
|
||
| Task.Delay(3000).ContinueWith(_ => { | ||
| try { | ||
| Start(_cpuEnabled, _gpuEnabled, _intervalMs); | ||
| } catch { | ||
| } | ||
| }); | ||
| } |
Contributor
Author
|
我修复一下合并冲突。 |
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.
close #77