fix: reset process changes on exit before the monitor stops tracking them
Stopping the process monitor untracks every process it changed, so the "reset on exit" step that ran afterwards always found nothing to reset (default-on setting, broken since before 1.7.7).
This commit is contained in:
committed by
Prime Build
parent
2af91100e5
commit
ea62c08d81
@@ -710,7 +710,7 @@ namespace ThreadPilot
|
||||
this.LogDebug("Starting graceful shutdown...");
|
||||
this.selfResourceManagementService.RestoreForegroundMode();
|
||||
|
||||
// 1. Stop monitoring services; Game Boost first restores what it changed
|
||||
// 1. Game Boost restores what it changed
|
||||
try
|
||||
{
|
||||
await this.serviceProvider.GetRequiredService<IGameSessionService>().StopAsync();
|
||||
@@ -720,18 +720,7 @@ namespace ThreadPilot
|
||||
this.LogDebug($"Error stopping Game Boost: {ex.Message}");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
this.LogDebug("Stopping process monitoring manager...");
|
||||
await this.processMonitorManagerService.StopAsync();
|
||||
this.LogDebug("Process monitoring manager stopped");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.LogDebug($"Error stopping process monitoring: {ex.Message}");
|
||||
}
|
||||
|
||||
// 2. Cleanup applied CPU masks (like CPU Set Setter's ClearAllProcessMasksNoSave)
|
||||
// 2. Reset tracked masks/priorities before the monitor stops: stopping it untracks every process
|
||||
if (this.settingsService.Settings.ClearMasksOnClose)
|
||||
{
|
||||
try
|
||||
@@ -760,6 +749,17 @@ namespace ThreadPilot
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
this.LogDebug("Stopping process monitoring manager...");
|
||||
await this.processMonitorManagerService.StopAsync();
|
||||
this.LogDebug("Process monitoring manager stopped");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.LogDebug($"Error stopping process monitoring: {ex.Message}");
|
||||
}
|
||||
|
||||
// 3. Restore default power plan if configured
|
||||
if (this.settingsService.Settings.RestoreDefaultPowerPlanOnExit)
|
||||
{
|
||||
|
||||
@@ -16,6 +16,21 @@ namespace ThreadPilot.Core.Tests
|
||||
Assert.Contains("this.initializedSections.Add(\"Tweaks\");", startupSection, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Shutdown_ResetsTrackedChangesBeforeTheMonitorForgetsThem()
|
||||
{
|
||||
// ProcessMonitorManagerService.StopAsync untracks every process it changed, so
|
||||
// "reset process changes on exit" found nothing to reset when it ran afterwards.
|
||||
var source = File.ReadAllText(GetRepositoryFilePath("MainWindow.Behaviors.partial.cs"));
|
||||
var start = source.IndexOf("private async Task PerformGracefulShutdownAsync(", StringComparison.Ordinal);
|
||||
var shutdown = source[start..source.IndexOf("// 3. Restore default power plan", start, StringComparison.Ordinal)];
|
||||
|
||||
var reset = shutdown.IndexOf("await processService.ClearAllAppliedMasksAsync();", StringComparison.Ordinal);
|
||||
var stopMonitor = shutdown.IndexOf("await this.processMonitorManagerService.StopAsync();", StringComparison.Ordinal);
|
||||
Assert.True(reset >= 0 && stopMonitor >= 0);
|
||||
Assert.True(reset < stopMonitor);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TweaksView_UsesWindows11ToggleWithStateLabel()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user