diff --git a/Locales/de-DE.xaml b/Locales/de-DE.xaml
index 0ff2e8d..e28c2d4 100644
--- a/Locales/de-DE.xaml
+++ b/Locales/de-DE.xaml
@@ -556,8 +556,8 @@
GPU-MSI-Modus
Steuert MSI nur, wenn der Grafiktreiber MSISupported bereits bereitstellt. Neustart erforderlich.
Einstellungen öffnen
- EIN
- AUS
+ Ein
+ Aus
Von Windows verwaltet
Windows-Einstellungen konnten nicht geöffnet werden
Einstellungen für {0} geöffnet
diff --git a/Locales/en-US.xaml b/Locales/en-US.xaml
index 44efaea..4e87b58 100644
--- a/Locales/en-US.xaml
+++ b/Locales/en-US.xaml
@@ -556,8 +556,8 @@
GPU MSI Mode
Controls MSI only when the display driver already exposes MSISupported. A restart is required.
Open settings
- ON
- OFF
+ On
+ Off
Managed by Windows
Could not open Windows settings
Opened settings for {0}
diff --git a/Locales/es-ES.xaml b/Locales/es-ES.xaml
index 271b14c..5761000 100644
--- a/Locales/es-ES.xaml
+++ b/Locales/es-ES.xaml
@@ -556,8 +556,8 @@
Modo MSI de GPU
Controla MSI solo si el controlador gráfico ya expone MSISupported. Requiere reiniciar.
Abrir configuración
- SÍ
- NO
+ Activado
+ Desactivado
Administrado por Windows
No se pudo abrir la configuración de Windows
Configuración abierta para {0}
diff --git a/Locales/fr-FR.xaml b/Locales/fr-FR.xaml
index f4391d6..472fce1 100644
--- a/Locales/fr-FR.xaml
+++ b/Locales/fr-FR.xaml
@@ -556,8 +556,8 @@
Mode MSI du GPU
Contrôle MSI uniquement si le pilote graphique expose déjà MSISupported. Redémarrage requis.
Ouvrir les paramètres
- OUI
- NON
+ Activé
+ Désactivé
Géré par Windows
Impossible d'ouvrir les paramètres Windows
Paramètres ouverts pour {0}
diff --git a/Locales/it-IT.xaml b/Locales/it-IT.xaml
index baea07c..d07a8cd 100644
--- a/Locales/it-IT.xaml
+++ b/Locales/it-IT.xaml
@@ -556,8 +556,8 @@
Modalità MSI GPU
Controlla MSI solo se il driver video espone già MSISupported. È necessario riavviare.
Apri impostazioni
- ON
- OFF
+ Attivato
+ Disattivato
Gestito da Windows
Impossibile aprire le impostazioni di Windows
Impostazioni aperte per {0}
diff --git a/Locales/ru-RU.xaml b/Locales/ru-RU.xaml
index 15ecce2..2f3854e 100644
--- a/Locales/ru-RU.xaml
+++ b/Locales/ru-RU.xaml
@@ -556,8 +556,8 @@
Режим MSI для GPU
Управляет MSI, только если видеодрайвер уже предоставляет MSISupported. Требуется перезагрузка.
Открыть параметры
- ВКЛ
- ВЫКЛ
+ Вкл.
+ Откл.
Управляется Windows
Не удалось открыть параметры Windows
Открыты параметры для {0}
diff --git a/MainWindow.Behaviors.partial.cs b/MainWindow.Behaviors.partial.cs
index c8876a3..09ac439 100644
--- a/MainWindow.Behaviors.partial.cs
+++ b/MainWindow.Behaviors.partial.cs
@@ -2196,6 +2196,7 @@ namespace ThreadPilot
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
+ this.SaveWindowPlacement();
if (this.isPerformingShutdown)
{
base.OnClosing(e);
@@ -2228,6 +2229,7 @@ namespace ThreadPilot
protected override void OnClosed(EventArgs e)
{
+ this.SaveWindowPlacement();
try
{
this.Loaded -= this.OnWindowLoaded;
diff --git a/MainWindow.UiState.partial.cs b/MainWindow.UiState.partial.cs
new file mode 100644
index 0000000..6946bb6
--- /dev/null
+++ b/MainWindow.UiState.partial.cs
@@ -0,0 +1,53 @@
+namespace ThreadPilot
+{
+ using System.Windows;
+ using ThreadPilot.Services;
+
+ public partial class MainWindow
+ {
+ // Puts the menu and the window back the way the user left them. A position that is now
+ // off-screen (unplugged monitor) is pulled back by EnsureDashboardVisibleOnScreen at startup.
+ private void RestoreUiState()
+ {
+ var state = UiStateStore.Current;
+ this.RootNavigation.IsPaneOpen = state.NavigationPaneOpen;
+ this.RootNavigation.PaneOpened += (_, _) => UiStateStore.Update(s => s with { NavigationPaneOpen = true });
+ this.RootNavigation.PaneClosed += (_, _) => UiStateStore.Update(s => s with { NavigationPaneOpen = false });
+
+ if (state.WindowWidth is > 0 && state.WindowHeight is > 0 && state.WindowLeft.HasValue && state.WindowTop.HasValue)
+ {
+ this.WindowStartupLocation = WindowStartupLocation.Manual;
+ this.Left = state.WindowLeft.Value;
+ this.Top = state.WindowTop.Value;
+ this.Width = state.WindowWidth.Value;
+ this.Height = state.WindowHeight.Value;
+ }
+
+ if (state.WindowMaximized)
+ {
+ this.WindowState = WindowState.Maximized;
+ }
+ }
+
+ private void SaveWindowPlacement()
+ {
+ // RestoreBounds is the normal-size rectangle even while maximized or minimized.
+ var bounds = this.WindowState == WindowState.Normal
+ ? new Rect(this.Left, this.Top, this.ActualWidth, this.ActualHeight)
+ : this.RestoreBounds;
+ if (bounds.IsEmpty || bounds.Width <= 0 || bounds.Height <= 0 || double.IsNaN(bounds.Left))
+ {
+ return;
+ }
+
+ UiStateStore.Update(s => s with
+ {
+ WindowLeft = bounds.Left,
+ WindowTop = bounds.Top,
+ WindowWidth = bounds.Width,
+ WindowHeight = bounds.Height,
+ WindowMaximized = this.WindowState == WindowState.Maximized,
+ });
+ }
+ }
+}
diff --git a/MainWindow.xaml b/MainWindow.xaml
index 69ba5cc..f9cda54 100644
--- a/MainWindow.xaml
+++ b/MainWindow.xaml
@@ -83,7 +83,6 @@
diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs
index 300d8e1..11ba983 100644
--- a/MainWindow.xaml.cs
+++ b/MainWindow.xaml.cs
@@ -101,6 +101,7 @@ namespace ThreadPilot
this.InitializeComponent();
System.Diagnostics.Debug.WriteLine("InitializeComponent completed");
+ this.RestoreUiState();
this.ConfigureDiagnosticsNavigation();
// Initialize loading overlay
diff --git a/Services/UiStateStore.cs b/Services/UiStateStore.cs
new file mode 100644
index 0000000..6cf0768
--- /dev/null
+++ b/Services/UiStateStore.cs
@@ -0,0 +1,99 @@
+namespace ThreadPilot.Services
+{
+ using System;
+ using System.IO;
+ using System.Text.Json;
+
+ // Layout choices the user makes by hand (menu, window, process list view). Kept out of settings.json
+ // so they never mark the Settings page as unsaved and never travel in exported configurations.
+ public sealed record UiState
+ {
+ public bool NavigationPaneOpen { get; init; } = true;
+
+ public double? WindowLeft { get; init; }
+
+ public double? WindowTop { get; init; }
+
+ public double? WindowWidth { get; init; }
+
+ public double? WindowHeight { get; init; }
+
+ public bool WindowMaximized { get; init; }
+
+ public bool ShowActiveApplicationsOnly { get; init; }
+
+ public bool HideSystemProcesses { get; init; }
+
+ public bool HideIdleProcesses { get; init; }
+
+ public string SortMode { get; init; } = "CpuUsage";
+
+ public bool ShowPidColumn { get; init; } = true;
+
+ public bool ShowWindowTitleColumn { get; init; }
+
+ public bool ShowHasWindowColumn { get; init; }
+ }
+
+ public static class UiStateStore
+ {
+ private static readonly JsonSerializerOptions JsonOptions = new() { WriteIndented = true };
+ private static readonly object Gate = new();
+ private static UiState? current;
+
+ internal static string FilePath { get; set; } = Path.Combine(StoragePaths.AppDataRoot, "ui-state.json");
+
+ public static UiState Current
+ {
+ get
+ {
+ lock (Gate)
+ {
+ return current ??= Load();
+ }
+ }
+ }
+
+ public static void Update(Func change)
+ {
+ lock (Gate)
+ {
+ var updated = change(current ??= Load());
+ if (updated == current)
+ {
+ return;
+ }
+
+ current = updated;
+ try
+ {
+ // Synchronous on purpose: this also runs while the window closes, right before exit.
+ Directory.CreateDirectory(Path.GetDirectoryName(FilePath)!);
+ var temp = FilePath + ".tmp";
+ File.WriteAllText(temp, JsonSerializer.Serialize(updated, JsonOptions));
+ File.Move(temp, FilePath, overwrite: true);
+ }
+ catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
+ {
+ // Losing a layout preference is harmless; the next change tries again.
+ }
+ }
+ }
+
+ internal static void ResetForTests() => current = null;
+
+ private static UiState Load()
+ {
+ try
+ {
+ return File.Exists(FilePath)
+ ? JsonSerializer.Deserialize(File.ReadAllText(FilePath), JsonOptions) ?? new UiState()
+ : new UiState();
+ }
+ catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or JsonException)
+ {
+ return new UiState();
+ }
+ }
+ }
+}
diff --git a/Tests/ThreadPilot.Core.Tests/ApplicationSettingsServiceTests.cs b/Tests/ThreadPilot.Core.Tests/ApplicationSettingsServiceTests.cs
index f5aa99e..45aaa4c 100644
--- a/Tests/ThreadPilot.Core.Tests/ApplicationSettingsServiceTests.cs
+++ b/Tests/ThreadPilot.Core.Tests/ApplicationSettingsServiceTests.cs
@@ -167,6 +167,37 @@ namespace ThreadPilot.Core.Tests
Assert.Equal(CpuAssignmentMode.CpuSets, reloaded.Settings.DefaultCpuAssignmentMode);
}
+ [Fact]
+ public async Task UpdateSettingsAsync_EveryOptionSurvivesARestart()
+ {
+ // Flip every on/off option, save, and read it back with a fresh service: nothing may silently
+ // fall back to its default. Migration markers are excluded because loading rewrites them on purpose.
+ var storage = new FakeSettingsStorage();
+ var service = CreateService(storage);
+ await service.LoadSettingsAsync();
+ var settings = service.Settings;
+ var flags = typeof(ApplicationSettingsModel).GetProperties()
+ .Where(property => property.PropertyType == typeof(bool) && property.CanWrite &&
+ !property.Name.StartsWith("HasMigrated", StringComparison.Ordinal))
+ .ToList();
+ var expected = flags.ToDictionary(property => property.Name, property => !(bool)property.GetValue(settings)!);
+ foreach (var property in flags)
+ {
+ property.SetValue(settings, expected[property.Name]);
+ }
+
+ settings.Language = "de-DE";
+ await service.UpdateSettingsAsync(settings);
+
+ var reloaded = CreateService(storage);
+ await reloaded.LoadSettingsAsync();
+ var lost = flags.Where(property => (bool)property.GetValue(reloaded.Settings)! != expected[property.Name])
+ .Select(property => property.Name)
+ .ToList();
+ Assert.Empty(lost);
+ Assert.Equal("de-DE", reloaded.Settings.Language);
+ }
+
[Fact]
public async Task UpdateSettingsAsync_PersistsAutomationMonitoringDisabled()
{
diff --git a/Tests/ThreadPilot.Core.Tests/SystemTweaksStartupAndStyleTests.cs b/Tests/ThreadPilot.Core.Tests/SystemTweaksStartupAndStyleTests.cs
index 09934bb..584edfe 100644
--- a/Tests/ThreadPilot.Core.Tests/SystemTweaksStartupAndStyleTests.cs
+++ b/Tests/ThreadPilot.Core.Tests/SystemTweaksStartupAndStyleTests.cs
@@ -17,44 +17,30 @@ namespace ThreadPilot.Core.Tests
}
[Fact]
- public void TweaksView_UsesLabelledPillToggle()
+ public void TweaksView_UsesWindows11ToggleWithStateLabel()
{
- // The native ui:ToggleSwitch is 40x20 with no text, too quiet to read as a control on
- // this list. The pill states ON/OFF inside the track and is sized to be obvious.
+ // Native Windows 11 switch (40x20 track, sliding thumb) with "On"/"Off" written beside it,
+ // as in Windows Settings, so the state is readable without decoding colours.
var document = XDocument.Load(GetRepositoryFilePath("Views", "SystemTweaksView.xaml"));
var serialized = document.ToString(SaveOptions.DisableFormatting);
- Assert.Contains("PillToggleButtonStyle", serialized, StringComparison.Ordinal);
+ Assert.Contains("Win11ToggleSwitchStyle", serialized, StringComparison.Ordinal);
Assert.Contains("AutomationProperties.Name=\"{Binding Name}\"", serialized, StringComparison.Ordinal);
Assert.Contains("SystemTweaks_ToggleOn", serialized, StringComparison.Ordinal);
Assert.Contains("SystemTweaks_ToggleOff", serialized, StringComparison.Ordinal);
- // The label and the thumb must be docked rather than stacked: a long localized label
- // (ru "ВЫКЛ") has to widen the pill, not slide underneath the thumb.
var track = Assert.Single(
document.Descendants(),
element => element.Name.LocalName == "Border" &&
element.Attributes().Any(attribute =>
attribute.Name.LocalName == "Name" && attribute.Value == "Track"));
- Assert.Single(track.Descendants(), element => element.Name.LocalName == "DockPanel");
+ Assert.Equal("40", track.Attribute("Width")?.Value);
+ Assert.Equal("20", track.Attribute("Height")?.Value);
- var pill = Assert.Single(
- document.Descendants(),
- element => element.Name.LocalName == "Style" &&
- element.Attributes().Any(attribute =>
- attribute.Name.LocalName == "Key" && attribute.Value == "PillToggleButtonStyle"));
- var setters = pill
- .Elements()
- .Where(element => element.Name.LocalName == "Setter")
- .ToDictionary(
- element => element.Attribute("Property")!.Value,
- element => element.Attribute("Value")?.Value,
- StringComparer.Ordinal);
-
- // MinWidth, never Width: a fixed track clips the wider locales.
- Assert.Equal("56", setters["MinWidth"]);
- Assert.Equal("28", setters["Height"]);
- Assert.False(setters.ContainsKey("Width"));
+ // The label lives outside the track: a long translation ("Disattivato") widens the control
+ // instead of sliding under the thumb.
+ Assert.DoesNotContain(track.Descendants(), element => element.Attributes().Any(attribute =>
+ attribute.Name.LocalName == "Name" && attribute.Value == "StateLabel"));
}
[Fact]
diff --git a/Tests/ThreadPilot.Core.Tests/TestUiStateIsolation.cs b/Tests/ThreadPilot.Core.Tests/TestUiStateIsolation.cs
new file mode 100644
index 0000000..d51c4f5
--- /dev/null
+++ b/Tests/ThreadPilot.Core.Tests/TestUiStateIsolation.cs
@@ -0,0 +1,14 @@
+namespace ThreadPilot.Core.Tests
+{
+ using System.IO;
+ using System.Runtime.CompilerServices;
+ using ThreadPilot.Services;
+
+ internal static class TestUiStateIsolation
+ {
+ // View models read and write UI layout state; keep tests away from the real user's file.
+ [ModuleInitializer]
+ internal static void Initialize() =>
+ UiStateStore.FilePath = Path.Combine(Path.GetTempPath(), $"threadpilot-tests-{Environment.ProcessId}", "ui-state.json");
+ }
+}
diff --git a/Tests/ThreadPilot.Core.Tests/UiStateStoreTests.cs b/Tests/ThreadPilot.Core.Tests/UiStateStoreTests.cs
new file mode 100644
index 0000000..826958a
--- /dev/null
+++ b/Tests/ThreadPilot.Core.Tests/UiStateStoreTests.cs
@@ -0,0 +1,35 @@
+namespace ThreadPilot.Core.Tests
+{
+ using System.IO;
+ using ThreadPilot.Services;
+
+ [Collection("UiStateStore")]
+ public sealed class UiStateStoreTests
+ {
+ [Fact]
+ public void Update_SurvivesARestart()
+ {
+ UiStateStore.Update(s => s with { NavigationPaneOpen = false, HideSystemProcesses = true, WindowWidth = 1234 });
+
+ UiStateStore.ResetForTests(); // next read comes from disk, as after a restart
+ var state = UiStateStore.Current;
+
+ Assert.False(state.NavigationPaneOpen);
+ Assert.True(state.HideSystemProcesses);
+ Assert.Equal(1234, state.WindowWidth);
+ }
+
+ [Fact]
+ public void CorruptFile_FallsBackToDefaults()
+ {
+ Directory.CreateDirectory(Path.GetDirectoryName(UiStateStore.FilePath)!);
+ File.WriteAllText(UiStateStore.FilePath, "{ not json");
+
+ UiStateStore.ResetForTests();
+
+ Assert.True(UiStateStore.Current.NavigationPaneOpen);
+ File.Delete(UiStateStore.FilePath);
+ UiStateStore.ResetForTests();
+ }
+ }
+}
diff --git a/ViewModels/ProcessViewModel.Behaviors.partial.cs b/ViewModels/ProcessViewModel.Behaviors.partial.cs
index b1ad7ba..cb0d294 100644
--- a/ViewModels/ProcessViewModel.Behaviors.partial.cs
+++ b/ViewModels/ProcessViewModel.Behaviors.partial.cs
@@ -2143,6 +2143,7 @@ namespace ThreadPilot.ViewModels
partial void OnShowActiveApplicationsOnlyChanged(bool value)
{
+ UiStateStore.Update(s => s with { ShowActiveApplicationsOnly = value });
_ = System.Windows.Application.Current.Dispatcher.InvokeAsync(async () =>
{
await LoadProcessesCommand.ExecuteAsync(null);
@@ -2151,16 +2152,19 @@ namespace ThreadPilot.ViewModels
partial void OnHideSystemProcessesChanged(bool value)
{
+ UiStateStore.Update(s => s with { HideSystemProcesses = value });
this.filterRefreshCoordinator.Schedule();
}
partial void OnHideIdleProcessesChanged(bool value)
{
+ UiStateStore.Update(s => s with { HideIdleProcesses = value });
this.filterRefreshCoordinator.Schedule();
}
partial void OnSortModeChanged(string value)
{
+ UiStateStore.Update(s => s with { SortMode = value });
this.filterRefreshCoordinator.Schedule();
}
diff --git a/ViewModels/ProcessViewModel.cs b/ViewModels/ProcessViewModel.cs
index df40f9a..9ae4c29 100644
--- a/ViewModels/ProcessViewModel.cs
+++ b/ViewModels/ProcessViewModel.cs
@@ -229,6 +229,13 @@ namespace ThreadPilot.ViewModels
this.persistentRuleStore = persistentRuleStore;
this.persistentRuleMatcher = persistentRuleMatcher;
this.SelectedCpuAssignmentMode = settingsService?.Settings.DefaultCpuAssignmentMode ?? CpuAssignmentMode.Automatic;
+
+ // Fields, not properties: the change handlers would reload and re-save the list during construction.
+ var uiState = UiStateStore.Current;
+ this.showActiveApplicationsOnly = uiState.ShowActiveApplicationsOnly;
+ this.hideSystemProcesses = uiState.HideSystemProcesses;
+ this.hideIdleProcesses = uiState.HideIdleProcesses;
+ this.sortMode = string.IsNullOrWhiteSpace(uiState.SortMode) ? this.sortMode : uiState.SortMode;
this.IsAutomationMonitoringEnabled = settingsService?.Settings.EnableAutomationMonitoring ?? true;
if (settingsService != null)
{
diff --git a/Views/ProcessView.xaml.cs b/Views/ProcessView.xaml.cs
index d906552..dcafe57 100644
--- a/Views/ProcessView.xaml.cs
+++ b/Views/ProcessView.xaml.cs
@@ -11,6 +11,22 @@ namespace ThreadPilot.Views
{
this.InitializeComponent();
this.DataContext = ServiceProviderExtensions.GetService();
+
+ var state = Services.UiStateStore.Current;
+ this.ShowPidColumn.IsChecked = state.ShowPidColumn;
+ this.ShowWindowColumn.IsChecked = state.ShowWindowTitleColumn;
+ this.ShowHasWindowColumn.IsChecked = state.ShowHasWindowColumn;
+ System.Windows.RoutedEventHandler save = (_, _) => Services.UiStateStore.Update(s => s with
+ {
+ ShowPidColumn = this.ShowPidColumn.IsChecked,
+ ShowWindowTitleColumn = this.ShowWindowColumn.IsChecked,
+ ShowHasWindowColumn = this.ShowHasWindowColumn.IsChecked,
+ });
+ foreach (var item in new[] { this.ShowPidColumn, this.ShowWindowColumn, this.ShowHasWindowColumn })
+ {
+ item.Checked += save;
+ item.Unchecked += save;
+ }
}
private void ProcessWorkspace_SizeChanged(object sender, System.Windows.SizeChangedEventArgs e)
diff --git a/Views/SystemTweaksView.xaml b/Views/SystemTweaksView.xaml
index 225eebb..61b0205 100644
--- a/Views/SystemTweaksView.xaml
+++ b/Views/SystemTweaksView.xaml
@@ -8,60 +8,84 @@
d:DesignHeight="600" d:DesignWidth="800">
-
-