Enable low-impact background mode by default
This commit is contained in:
@@ -605,6 +605,7 @@ namespace ThreadPilot
|
||||
try
|
||||
{
|
||||
this.LogDebug("Starting graceful shutdown...");
|
||||
this.selfResourceManagementService.RestoreForegroundMode();
|
||||
|
||||
// 1. Stop monitoring services
|
||||
try
|
||||
@@ -1425,9 +1426,12 @@ namespace ThreadPilot
|
||||
var currentSettings = settings ?? this.settingsService.Settings;
|
||||
var isHiddenState = state is AppActivityState.Minimized or AppActivityState.TrayHidden;
|
||||
|
||||
if (isHiddenState && currentSettings.EnableSelfLowImpactMode)
|
||||
if (SelfResourcePolicy.ShouldApplyLowImpactMode(isHiddenState, currentSettings.EnableSelfLowImpactMode))
|
||||
{
|
||||
this.selfResourceManagementService.ApplyLowImpactMode(currentSettings.EnableSelfAffinityLimit);
|
||||
this.selfResourceManagementService.ApplyLowImpactMode(SelfResourcePolicy.ShouldLimitAffinity(
|
||||
isHiddenState,
|
||||
currentSettings.EnableSelfLowImpactMode,
|
||||
currentSettings.EnableSelfAffinityLimit));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1844,6 +1848,7 @@ namespace ThreadPilot
|
||||
this.initializationTimeoutTimer?.Stop();
|
||||
this.initializationTimeoutTimer?.Dispose();
|
||||
|
||||
this.selfResourceManagementService.RestoreForegroundMode();
|
||||
this.navigationBehavior.Dispose();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -172,7 +172,7 @@ namespace ThreadPilot.Models
|
||||
private bool hasSeenElevationWarning = false;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool enableSelfLowImpactMode = false;
|
||||
private bool enableSelfLowImpactMode = true;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool enableSelfAffinityLimit = false;
|
||||
@@ -340,4 +340,3 @@ namespace ThreadPilot.Models
|
||||
Custom,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,19 @@ namespace ThreadPilot.Services
|
||||
|
||||
public static class SelfResourcePolicy
|
||||
{
|
||||
public static bool ShouldApplyLowImpactMode(bool isHidden, bool enableSelfLowImpactMode)
|
||||
{
|
||||
return isHidden && enableSelfLowImpactMode;
|
||||
}
|
||||
|
||||
public static bool ShouldLimitAffinity(
|
||||
bool isHidden,
|
||||
bool enableSelfLowImpactMode,
|
||||
bool enableSelfAffinityLimit)
|
||||
{
|
||||
return ShouldApplyLowImpactMode(isHidden, enableSelfLowImpactMode) && enableSelfAffinityLimit;
|
||||
}
|
||||
|
||||
public static bool TryCreateLowImpactAffinityMask(int logicalProcessorCount, out long affinityMask)
|
||||
{
|
||||
affinityMask = 0;
|
||||
|
||||
@@ -22,6 +22,8 @@ namespace ThreadPilot.Core.Tests
|
||||
Assert.True(storage.Writes.ContainsKey(TestPaths.SettingsFilePath));
|
||||
Assert.Equal(3000, service.Settings.NotificationDisplayDurationMs);
|
||||
Assert.Equal(5000, service.Settings.BalloonNotificationTimeoutMs);
|
||||
Assert.True(service.Settings.EnableSelfLowImpactMode);
|
||||
Assert.False(service.Settings.EnableSelfAffinityLimit);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -35,6 +37,44 @@ namespace ThreadPilot.Core.Tests
|
||||
|
||||
Assert.Equal(3000, service.Settings.NotificationDisplayDurationMs);
|
||||
Assert.Equal(string.Empty, service.Settings.CustomTrayIconPath);
|
||||
Assert.True(service.Settings.EnableSelfLowImpactMode);
|
||||
Assert.False(service.Settings.EnableSelfAffinityLimit);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task LoadSettingsAsync_EnablesSafeSelfLowImpactDefault_ForOlderSettingsJson()
|
||||
{
|
||||
var storage = new FakeSettingsStorage();
|
||||
storage.Files[TestPaths.SettingsFilePath] = """
|
||||
{
|
||||
"notificationDisplayDurationMs": 3000,
|
||||
"balloonNotificationTimeoutMs": 5000
|
||||
}
|
||||
""";
|
||||
var service = CreateService(storage);
|
||||
|
||||
await service.LoadSettingsAsync();
|
||||
|
||||
Assert.True(service.Settings.EnableSelfLowImpactMode);
|
||||
Assert.False(service.Settings.EnableSelfAffinityLimit);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task LoadSettingsAsync_PreservesExplicitSelfLowImpactOptOut()
|
||||
{
|
||||
var storage = new FakeSettingsStorage();
|
||||
storage.Files[TestPaths.SettingsFilePath] = """
|
||||
{
|
||||
"enableSelfLowImpactMode": false,
|
||||
"enableSelfAffinityLimit": true
|
||||
}
|
||||
""";
|
||||
var service = CreateService(storage);
|
||||
|
||||
await service.LoadSettingsAsync();
|
||||
|
||||
Assert.False(service.Settings.EnableSelfLowImpactMode);
|
||||
Assert.True(service.Settings.EnableSelfAffinityLimit);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -33,5 +33,21 @@ namespace ThreadPilot.Core.Tests
|
||||
{
|
||||
Assert.False(SelfResourcePolicy.TryCreateLowImpactAffinityMask(logicalProcessorCount, out _));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(false, true, true, false)]
|
||||
[InlineData(true, false, true, false)]
|
||||
[InlineData(true, true, false, false)]
|
||||
[InlineData(true, true, true, true)]
|
||||
public void ShouldLimitAffinity_RequiresHiddenLowImpactModeAndAffinitySetting(
|
||||
bool isHidden,
|
||||
bool enableSelfLowImpactMode,
|
||||
bool enableSelfAffinityLimit,
|
||||
bool expected)
|
||||
{
|
||||
Assert.Equal(
|
||||
expected,
|
||||
SelfResourcePolicy.ShouldLimitAffinity(isHidden, enableSelfLowImpactMode, enableSelfAffinityLimit));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user