Prepare ThreadPilot 1.7.0 gaming and signing release (#51)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
namespace ThreadPilot.ViewModels
|
||||
{
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
@@ -104,6 +105,18 @@ namespace ThreadPilot.ViewModels
|
||||
this.HasError = false;
|
||||
}
|
||||
|
||||
protected void OpenExternalLink(string url)
|
||||
{
|
||||
try
|
||||
{
|
||||
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.SetError("Unable to open the link.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
protected async Task ExecuteAsync(Func<Task> operation, string? statusMessage = null, string? successMessage = null)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace ThreadPilot.ViewModels
|
||||
|
||||
public partial class PowerPlanViewModel : BaseViewModel
|
||||
{
|
||||
internal const string MorePlansUrl = "https://discord.gg/EmPfb57Kfr";
|
||||
private readonly IPowerPlanService powerPlanService;
|
||||
private System.Timers.Timer? refreshTimer;
|
||||
private bool isAutoRefreshPaused = true;
|
||||
@@ -133,6 +134,9 @@ namespace ThreadPilot.ViewModels
|
||||
});
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void OpenMorePlans() => this.OpenExternalLink(MorePlansUrl);
|
||||
|
||||
[RelayCommand]
|
||||
public async Task LoadPowerPlans()
|
||||
{
|
||||
|
||||
@@ -145,24 +145,24 @@ namespace ThreadPilot.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
partial void OnSelectedProcessChanged(ProcessModel? value)
|
||||
{
|
||||
this.SetCpuAssignmentMode(
|
||||
this.settingsService?.Settings.DefaultCpuAssignmentMode ?? CpuAssignmentMode.Automatic,
|
||||
overriddenByRule: false);
|
||||
this.UpdateSelectedProcessSummary(value);
|
||||
partial void OnSelectedProcessChanged(ProcessModel? value)
|
||||
{
|
||||
this.SetCpuAssignmentMode(
|
||||
this.settingsService?.Settings.DefaultCpuAssignmentMode ?? CpuAssignmentMode.Automatic,
|
||||
overriddenByRule: false);
|
||||
this.UpdateSelectedProcessSummary(value);
|
||||
|
||||
if (value != null && CpuTopology != null)
|
||||
{
|
||||
this.HasPendingAffinityEdits = false;
|
||||
this.UpdateAffinityDisplayState();
|
||||
// Immediately fetch and display real-time process information
|
||||
TaskSafety.FireAndForget(HandleSelectedProcessChangedAsync(value), ex =>
|
||||
TaskSafety.FireAndForget(HandleSelectedProcessChangedAsync(value), ex =>
|
||||
{
|
||||
this.Logger.LogWarning(ex, "Failed while handling selected process change for {ProcessName}", value.Name);
|
||||
});
|
||||
TaskSafety.FireAndForget(this.ResolveCpuAssignmentModeAsync(value), ex =>
|
||||
this.Logger.LogDebug(ex, "Could not resolve saved CPU assignment mode for {ProcessName}", value.Name));
|
||||
});
|
||||
TaskSafety.FireAndForget(this.ResolveCpuAssignmentModeAsync(value), ex =>
|
||||
this.Logger.LogDebug(ex, "Could not resolve saved CPU assignment mode for {ProcessName}", value.Name));
|
||||
}
|
||||
else if (value == null)
|
||||
{
|
||||
@@ -172,39 +172,39 @@ namespace ThreadPilot.ViewModels
|
||||
|
||||
// Update system tray context menu
|
||||
this.systemTrayService.UpdateContextMenu(value?.Name, value != null);
|
||||
}
|
||||
|
||||
partial void OnSelectedCpuAssignmentModeChanged(CpuAssignmentMode value)
|
||||
{
|
||||
if (!this.suppressCpuAssignmentModeChanges && this.SelectedProcess != null)
|
||||
{
|
||||
this.HasPendingAffinityEdits = true;
|
||||
this.cpuAssignmentModeOverriddenByRule = true;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ResolveCpuAssignmentModeAsync(ProcessModel process)
|
||||
{
|
||||
if (this.persistentRuleStore == null || this.persistentRuleMatcher == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var rules = await this.persistentRuleStore.LoadAsync().ConfigureAwait(false);
|
||||
var rule = rules.FirstOrDefault(candidate => candidate.IsEnabled && this.persistentRuleMatcher.IsMatch(candidate, process));
|
||||
if (rule != null && this.SelectedProcess?.ProcessId == process.ProcessId)
|
||||
{
|
||||
await InvokeOnUiAsync(() => this.SetCpuAssignmentMode(rule.CpuAssignmentMode, overriddenByRule: true));
|
||||
}
|
||||
}
|
||||
|
||||
private void SetCpuAssignmentMode(CpuAssignmentMode mode, bool overriddenByRule)
|
||||
{
|
||||
this.suppressCpuAssignmentModeChanges = true;
|
||||
this.SelectedCpuAssignmentMode = Enum.IsDefined(mode) ? mode : CpuAssignmentMode.Automatic;
|
||||
this.suppressCpuAssignmentModeChanges = false;
|
||||
this.cpuAssignmentModeOverriddenByRule = overriddenByRule;
|
||||
}
|
||||
}
|
||||
|
||||
partial void OnSelectedCpuAssignmentModeChanged(CpuAssignmentMode value)
|
||||
{
|
||||
if (!this.suppressCpuAssignmentModeChanges && this.SelectedProcess != null)
|
||||
{
|
||||
this.HasPendingAffinityEdits = true;
|
||||
this.cpuAssignmentModeOverriddenByRule = true;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ResolveCpuAssignmentModeAsync(ProcessModel process)
|
||||
{
|
||||
if (this.persistentRuleStore == null || this.persistentRuleMatcher == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var rules = await this.persistentRuleStore.LoadAsync().ConfigureAwait(false);
|
||||
var rule = rules.FirstOrDefault(candidate => candidate.IsEnabled && this.persistentRuleMatcher.IsMatch(candidate, process));
|
||||
if (rule != null && this.SelectedProcess?.ProcessId == process.ProcessId)
|
||||
{
|
||||
await InvokeOnUiAsync(() => this.SetCpuAssignmentMode(rule.CpuAssignmentMode, overriddenByRule: true));
|
||||
}
|
||||
}
|
||||
|
||||
private void SetCpuAssignmentMode(CpuAssignmentMode mode, bool overriddenByRule)
|
||||
{
|
||||
this.suppressCpuAssignmentModeChanges = true;
|
||||
this.SelectedCpuAssignmentMode = Enum.IsDefined(mode) ? mode : CpuAssignmentMode.Automatic;
|
||||
this.suppressCpuAssignmentModeChanges = false;
|
||||
this.cpuAssignmentModeOverriddenByRule = overriddenByRule;
|
||||
}
|
||||
|
||||
private void UpdateSelectedProcessSummary(ProcessModel? process)
|
||||
{
|
||||
@@ -546,7 +546,7 @@ namespace ThreadPilot.ViewModels
|
||||
this.PendingAffinityText = pendingMask > 0
|
||||
? $"Pending core mask: 0x{pendingMask:X}"
|
||||
: "Pending core mask: no cores selected";
|
||||
this.AffinityEditStateText = "CPU selection staged. Use Apply CPU Assignment to apply it.";
|
||||
this.AffinityEditStateText = "CPU selection staged. Use Apply CPU Assignment to apply it.";
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
@@ -813,11 +813,13 @@ namespace ThreadPilot.ViewModels
|
||||
var currentCoreSelection = this.HasPendingAffinityEdits && this.CpuCores.Count > 0
|
||||
? this.GetPendingCoreSelectionMask()
|
||||
: null;
|
||||
var result = await this.processRuleCreationService.SaveCurrentSettingsAsRuleAsync(
|
||||
targetProcess,
|
||||
currentCoreSelection,
|
||||
this.SelectedProcessSummary.MemoryPriority,
|
||||
this.SelectedCpuAssignmentMode);
|
||||
var result = await this.processRuleCreationService.SaveCurrentSettingsAsRuleAsync(
|
||||
targetProcess,
|
||||
currentCoreSelection,
|
||||
this.SelectedProcessSummary.MemoryPriority,
|
||||
this.SelectedCpuAssignmentMode,
|
||||
this.SelectedProcessSummary.IoPriority,
|
||||
this.IsIdleServerDisabled);
|
||||
|
||||
this.ApplyRuleCreationResultStatus(result);
|
||||
await this.LogUserActionAsync(
|
||||
@@ -848,24 +850,24 @@ namespace ThreadPilot.ViewModels
|
||||
}
|
||||
|
||||
var pendingSelection = this.GetPendingCoreSelectionMask();
|
||||
var applyResult = await this.processAffinityApplyCoordinator.ApplyCoreSelectionAsync(
|
||||
process,
|
||||
pendingSelection,
|
||||
"Manual Process tab context menu CPU selection",
|
||||
this.SelectedCpuAssignmentMode);
|
||||
var applyResult = await this.processAffinityApplyCoordinator.ApplyCoreSelectionAsync(
|
||||
process,
|
||||
pendingSelection,
|
||||
"Manual Process tab context menu CPU selection",
|
||||
this.SelectedCpuAssignmentMode);
|
||||
|
||||
if (!applyResult.Success)
|
||||
{
|
||||
this.SetContextError(applyResult.Message);
|
||||
await this.LogUserActionAsync(
|
||||
"ProcessCpuAssignmentFailed",
|
||||
applyResult.Message,
|
||||
$"Process: {process.Name}, PID: {process.ProcessId}, RequestedMode: {applyResult.RequestedMode}, EffectiveMode: {applyResult.EffectiveMode}, RequestedMask: 0x{applyResult.RequestedMask:X}");
|
||||
"ProcessCpuAssignmentFailed",
|
||||
applyResult.Message,
|
||||
$"Process: {process.Name}, PID: {process.ProcessId}, RequestedMode: {applyResult.RequestedMode}, EffectiveMode: {applyResult.EffectiveMode}, RequestedMask: 0x{applyResult.RequestedMask:X}");
|
||||
await this.UpdateSelectedProcessSummaryAsync(process);
|
||||
return;
|
||||
}
|
||||
|
||||
if (applyResult.EffectiveMode == CpuAssignmentMode.AffinityMask)
|
||||
if (applyResult.EffectiveMode == CpuAssignmentMode.AffinityMask)
|
||||
{
|
||||
this.UpdateCoreSelections(process.ProcessorAffinity, true);
|
||||
}
|
||||
@@ -875,11 +877,13 @@ namespace ThreadPilot.ViewModels
|
||||
this.HasPendingAffinityEdits = false;
|
||||
this.UpdateAffinityDisplayState();
|
||||
|
||||
var saveResult = await this.processRuleCreationService.SaveCurrentSettingsAsRuleAsync(
|
||||
process,
|
||||
pendingSelection,
|
||||
currentMemoryPriority: null,
|
||||
cpuAssignmentMode: this.SelectedCpuAssignmentMode);
|
||||
var saveResult = await this.processRuleCreationService.SaveCurrentSettingsAsRuleAsync(
|
||||
process,
|
||||
pendingSelection,
|
||||
currentMemoryPriority: null,
|
||||
cpuAssignmentMode: this.SelectedCpuAssignmentMode,
|
||||
currentIoPriority: null,
|
||||
preventSystemSleepWhileRunning: this.IsIdleServerDisabled);
|
||||
|
||||
this.ApplyRuleCreationResultStatus(saveResult);
|
||||
await this.LogUserActionAsync(
|
||||
@@ -913,15 +917,15 @@ namespace ThreadPilot.ViewModels
|
||||
this.SetStatus($"Setting affinity for {selectedProcess.Name}...");
|
||||
});
|
||||
|
||||
var result = await this.processAffinityApplyCoordinator.ApplyCoreSelectionAsync(
|
||||
selectedProcess,
|
||||
pendingSelection,
|
||||
selectionReason,
|
||||
this.SelectedCpuAssignmentMode);
|
||||
var result = await this.processAffinityApplyCoordinator.ApplyCoreSelectionAsync(
|
||||
selectedProcess,
|
||||
pendingSelection,
|
||||
selectionReason,
|
||||
this.SelectedCpuAssignmentMode);
|
||||
|
||||
await InvokeOnUiAsync(() =>
|
||||
{
|
||||
if (result.EffectiveMode == CpuAssignmentMode.AffinityMask)
|
||||
if (result.EffectiveMode == CpuAssignmentMode.AffinityMask)
|
||||
{
|
||||
this.UpdateCoreSelections(selectedProcess.ProcessorAffinity, true);
|
||||
}
|
||||
@@ -933,58 +937,58 @@ namespace ThreadPilot.ViewModels
|
||||
{
|
||||
this.HasPendingAffinityEdits = false;
|
||||
this.UpdateAffinityDisplayState();
|
||||
this.SetStatus($"CPU assignment applied successfully to {selectedProcess.Name} using {result.EffectiveMode}.", false);
|
||||
_ = this.notificationService.ShowNotificationAsync("CPU assignment applied", $"{selectedProcess.Name}: {result.EffectiveMode}", NotificationType.Success);
|
||||
this.SetStatus($"CPU assignment applied successfully to {selectedProcess.Name} using {result.EffectiveMode}.", false);
|
||||
_ = this.notificationService.ShowNotificationAsync("CPU assignment applied", $"{selectedProcess.Name}: {result.EffectiveMode}", NotificationType.Success);
|
||||
}
|
||||
else if (result.FailureReason == AffinityApplyFailureReason.VerificationMismatch)
|
||||
{
|
||||
this.HasPendingAffinityEdits = false;
|
||||
this.UpdateAffinityDisplayState();
|
||||
this.SetStatus(result.Message, false);
|
||||
_ = this.notificationService.ShowNotificationAsync("CPU assignment adjusted", result.Message, NotificationType.Warning);
|
||||
_ = this.notificationService.ShowNotificationAsync("CPU assignment adjusted", result.Message, NotificationType.Warning);
|
||||
}
|
||||
else if (result.FailureReason == AffinityApplyFailureReason.ProcessTerminated)
|
||||
{
|
||||
this.SelectedProcess = null;
|
||||
this.ClearProcessSelection();
|
||||
this.SetCriticalStatus(result.Message);
|
||||
_ = this.notificationService.ShowNotificationAsync("CPU assignment failed", result.Message, NotificationType.Warning);
|
||||
_ = this.notificationService.ShowNotificationAsync("CPU assignment failed", result.Message, NotificationType.Warning);
|
||||
}
|
||||
else if (result.FailureReason == AffinityApplyFailureReason.AccessDenied)
|
||||
{
|
||||
this.SetCriticalStatus(result.Message);
|
||||
_ = this.notificationService.ShowNotificationAsync("CPU assignment blocked", result.Message, NotificationType.Warning);
|
||||
_ = this.notificationService.ShowNotificationAsync("CPU assignment blocked", result.Message, NotificationType.Warning);
|
||||
}
|
||||
else if (result.IsInvalidTopology || result.IsLegacyFallbackBlocked)
|
||||
{
|
||||
this.SetCriticalStatus(result.Message);
|
||||
_ = this.notificationService.ShowNotificationAsync("CPU assignment blocked", result.Message, NotificationType.Warning);
|
||||
_ = this.notificationService.ShowNotificationAsync("CPU assignment blocked", result.Message, NotificationType.Warning);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.SetStatus(result.Message, false);
|
||||
_ = this.notificationService.ShowNotificationAsync("CPU assignment error", result.Message, NotificationType.Error);
|
||||
_ = this.notificationService.ShowNotificationAsync("CPU assignment error", result.Message, NotificationType.Error);
|
||||
}
|
||||
});
|
||||
|
||||
await this.LogUserActionAsync(
|
||||
result.Success ? "ProcessCpuAssignmentApplied" : "ProcessCpuAssignmentFailed",
|
||||
result.Message,
|
||||
$"Process: {selectedProcess.Name}, PID: {selectedProcess.ProcessId}, RequestedMode: {result.RequestedMode}, EffectiveMode: {result.EffectiveMode}, Threads: {result.AppliedThreadCount}, RequestedMask: 0x{result.RequestedMask:X}, VerifiedMask: 0x{result.VerifiedMask:X}");
|
||||
result.Success ? "ProcessCpuAssignmentApplied" : "ProcessCpuAssignmentFailed",
|
||||
result.Message,
|
||||
$"Process: {selectedProcess.Name}, PID: {selectedProcess.ProcessId}, RequestedMode: {result.RequestedMode}, EffectiveMode: {result.EffectiveMode}, Threads: {result.AppliedThreadCount}, RequestedMask: 0x{result.RequestedMask:X}, VerifiedMask: 0x{result.VerifiedMask:X}");
|
||||
await this.UpdateSelectedProcessSummaryAsync(selectedProcess);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var friendly = ex.Message;
|
||||
_ = this.notificationService.ShowNotificationAsync("CPU assignment error", friendly, NotificationType.Error);
|
||||
_ = this.notificationService.ShowNotificationAsync("CPU assignment error", friendly, NotificationType.Error);
|
||||
await this.LogUserActionAsync(
|
||||
"ProcessCpuAssignmentFailed",
|
||||
friendly,
|
||||
$"Process: {selectedProcess.Name}, PID: {selectedProcess.ProcessId}, Mode: {this.SelectedCpuAssignmentMode}");
|
||||
"ProcessCpuAssignmentFailed",
|
||||
friendly,
|
||||
$"Process: {selectedProcess.Name}, PID: {selectedProcess.ProcessId}, Mode: {this.SelectedCpuAssignmentMode}");
|
||||
|
||||
await InvokeOnUiAsync(() =>
|
||||
{
|
||||
this.SetCriticalStatus($"Error applying CPU assignment: {friendly}");
|
||||
this.SetCriticalStatus($"Error applying CPU assignment: {friendly}");
|
||||
});
|
||||
|
||||
// Try to refresh process info even if setting failed, to show current state
|
||||
@@ -1148,10 +1152,6 @@ namespace ThreadPilot.ViewModels
|
||||
"Applying mask '{MaskName}' to process {ProcessName} (PID: {ProcessId})",
|
||||
mask.Name, selectedProcess.Name, selectedProcess.ProcessId);
|
||||
|
||||
// Disable Windows Game Mode for better CPU affinity control
|
||||
// Game Mode can interfere with CPU Sets, particularly on AMD systems
|
||||
await this.gameModeService.DisableGameModeForAffinityAsync();
|
||||
|
||||
var result = await this.processAffinityApplyCoordinator.ApplyCoreMaskAsync(selectedProcess, mask);
|
||||
|
||||
System.Windows.Application.Current.Dispatcher.Invoke(() =>
|
||||
@@ -1231,7 +1231,7 @@ namespace ThreadPilot.ViewModels
|
||||
|
||||
try
|
||||
{
|
||||
var affinityModeChangedOsAffinity = false;
|
||||
var affinityModeChangedOsAffinity = false;
|
||||
|
||||
await System.Windows.Application.Current.Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
@@ -1242,16 +1242,16 @@ namespace ThreadPilot.ViewModels
|
||||
var pendingSelection = this.GetPendingCoreSelectionMask();
|
||||
if (pendingSelection.Any(selected => selected))
|
||||
{
|
||||
var result = await this.processAffinityApplyCoordinator.ApplyCoreSelectionAsync(
|
||||
selectedProcess,
|
||||
pendingSelection,
|
||||
"Manual Process tab quick apply CPU selection",
|
||||
this.SelectedCpuAssignmentMode);
|
||||
var result = await this.processAffinityApplyCoordinator.ApplyCoreSelectionAsync(
|
||||
selectedProcess,
|
||||
pendingSelection,
|
||||
"Manual Process tab quick apply CPU selection",
|
||||
this.SelectedCpuAssignmentMode);
|
||||
if (!result.Success)
|
||||
{
|
||||
await System.Windows.Application.Current.Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
if (result.EffectiveMode == CpuAssignmentMode.AffinityMask)
|
||||
if (result.EffectiveMode == CpuAssignmentMode.AffinityMask)
|
||||
{
|
||||
this.UpdateCoreSelections(selectedProcess.ProcessorAffinity, true);
|
||||
}
|
||||
@@ -1265,7 +1265,7 @@ namespace ThreadPilot.ViewModels
|
||||
|
||||
this.HasPendingAffinityEdits = false;
|
||||
this.UpdateAffinityDisplayState();
|
||||
affinityModeChangedOsAffinity = result.EffectiveMode == CpuAssignmentMode.AffinityMask;
|
||||
affinityModeChangedOsAffinity = result.EffectiveMode == CpuAssignmentMode.AffinityMask;
|
||||
}
|
||||
|
||||
// Apply power plan if selected
|
||||
@@ -1278,7 +1278,7 @@ namespace ThreadPilot.ViewModels
|
||||
|
||||
await System.Windows.Application.Current.Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
if (affinityModeChangedOsAffinity)
|
||||
if (affinityModeChangedOsAffinity)
|
||||
{
|
||||
this.UpdateCoreSelections(selectedProcess.ProcessorAffinity, true);
|
||||
}
|
||||
@@ -1531,6 +1531,22 @@ namespace ThreadPilot.ViewModels
|
||||
private Task SetContextMemoryPriorityNormal(ProcessModel? process) =>
|
||||
this.SetContextMemoryPriorityAsync(process, ProcessMemoryPriority.Normal);
|
||||
|
||||
[RelayCommand]
|
||||
private Task SetContextIoPriorityVeryLow(ProcessModel? process) =>
|
||||
this.SetContextIoPriorityAsync(process, ProcessIoPriority.VeryLow);
|
||||
|
||||
[RelayCommand]
|
||||
private Task SetContextIoPriorityLow(ProcessModel? process) =>
|
||||
this.SetContextIoPriorityAsync(process, ProcessIoPriority.Low);
|
||||
|
||||
[RelayCommand]
|
||||
private Task SetContextIoPriorityNormal(ProcessModel? process) =>
|
||||
this.SetContextIoPriorityAsync(process, ProcessIoPriority.Normal);
|
||||
|
||||
[RelayCommand]
|
||||
private Task SetContextIoPriorityHigh(ProcessModel? process) =>
|
||||
this.SetContextIoPriorityAsync(process, ProcessIoPriority.High);
|
||||
|
||||
[RelayCommand]
|
||||
private async Task ClearContextCpuSets(ProcessModel? process)
|
||||
{
|
||||
@@ -1665,6 +1681,7 @@ namespace ThreadPilot.ViewModels
|
||||
.AppendLine($"Path: {path}")
|
||||
.AppendLine($"CPU priority: {process.Priority}")
|
||||
.AppendLine($"Memory priority: {this.SelectedProcessSummary.MemoryPriority?.ToString() ?? "unavailable"}")
|
||||
.AppendLine($"I/O priority: {this.SelectedProcessSummary.IoPriority?.ToString() ?? "unavailable"}")
|
||||
.AppendLine($"Affinity: 0x{process.ProcessorAffinity:X}")
|
||||
.AppendLine($"Rule status: {this.SelectedProcessSummary.RuleStatusText}");
|
||||
|
||||
@@ -1794,6 +1811,33 @@ namespace ThreadPilot.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SetContextIoPriorityAsync(ProcessModel? process, ProcessIoPriority priority)
|
||||
{
|
||||
if (process == null || this.memoryPriorityService == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var result = await this.memoryPriorityService.SetIoPriorityAsync(process, priority);
|
||||
if (!result.Success)
|
||||
{
|
||||
this.SetContextError(result.UserMessage);
|
||||
await this.LogUserActionAsync(
|
||||
"ProcessIoPriorityFailed",
|
||||
result.UserMessage,
|
||||
$"Process: {process.Name}, PID: {process.ProcessId}, Priority: {priority}");
|
||||
await this.UpdateSelectedProcessSummaryAsync(process);
|
||||
return;
|
||||
}
|
||||
|
||||
this.SetStatus($"I/O priority applied successfully to {process.Name}: {priority}.", false);
|
||||
await this.LogUserActionAsync(
|
||||
"ProcessIoPriorityChanged",
|
||||
$"I/O priority changed for {process.Name}: {priority}",
|
||||
$"PID: {process.ProcessId}");
|
||||
await this.UpdateSelectedProcessSummaryAsync(process);
|
||||
}
|
||||
|
||||
private async Task TryRefreshContextProcessSummaryAsync(ProcessModel process)
|
||||
{
|
||||
try
|
||||
@@ -2230,32 +2274,30 @@ namespace ThreadPilot.ViewModels
|
||||
|
||||
try
|
||||
{
|
||||
this.SetStatus($"{(disable ? "Disabling" : "Enabling")} idle server for {this.SelectedProcess.Name}...");
|
||||
|
||||
// Implementation for disabling/enabling idle server
|
||||
// This typically involves setting process execution state or power management settings
|
||||
var success = await this.processService.SetIdleServerStateAsync(this.SelectedProcess, !disable);
|
||||
this.SetStatus($"{(disable ? "Enabling" : "Disabling")} sleep prevention for {this.SelectedProcess.Name}...");
|
||||
var success = this.powerRequestService != null &&
|
||||
await this.powerRequestService.SetPreventSleepAsync(this.SelectedProcess, disable);
|
||||
|
||||
if (success)
|
||||
{
|
||||
this.SelectedProcess.IsIdleServerDisabled = disable;
|
||||
this.SetStatus($"Idle server {(disable ? "disabled" : "enabled")} for {this.SelectedProcess.Name}");
|
||||
this.SetStatus($"Sleep prevention {(disable ? "enabled" : "disabled")} for {this.SelectedProcess.Name}");
|
||||
|
||||
await this.LogUserActionAsync(
|
||||
"IdleServer",
|
||||
$"Idle server {(disable ? "disabled" : "enabled")} for process {this.SelectedProcess.Name}",
|
||||
"ProcessSleepPrevention",
|
||||
$"Sleep prevention {(disable ? "enabled" : "disabled")} for process {this.SelectedProcess.Name}",
|
||||
$"PID: {this.SelectedProcess.ProcessId}");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.SetStatus($"Failed to {(disable ? "disable" : "enable")} idle server for {this.SelectedProcess.Name}", false);
|
||||
this.SetStatus($"Failed to {(disable ? "enable" : "disable")} sleep prevention for {this.SelectedProcess.Name}", false);
|
||||
// Revert the UI state
|
||||
this.IsIdleServerDisabled = !disable;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Logger.LogError(ex, "Error toggling idle server for process {ProcessName}", this.SelectedProcess.Name);
|
||||
this.Logger.LogError(ex, "Error toggling sleep prevention for process {ProcessName}", this.SelectedProcess.Name);
|
||||
this.SetStatus($"Error: {ex.Message}", false);
|
||||
// Revert the UI state
|
||||
this.IsIdleServerDisabled = !disable;
|
||||
|
||||
@@ -32,10 +32,11 @@ namespace ThreadPilot.ViewModels
|
||||
private readonly IAffinityApplyService affinityApplyService;
|
||||
private readonly IProcessAffinityApplyCoordinator processAffinityApplyCoordinator;
|
||||
private readonly IProcessMemoryPriorityService? memoryPriorityService;
|
||||
private readonly ProcessPowerRequestService? powerRequestService;
|
||||
private readonly IProcessRuleCreationService? processRuleCreationService;
|
||||
private readonly IApplicationSettingsService? settingsService;
|
||||
private readonly IPersistentProcessRuleStore? persistentRuleStore;
|
||||
private readonly IPersistentProcessRuleMatcher? persistentRuleMatcher;
|
||||
private readonly IApplicationSettingsService? settingsService;
|
||||
private readonly IPersistentProcessRuleStore? persistentRuleStore;
|
||||
private readonly IPersistentProcessRuleMatcher? persistentRuleMatcher;
|
||||
private readonly Action<string> clipboardSetter;
|
||||
private readonly Action<string> executableLocationOpener;
|
||||
private System.Timers.Timer? refreshTimer;
|
||||
@@ -47,9 +48,9 @@ namespace ThreadPilot.ViewModels
|
||||
private readonly ThrottledRefreshCoordinator filterRefreshCoordinator;
|
||||
private bool isApplyingFilter;
|
||||
private bool filterRefreshPending;
|
||||
private bool suppressCoreSelectionEvents;
|
||||
private bool suppressCpuAssignmentModeChanges;
|
||||
private bool cpuAssignmentModeOverriddenByRule;
|
||||
private bool suppressCoreSelectionEvents;
|
||||
private bool suppressCpuAssignmentModeChanges;
|
||||
private bool cpuAssignmentModeOverriddenByRule;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool isAutomationMonitoringEnabled = true;
|
||||
@@ -105,10 +106,10 @@ namespace ThreadPilot.ViewModels
|
||||
private string topologyStatus = "Detecting CPU topology...";
|
||||
|
||||
[ObservableProperty]
|
||||
private bool areAdvancedFeaturesAvailable = false;
|
||||
|
||||
[ObservableProperty]
|
||||
private CpuAssignmentMode selectedCpuAssignmentMode = CpuAssignmentMode.Automatic;
|
||||
private bool areAdvancedFeaturesAvailable = false;
|
||||
|
||||
[ObservableProperty]
|
||||
private CpuAssignmentMode selectedCpuAssignmentMode = CpuAssignmentMode.Automatic;
|
||||
|
||||
[ObservableProperty]
|
||||
private PowerPlanModel? selectedPowerPlan;
|
||||
@@ -194,7 +195,8 @@ namespace ThreadPilot.ViewModels
|
||||
Action<string>? clipboardSetter = null,
|
||||
Action<string>? executableLocationOpener = null,
|
||||
ILocalizationService? localizationService = null,
|
||||
IApplicationSettingsService? settingsService = null)
|
||||
IApplicationSettingsService? settingsService = null,
|
||||
ProcessPowerRequestService? powerRequestService = null)
|
||||
: base(logger, enhancedLoggingService, activityAuditService)
|
||||
{
|
||||
this.processService = processService ?? throw new ArgumentNullException(nameof(processService));
|
||||
@@ -217,10 +219,11 @@ namespace ThreadPilot.ViewModels
|
||||
new CpuSelectionMigrationService(),
|
||||
NullLogger<ProcessAffinityApplyCoordinator>.Instance);
|
||||
this.memoryPriorityService = memoryPriorityService;
|
||||
this.settingsService = settingsService;
|
||||
this.persistentRuleStore = persistentRuleStore;
|
||||
this.persistentRuleMatcher = persistentRuleMatcher;
|
||||
this.SelectedCpuAssignmentMode = settingsService?.Settings.DefaultCpuAssignmentMode ?? CpuAssignmentMode.Automatic;
|
||||
this.powerRequestService = powerRequestService;
|
||||
this.settingsService = settingsService;
|
||||
this.persistentRuleStore = persistentRuleStore;
|
||||
this.persistentRuleMatcher = persistentRuleMatcher;
|
||||
this.SelectedCpuAssignmentMode = settingsService?.Settings.DefaultCpuAssignmentMode ?? CpuAssignmentMode.Automatic;
|
||||
this.IsAutomationMonitoringEnabled = settingsService?.Settings.EnableAutomationMonitoring ?? true;
|
||||
if (settingsService != null)
|
||||
{
|
||||
@@ -265,11 +268,11 @@ namespace ThreadPilot.ViewModels
|
||||
|
||||
private void OnSettingsChanged(object? sender, ApplicationSettingsChangedEventArgs e)
|
||||
{
|
||||
this.IsAutomationMonitoringEnabled = e.NewSettings.EnableAutomationMonitoring;
|
||||
if (!this.cpuAssignmentModeOverriddenByRule)
|
||||
{
|
||||
this.SetCpuAssignmentMode(e.NewSettings.DefaultCpuAssignmentMode, overriddenByRule: false);
|
||||
}
|
||||
this.IsAutomationMonitoringEnabled = e.NewSettings.EnableAutomationMonitoring;
|
||||
if (!this.cpuAssignmentModeOverriddenByRule)
|
||||
{
|
||||
this.SetCpuAssignmentMode(e.NewSettings.DefaultCpuAssignmentMode, overriddenByRule: false);
|
||||
}
|
||||
if (!this.IsAutomationMonitoringEnabled)
|
||||
{
|
||||
this.SetUiRefreshEnabled(false, refreshImmediately: false);
|
||||
|
||||
@@ -24,12 +24,14 @@ namespace ThreadPilot.ViewModels
|
||||
private ProcessPriorityClass cpuPriority;
|
||||
private long processorAffinity;
|
||||
private ProcessMemoryPriority? memoryPriority;
|
||||
private ProcessIoPriority? ioPriority;
|
||||
private string processTitle = "No process selected";
|
||||
private string currentProcessStatusText = "No process selected";
|
||||
private string cpuUsageText = "CPU: unavailable";
|
||||
private string memoryUsageText = "Memory: unavailable";
|
||||
private string cpuPriorityText = "CPU priority: unavailable";
|
||||
private string memoryPriorityText = "Memory priority unavailable";
|
||||
private string ioPriorityText = "I/O priority unavailable";
|
||||
private string affinityText = "Affinity: unavailable";
|
||||
private string ruleStatusText = "No saved rule";
|
||||
private string lastOperationMessage = "No recent ThreadPilot action";
|
||||
@@ -105,6 +107,12 @@ namespace ThreadPilot.ViewModels
|
||||
private set => this.SetProperty(ref this.memoryPriority, value);
|
||||
}
|
||||
|
||||
public ProcessIoPriority? IoPriority
|
||||
{
|
||||
get => this.ioPriority;
|
||||
private set => this.SetProperty(ref this.ioPriority, value);
|
||||
}
|
||||
|
||||
public string ProcessTitle
|
||||
{
|
||||
get => this.processTitle;
|
||||
@@ -141,6 +149,12 @@ namespace ThreadPilot.ViewModels
|
||||
private set => this.SetProperty(ref this.memoryPriorityText, value);
|
||||
}
|
||||
|
||||
public string IoPriorityText
|
||||
{
|
||||
get => this.ioPriorityText;
|
||||
private set => this.SetProperty(ref this.ioPriorityText, value);
|
||||
}
|
||||
|
||||
public string AffinityText
|
||||
{
|
||||
get => this.affinityText;
|
||||
@@ -214,6 +228,12 @@ namespace ThreadPilot.ViewModels
|
||||
return;
|
||||
}
|
||||
|
||||
await this.UpdateIoPriorityAsync(process, version);
|
||||
if (!this.IsCurrentVersion(version))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await this.UpdateRuleStatusAsync(process, version);
|
||||
}
|
||||
|
||||
@@ -244,6 +264,7 @@ namespace ThreadPilot.ViewModels
|
||||
this.CpuPriority = default;
|
||||
this.ProcessorAffinity = 0;
|
||||
this.MemoryPriority = null;
|
||||
this.IoPriority = null;
|
||||
this.IsProtectedOrAccessDenied = false;
|
||||
this.HasThreadPilotRule = false;
|
||||
this.ProcessTitle = this.L("ProcessView_NoProcessSelected", "No process selected");
|
||||
@@ -252,6 +273,7 @@ namespace ThreadPilot.ViewModels
|
||||
this.MemoryUsageText = this.L("ProcessSummary_MemoryUnavailable", "Memory: unavailable");
|
||||
this.CpuPriorityText = this.L("ProcessSummary_CpuPriorityUnavailable", "CPU priority: unavailable");
|
||||
this.MemoryPriorityText = this.L("ProcessSummary_MemoryPriorityUnavailable", "Memory priority unavailable");
|
||||
this.IoPriorityText = this.L("ProcessSummary_IoPriorityUnavailable", "I/O priority unavailable");
|
||||
this.AffinityText = this.L("ProcessSummary_AffinityUnavailable", "Affinity: unavailable");
|
||||
this.RuleStatusText = this.L("ProcessSummary_NoSavedRule", "No saved rule");
|
||||
this.UpdateLastOperation(lastOperationMessage, lastOperationIsError);
|
||||
@@ -295,6 +317,32 @@ namespace ThreadPilot.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
private async Task UpdateIoPriorityAsync(ProcessModel process, int version)
|
||||
{
|
||||
this.IoPriority = null;
|
||||
this.IoPriorityText = this.L("ProcessSummary_IoPriorityUnavailable", "I/O priority unavailable");
|
||||
if (this.memoryPriorityService == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var priority = await this.memoryPriorityService.GetIoPriorityAsync(process);
|
||||
if (!this.IsCurrentVersion(version) || priority == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.IoPriority = priority.Value;
|
||||
this.IoPriorityText = this.L("ProcessSummary_IoPriorityFormat", "I/O priority: {0}", priority.Value);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
this.IoPriority = null;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task UpdateRuleStatusAsync(ProcessModel process, int version)
|
||||
{
|
||||
this.HasThreadPilotRule = false;
|
||||
|
||||
@@ -21,6 +21,8 @@ namespace ThreadPilot.ViewModels
|
||||
|
||||
public partial class SettingsViewModel : BaseViewModel
|
||||
{
|
||||
internal const string DiscordUrl = "https://discord.gg/VYwkCbr4vH";
|
||||
internal const string IssuesUrl = "https://github.com/PrimeBuild-pc/ThreadPilot/issues";
|
||||
private readonly IApplicationSettingsService settingsService;
|
||||
private readonly INotificationService notificationService;
|
||||
private readonly IAutostartService autostartService;
|
||||
@@ -31,8 +33,8 @@ namespace ThreadPilot.ViewModels
|
||||
private readonly ISystemTrayService systemTrayService;
|
||||
private readonly IUpdateService updateService;
|
||||
private readonly IApplicationVersionProvider versionProvider;
|
||||
private readonly ILocalizationService localizationService;
|
||||
private readonly ICpuTopologyProvider? cpuTopologyProvider;
|
||||
private readonly ILocalizationService localizationService;
|
||||
private readonly ICpuTopologyProvider? cpuTopologyProvider;
|
||||
private ApplicationSettingsModel savedSettingsSnapshot;
|
||||
private bool isSyncingFromService = false;
|
||||
private bool? appliedThemePreference;
|
||||
@@ -88,11 +90,11 @@ namespace ThreadPilot.ViewModels
|
||||
[ObservableProperty]
|
||||
private string lastUpdateCheckText = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool isUpdateAvailable = false;
|
||||
|
||||
[ObservableProperty]
|
||||
private string reservedCpuSetsStatus = string.Empty;
|
||||
[ObservableProperty]
|
||||
private bool isUpdateAvailable = false;
|
||||
|
||||
[ObservableProperty]
|
||||
private string reservedCpuSetsStatus = string.Empty;
|
||||
|
||||
public bool CanDownloadAndInstallUpdate => this.IsUpdateAvailable && !this.IsLoading;
|
||||
|
||||
@@ -108,10 +110,10 @@ namespace ThreadPilot.ViewModels
|
||||
ISystemTrayService systemTrayService,
|
||||
IUpdateService updateService,
|
||||
IApplicationVersionProvider versionProvider,
|
||||
ILocalizationService localizationService,
|
||||
IEnhancedLoggingService? enhancedLoggingService = null,
|
||||
IActivityAuditService? activityAuditService = null,
|
||||
ICpuTopologyProvider? cpuTopologyProvider = null)
|
||||
ILocalizationService localizationService,
|
||||
IEnhancedLoggingService? enhancedLoggingService = null,
|
||||
IActivityAuditService? activityAuditService = null,
|
||||
ICpuTopologyProvider? cpuTopologyProvider = null)
|
||||
: base(logger, enhancedLoggingService, activityAuditService)
|
||||
{
|
||||
this.settingsService = settingsService ?? throw new ArgumentNullException(nameof(settingsService));
|
||||
@@ -124,8 +126,8 @@ namespace ThreadPilot.ViewModels
|
||||
this.systemTrayService = systemTrayService ?? throw new ArgumentNullException(nameof(systemTrayService));
|
||||
this.updateService = updateService ?? throw new ArgumentNullException(nameof(updateService));
|
||||
this.versionProvider = versionProvider ?? throw new ArgumentNullException(nameof(versionProvider));
|
||||
this.localizationService = localizationService ?? throw new ArgumentNullException(nameof(localizationService));
|
||||
this.cpuTopologyProvider = cpuTopologyProvider;
|
||||
this.localizationService = localizationService ?? throw new ArgumentNullException(nameof(localizationService));
|
||||
this.cpuTopologyProvider = cpuTopologyProvider;
|
||||
|
||||
this.ApplicationVersion = this.versionProvider.DisplayVersion;
|
||||
|
||||
@@ -133,8 +135,8 @@ namespace ThreadPilot.ViewModels
|
||||
this.settings = (ApplicationSettingsModel)this.settingsService.Settings.Clone();
|
||||
this.savedSettingsSnapshot = (ApplicationSettingsModel)this.settings.Clone();
|
||||
this.appliedThemePreference = this.settings.UseDarkTheme;
|
||||
this.LatestUpdateVersion = this.GetLocalizedString("Settings_UpdateNotChecked", "Not checked");
|
||||
this.ReservedCpuSetsStatus = this.GetLocalizedString("SettingsView_ReservedCpuSetsUnknown", "Reserved CPU Sets: status unavailable.");
|
||||
this.LatestUpdateVersion = this.GetLocalizedString("Settings_UpdateNotChecked", "Not checked");
|
||||
this.ReservedCpuSetsStatus = this.GetLocalizedString("SettingsView_ReservedCpuSetsUnknown", "Reserved CPU Sets: status unavailable.");
|
||||
this.UpdateLastCheckedText();
|
||||
|
||||
// Initialize commands
|
||||
@@ -158,36 +160,42 @@ namespace ThreadPilot.ViewModels
|
||||
this.Logger.LogInformation("Settings ViewModel initialized");
|
||||
}
|
||||
|
||||
public override async Task InitializeAsync()
|
||||
{
|
||||
await this.RefreshSettingsAsync();
|
||||
await this.RefreshPowerPlansAsync();
|
||||
await this.RefreshReservedCpuSetsStatusAsync();
|
||||
}
|
||||
|
||||
private async Task RefreshReservedCpuSetsStatusAsync()
|
||||
{
|
||||
if (this.cpuTopologyProvider == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var topology = await this.cpuTopologyProvider.GetTopologySnapshotAsync();
|
||||
this.ReservedCpuSetsStatus = topology.ReservedLogicalProcessorIndexes.Count == 0
|
||||
? this.GetLocalizedString("SettingsView_ReservedCpuSetsNone", "Reserved CPU Sets: none detected.")
|
||||
: this.GetLocalizedString(
|
||||
"SettingsView_ReservedCpuSetsDetectedFormat",
|
||||
"Reserved CPU Sets detected on logical processors: {0}.",
|
||||
string.Join(", ", topology.ReservedLogicalProcessorIndexes));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Logger.LogDebug(ex, "Could not read reserved CPU Set state");
|
||||
this.ReservedCpuSetsStatus = this.GetLocalizedString("SettingsView_ReservedCpuSetsUnknown", "Reserved CPU Sets: status unavailable.");
|
||||
}
|
||||
}
|
||||
public override async Task InitializeAsync()
|
||||
{
|
||||
await this.RefreshSettingsAsync();
|
||||
await this.RefreshPowerPlansAsync();
|
||||
await this.RefreshReservedCpuSetsStatusAsync();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void OpenDiscord() => this.OpenExternalLink(DiscordUrl);
|
||||
|
||||
[RelayCommand]
|
||||
private void ReportIssue() => this.OpenExternalLink(IssuesUrl);
|
||||
|
||||
private async Task RefreshReservedCpuSetsStatusAsync()
|
||||
{
|
||||
if (this.cpuTopologyProvider == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var topology = await this.cpuTopologyProvider.GetTopologySnapshotAsync();
|
||||
this.ReservedCpuSetsStatus = topology.ReservedLogicalProcessorIndexes.Count == 0
|
||||
? this.GetLocalizedString("SettingsView_ReservedCpuSetsNone", "Reserved CPU Sets: none detected.")
|
||||
: this.GetLocalizedString(
|
||||
"SettingsView_ReservedCpuSetsDetectedFormat",
|
||||
"Reserved CPU Sets detected on logical processors: {0}.",
|
||||
string.Join(", ", topology.ReservedLogicalProcessorIndexes));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Logger.LogDebug(ex, "Could not read reserved CPU Set state");
|
||||
this.ReservedCpuSetsStatus = this.GetLocalizedString("SettingsView_ReservedCpuSetsUnknown", "Reserved CPU Sets: status unavailable.");
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSettingsPropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
|
||||
@@ -50,7 +50,9 @@ namespace ThreadPilot.ViewModels
|
||||
Enum.GetValues<SystemTweak>().Select(type => new SystemTweakItem
|
||||
{
|
||||
TweakType = type,
|
||||
IsGuidedAction = type is SystemTweak.MemoryIntegrity or SystemTweak.Hags or SystemTweak.WindowedOptimizations,
|
||||
ToggleCommand = new AsyncRelayCommand<SystemTweakItem>(this.ToggleTweakAsync),
|
||||
ActionCommand = new AsyncRelayCommand<SystemTweakItem>(this.OpenTweakSettingsAsync),
|
||||
}));
|
||||
this.ApplyLocalizedTweakText();
|
||||
}
|
||||
@@ -105,8 +107,20 @@ namespace ThreadPilot.ViewModels
|
||||
{
|
||||
TweakStatus status = item.TweakType switch
|
||||
{
|
||||
SystemTweak.GameMode => await this.systemTweaksService.GetGameModeStatusAsync(),
|
||||
SystemTweak.CoreParking => await this.systemTweaksService.GetCoreParkingStatusAsync(),
|
||||
SystemTweak.CStates => await this.systemTweaksService.GetCStatesStatusAsync(),
|
||||
SystemTweak.MemoryIntegrity => await this.systemTweaksService.GetMemoryIntegrityStatusAsync(),
|
||||
SystemTweak.Hags or SystemTweak.WindowedOptimizations => new TweakStatus
|
||||
{
|
||||
IsAvailable = true,
|
||||
StatusText = this.Localize("SystemTweaks_StatusManagedByWindows", "Managed by Windows"),
|
||||
},
|
||||
SystemTweak.UsbSelectiveSuspend => await this.systemTweaksService.GetUsbSelectiveSuspendStatusAsync(),
|
||||
SystemTweak.PointerPrecision => await this.systemTweaksService.GetPointerPrecisionStatusAsync(),
|
||||
SystemTweak.EthernetPowerSaving => await this.systemTweaksService.GetEthernetPowerSavingStatusAsync(),
|
||||
SystemTweak.InterruptModeration => await this.systemTweaksService.GetInterruptModerationStatusAsync(),
|
||||
SystemTweak.GpuMsiMode => await this.systemTweaksService.GetGpuMsiModeStatusAsync(),
|
||||
SystemTweak.SysMain => await this.systemTweaksService.GetSysMainStatusAsync(),
|
||||
SystemTweak.Prefetch => await this.systemTweaksService.GetPrefetchStatusAsync(),
|
||||
SystemTweak.PowerThrottling => await this.systemTweaksService.GetPowerThrottlingStatusAsync(),
|
||||
@@ -118,6 +132,7 @@ namespace ThreadPilot.ViewModels
|
||||
item.IsEnabled = status.IsEnabled;
|
||||
item.IsAvailable = status.IsAvailable;
|
||||
item.ErrorMessage = status.ErrorMessage;
|
||||
item.StatusText = status.StatusText ?? this.GetStatusText(status);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -144,8 +159,14 @@ namespace ThreadPilot.ViewModels
|
||||
var newState = !item.IsEnabled;
|
||||
bool success = item.TweakType switch
|
||||
{
|
||||
SystemTweak.GameMode => await this.systemTweaksService.SetGameModeAsync(newState),
|
||||
SystemTweak.CoreParking => await this.systemTweaksService.SetCoreParkingAsync(newState),
|
||||
SystemTweak.CStates => await this.systemTweaksService.SetCStatesAsync(newState),
|
||||
SystemTweak.UsbSelectiveSuspend => await this.systemTweaksService.SetUsbSelectiveSuspendAsync(newState),
|
||||
SystemTweak.PointerPrecision => await this.systemTweaksService.SetPointerPrecisionAsync(newState),
|
||||
SystemTweak.EthernetPowerSaving => await this.systemTweaksService.SetEthernetPowerSavingAsync(newState),
|
||||
SystemTweak.InterruptModeration => await this.systemTweaksService.SetInterruptModerationAsync(newState),
|
||||
SystemTweak.GpuMsiMode => await this.systemTweaksService.SetGpuMsiModeAsync(newState),
|
||||
SystemTweak.SysMain => await this.systemTweaksService.SetSysMainAsync(newState),
|
||||
SystemTweak.Prefetch => await this.systemTweaksService.SetPrefetchAsync(newState),
|
||||
SystemTweak.PowerThrottling => await this.systemTweaksService.SetPowerThrottlingAsync(newState),
|
||||
@@ -209,6 +230,18 @@ namespace ThreadPilot.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
private async Task OpenTweakSettingsAsync(SystemTweakItem? item)
|
||||
{
|
||||
if (item == null || !await this.systemTweaksService.OpenSettingsAsync(item.TweakType))
|
||||
{
|
||||
this.SetError(this.Localize("SystemTweaks_StatusOpenSettingsFailed", "Could not open Windows settings"), null);
|
||||
return;
|
||||
}
|
||||
|
||||
this.SetStatus(this.Localize("SystemTweaks_StatusSettingsOpenedFormat", "Opened settings for {0}", item.Name));
|
||||
await this.LogUserActionAsync("SystemTweakSettingsOpened", $"Opened settings for {item.Name}", item.TweakType.ToString());
|
||||
}
|
||||
|
||||
private static Task InvokeOnUiAsync(Action action)
|
||||
{
|
||||
var dispatcher = System.Windows.Application.Current?.Dispatcher;
|
||||
@@ -227,8 +260,17 @@ namespace ThreadPilot.ViewModels
|
||||
{
|
||||
var text = item.TweakType switch
|
||||
{
|
||||
SystemTweak.GameMode => ("SystemTweak_GameMode_Name", "Game Mode", "SystemTweak_GameMode_Desc", "Windows Game Mode scheduling optimizations"),
|
||||
SystemTweak.CoreParking => ("SystemTweak_CoreParking_Name", "Core Parking", "SystemTweak_CoreParking_Desc", "Controls CPU core parking for power management"),
|
||||
SystemTweak.CStates => ("SystemTweak_CStates_Name", "C-States", "SystemTweak_CStates_Desc", "Controls CPU C-States for power management"),
|
||||
SystemTweak.MemoryIntegrity => ("SystemTweak_MemoryIntegrity_Name", "Memory Integrity (HVCI)", "SystemTweak_MemoryIntegrity_Desc", "Opens Windows Security. Disabling this protection reduces system security and may require a restart."),
|
||||
SystemTweak.Hags => ("SystemTweak_Hags_Name", "Hardware-accelerated GPU scheduling", "SystemTweak_Hags_Desc", "Opens Windows graphics settings to let you review HAGS."),
|
||||
SystemTweak.WindowedOptimizations => ("SystemTweak_WindowedOptimizations_Name", "Optimizations for windowed games", "SystemTweak_WindowedOptimizations_Desc", "Opens Windows graphics settings to manage Flip Model optimizations."),
|
||||
SystemTweak.UsbSelectiveSuspend => ("SystemTweak_UsbSelectiveSuspend_Name", "USB Selective Suspend", "SystemTweak_UsbSelectiveSuspend_Desc", "Controls USB selective suspend for the active power plan while plugged in."),
|
||||
SystemTweak.PointerPrecision => ("SystemTweak_PointerPrecision_Name", "Enhance pointer precision", "SystemTweak_PointerPrecision_Desc", "Controls Windows mouse acceleration."),
|
||||
SystemTweak.EthernetPowerSaving => ("SystemTweak_EthernetPowerSaving_Name", "Disable Ethernet power saving", "SystemTweak_EthernetPowerSaving_Desc", "Disables supported EEE, Green Ethernet and power-saving driver properties on physical Ethernet adapters."),
|
||||
SystemTweak.InterruptModeration => ("SystemTweak_InterruptModeration_Name", "Disable interrupt moderation", "SystemTweak_InterruptModeration_Desc", "Can reduce Ethernet latency at the cost of higher CPU and interrupt load."),
|
||||
SystemTweak.GpuMsiMode => ("SystemTweak_GpuMsiMode_Name", "GPU MSI Mode", "SystemTweak_GpuMsiMode_Desc", "Controls MSI only when the display driver already exposes MSISupported. A restart is required."),
|
||||
SystemTweak.SysMain => ("SystemTweak_SysMain_Name", "SysMain Service", "SystemTweak_SysMain_Desc", "Windows SysMain service for memory management"),
|
||||
SystemTweak.Prefetch => ("SystemTweak_Prefetch_Name", "Prefetch", "SystemTweak_Prefetch_Desc", "Windows Prefetch for faster application loading"),
|
||||
SystemTweak.PowerThrottling => ("SystemTweak_PowerThrottling_Name", "Power Throttling", "SystemTweak_PowerThrottling_Desc", "Turns off Windows Power Throttling for sustained performance"),
|
||||
@@ -239,6 +281,10 @@ namespace ThreadPilot.ViewModels
|
||||
|
||||
item.Name = this.Localize(text.Item1, text.Item2);
|
||||
item.Description = this.Localize(text.Item3, text.Item4);
|
||||
if (!string.IsNullOrEmpty(item.StatusText) && item.TweakType is not SystemTweak.Hags and not SystemTweak.WindowedOptimizations)
|
||||
{
|
||||
item.StatusText = this.GetStatusText(new TweakStatus { IsAvailable = item.IsAvailable, IsEnabled = item.IsEnabled });
|
||||
}
|
||||
}
|
||||
|
||||
this.RefreshStatusText = this.Localize("SystemTweaks_StatusReady", "Ready");
|
||||
@@ -255,6 +301,10 @@ namespace ThreadPilot.ViewModels
|
||||
: string.Format(CultureInfo.CurrentCulture, format, arguments);
|
||||
}
|
||||
|
||||
private string GetStatusText(TweakStatus status) => !status.IsAvailable
|
||||
? this.Localize("SystemTweaks_StatusNotAvailable", "Not available")
|
||||
: this.Localize(status.IsEnabled ? "SystemTweaks_StatusEnabled" : "SystemTweaks_StatusDisabled", status.IsEnabled ? "Enabled" : "Disabled");
|
||||
|
||||
private void OnLanguageChanged(object? sender, string language) => this.ApplyLocalizedTweakText();
|
||||
|
||||
private void OnTweakStatusChanged(object? sender, TweakStatusChangedEventArgs e)
|
||||
@@ -267,6 +317,7 @@ namespace ThreadPilot.ViewModels
|
||||
item.IsEnabled = e.Status.IsEnabled;
|
||||
item.IsAvailable = e.Status.IsAvailable;
|
||||
item.ErrorMessage = e.Status.ErrorMessage;
|
||||
item.StatusText = e.Status.StatusText ?? this.GetStatusText(e.Status);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -303,6 +354,14 @@ namespace ThreadPilot.ViewModels
|
||||
[ObservableProperty]
|
||||
private string? errorMessage;
|
||||
|
||||
[ObservableProperty]
|
||||
private string statusText = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool isGuidedAction;
|
||||
|
||||
public IAsyncRelayCommand<SystemTweakItem>? ToggleCommand { get; set; }
|
||||
|
||||
public IAsyncRelayCommand<SystemTweakItem>? ActionCommand { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user