Skip to content

refactor: decouple hardware logic from UI#78

Open
shihuaidexianyu wants to merge 2 commits into
breadeding:masterfrom
shihuaidexianyu:master
Open

refactor: decouple hardware logic from UI#78
shihuaidexianyu wants to merge 2 commits into
breadeding:masterfrom
shihuaidexianyu:master

Conversation

@shihuaidexianyu

Copy link
Copy Markdown
Contributor

close #77

Copilot AI review requested due to automatic review settings June 18, 2026 04:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 --hwmonitor child-process lifecycle + parsing into HardwareMonitorService, with Program subscribing 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 {
}
});
}
@shihuaidexianyu

Copy link
Copy Markdown
Contributor Author

我修复一下合并冲突。
主要是做了一些逻辑的解耦合,没有改动原有的功能,因为看到issue中以后可能会有做gui的计划。

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.

结构化升级:解耦硬件逻辑与 UI 层,为后续主界面重构做准备

2 participants