feat: remember layout choices; Windows 11 toggles in Tweaks
- The navigation pane, window size/position/maximized state, and the process list filters, sort and columns now survive a restart. They live in ui-state.json, apart from settings.json, so they never mark the Settings page as unsaved or travel in exported configurations. A corrupt file falls back to defaults; tests write to a temp file. - Fixes the pane re-opening on every start (it was hard-coded open). - Tweaks use a native-looking Windows 11 switch (40x20 track, sliding thumb) with On/Off written beside it. - New test: every on/off setting survives save and reload.
This commit is contained in:
+2
-2
@@ -556,8 +556,8 @@
|
||||
<sys:String x:Key="SystemTweak_GpuMsiMode_Name">GPU-MSI-Modus</sys:String>
|
||||
<sys:String x:Key="SystemTweak_GpuMsiMode_Desc">Steuert MSI nur, wenn der Grafiktreiber MSISupported bereits bereitstellt. Neustart erforderlich.</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_OpenSettings">Einstellungen öffnen</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_ToggleOn">EIN</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_ToggleOff">AUS</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_ToggleOn">Ein</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_ToggleOff">Aus</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_StatusManagedByWindows">Von Windows verwaltet</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_StatusOpenSettingsFailed">Windows-Einstellungen konnten nicht geöffnet werden</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_StatusSettingsOpenedFormat">Einstellungen für {0} geöffnet</sys:String>
|
||||
|
||||
+2
-2
@@ -556,8 +556,8 @@
|
||||
<sys:String x:Key="SystemTweak_GpuMsiMode_Name">GPU MSI Mode</sys:String>
|
||||
<sys:String x:Key="SystemTweak_GpuMsiMode_Desc">Controls MSI only when the display driver already exposes MSISupported. A restart is required.</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_OpenSettings">Open settings</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_ToggleOn">ON</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_ToggleOff">OFF</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_ToggleOn">On</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_ToggleOff">Off</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_StatusManagedByWindows">Managed by Windows</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_StatusOpenSettingsFailed">Could not open Windows settings</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_StatusSettingsOpenedFormat">Opened settings for {0}</sys:String>
|
||||
|
||||
+2
-2
@@ -556,8 +556,8 @@
|
||||
<sys:String x:Key="SystemTweak_GpuMsiMode_Name">Modo MSI de GPU</sys:String>
|
||||
<sys:String x:Key="SystemTweak_GpuMsiMode_Desc">Controla MSI solo si el controlador gráfico ya expone MSISupported. Requiere reiniciar.</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_OpenSettings">Abrir configuración</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_ToggleOn">SÍ</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_ToggleOff">NO</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_ToggleOn">Activado</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_ToggleOff">Desactivado</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_StatusManagedByWindows">Administrado por Windows</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_StatusOpenSettingsFailed">No se pudo abrir la configuración de Windows</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_StatusSettingsOpenedFormat">Configuración abierta para {0}</sys:String>
|
||||
|
||||
+2
-2
@@ -556,8 +556,8 @@
|
||||
<sys:String x:Key="SystemTweak_GpuMsiMode_Name">Mode MSI du GPU</sys:String>
|
||||
<sys:String x:Key="SystemTweak_GpuMsiMode_Desc">Contrôle MSI uniquement si le pilote graphique expose déjà MSISupported. Redémarrage requis.</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_OpenSettings">Ouvrir les paramètres</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_ToggleOn">OUI</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_ToggleOff">NON</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_ToggleOn">Activé</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_ToggleOff">Désactivé</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_StatusManagedByWindows">Géré par Windows</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_StatusOpenSettingsFailed">Impossible d'ouvrir les paramètres Windows</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_StatusSettingsOpenedFormat">Paramètres ouverts pour {0}</sys:String>
|
||||
|
||||
+2
-2
@@ -556,8 +556,8 @@
|
||||
<sys:String x:Key="SystemTweak_GpuMsiMode_Name">Modalità MSI GPU</sys:String>
|
||||
<sys:String x:Key="SystemTweak_GpuMsiMode_Desc">Controlla MSI solo se il driver video espone già MSISupported. È necessario riavviare.</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_OpenSettings">Apri impostazioni</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_ToggleOn">ON</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_ToggleOff">OFF</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_ToggleOn">Attivato</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_ToggleOff">Disattivato</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_StatusManagedByWindows">Gestito da Windows</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_StatusOpenSettingsFailed">Impossibile aprire le impostazioni di Windows</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_StatusSettingsOpenedFormat">Impostazioni aperte per {0}</sys:String>
|
||||
|
||||
+2
-2
@@ -556,8 +556,8 @@
|
||||
<sys:String x:Key="SystemTweak_GpuMsiMode_Name">Режим MSI для GPU</sys:String>
|
||||
<sys:String x:Key="SystemTweak_GpuMsiMode_Desc">Управляет MSI, только если видеодрайвер уже предоставляет MSISupported. Требуется перезагрузка.</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_OpenSettings">Открыть параметры</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_ToggleOn">ВКЛ</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_ToggleOff">ВЫКЛ</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_ToggleOn">Вкл.</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_ToggleOff">Откл.</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_StatusManagedByWindows">Управляется Windows</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_StatusOpenSettingsFailed">Не удалось открыть параметры Windows</sys:String>
|
||||
<sys:String x:Key="SystemTweaks_StatusSettingsOpenedFormat">Открыты параметры для {0}</sys:String>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,7 +83,6 @@
|
||||
<ui:NavigationView x:Name="RootNavigation"
|
||||
PaneDisplayMode="Left"
|
||||
IsBackButtonVisible="Collapsed"
|
||||
IsPaneOpen="True"
|
||||
OpenPaneLength="200"
|
||||
CompactPaneLength="52"
|
||||
AutomationProperties.Name="{DynamicResource MainWindow_PrimaryNavigation}">
|
||||
|
||||
@@ -101,6 +101,7 @@ namespace ThreadPilot
|
||||
|
||||
this.InitializeComponent();
|
||||
System.Diagnostics.Debug.WriteLine("InitializeComponent completed");
|
||||
this.RestoreUiState();
|
||||
this.ConfigureDiagnosticsNavigation();
|
||||
|
||||
// Initialize loading overlay
|
||||
|
||||
@@ -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<UiState, UiState> 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<UiState>(File.ReadAllText(FilePath), JsonOptions) ?? new UiState()
|
||||
: new UiState();
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or JsonException)
|
||||
{
|
||||
return new UiState();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -11,6 +11,22 @@ namespace ThreadPilot.Views
|
||||
{
|
||||
this.InitializeComponent();
|
||||
this.DataContext = ServiceProviderExtensions.GetService<ProcessViewModel>();
|
||||
|
||||
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)
|
||||
|
||||
+63
-39
@@ -8,60 +8,84 @@
|
||||
d:DesignHeight="600" d:DesignWidth="800">
|
||||
|
||||
<UserControl.Resources>
|
||||
<!-- Larger, labelled pill toggle. The native ui:ToggleSwitch is 40x20 with no text,
|
||||
which reads as a decoration rather than a switch on this dense list. -->
|
||||
<Style x:Key="PillToggleButtonStyle" TargetType="ToggleButton">
|
||||
<Setter Property="MinWidth" Value="56"/>
|
||||
<Setter Property="Height" Value="28"/>
|
||||
<!-- Windows 11 toggle switch: 40x20 track, a thumb that slides and grows on hover, accent when on,
|
||||
and the state written beside it ("On"/"Off") as in Windows Settings. The label sits outside
|
||||
the track, so a long translation widens the control instead of colliding with the thumb. -->
|
||||
<Style x:Key="Win11ToggleSwitchStyle" TargetType="ToggleButton">
|
||||
<Setter Property="Cursor" Value="Hand"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Right"/>
|
||||
<Setter Property="Focusable" Value="True"/>
|
||||
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ToggleButton">
|
||||
<Border x:Name="Track"
|
||||
Background="{DynamicResource ControlFillColorSecondaryBrush}"
|
||||
BorderBrush="{DynamicResource ControlStrokeColorDefaultBrush}"
|
||||
BorderThickness="1"
|
||||
CornerRadius="14"
|
||||
Padding="3"
|
||||
SnapsToDevicePixels="True">
|
||||
<!-- Thumb and label are docked, never stacked, so a long localized
|
||||
label (ru "ВЫКЛ") pushes the pill wider instead of colliding with
|
||||
the thumb. MinWidth keeps the common case at the intended size. -->
|
||||
<DockPanel LastChildFill="True">
|
||||
<DockPanel Background="Transparent">
|
||||
<TextBlock x:Name="StateLabel"
|
||||
DockPanel.Dock="Left"
|
||||
Text="{DynamicResource SystemTweaks_ToggleOff}"
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,0,12,0"
|
||||
Foreground="{DynamicResource TextPrimaryBrush}"/>
|
||||
<Border x:Name="Track"
|
||||
Width="40"
|
||||
Height="20"
|
||||
CornerRadius="10"
|
||||
BorderThickness="1"
|
||||
Background="Transparent"
|
||||
BorderBrush="{DynamicResource TextSecondaryBrush}"
|
||||
SnapsToDevicePixels="True">
|
||||
<Ellipse x:Name="Thumb"
|
||||
DockPanel.Dock="Left"
|
||||
Width="20"
|
||||
Height="20"
|
||||
Fill="{DynamicResource TextSecondaryBrush}"/>
|
||||
<TextBlock x:Name="StateLabel"
|
||||
Text="{DynamicResource SystemTweaks_ToggleOff}"
|
||||
FontSize="10"
|
||||
FontWeight="SemiBold"
|
||||
VerticalAlignment="Center"
|
||||
TextAlignment="Center"
|
||||
Margin="3,0,4,0"
|
||||
Foreground="{DynamicResource TextSecondaryBrush}"/>
|
||||
</DockPanel>
|
||||
</Border>
|
||||
Width="12"
|
||||
Height="12"
|
||||
Margin="3,0,0,0"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
Fill="{DynamicResource TextSecondaryBrush}">
|
||||
<Ellipse.RenderTransform>
|
||||
<TranslateTransform x:Name="ThumbOffset" X="0"/>
|
||||
</Ellipse.RenderTransform>
|
||||
</Ellipse>
|
||||
</Border>
|
||||
</DockPanel>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsChecked" Value="True">
|
||||
<Setter TargetName="Track" Property="Background" Value="{DynamicResource AccentFillColorDefaultBrush}"/>
|
||||
<Setter TargetName="Track" Property="BorderBrush" Value="{DynamicResource AccentFillColorDefaultBrush}"/>
|
||||
<Setter TargetName="Thumb" Property="DockPanel.Dock" Value="Right"/>
|
||||
<Setter TargetName="Thumb" Property="Fill" Value="{DynamicResource TextOnAccentFillColorPrimaryBrush}"/>
|
||||
<Setter TargetName="StateLabel" Property="Text" Value="{DynamicResource SystemTweaks_ToggleOn}"/>
|
||||
<Setter TargetName="StateLabel" Property="Margin" Value="4,0,3,0"/>
|
||||
<Setter TargetName="StateLabel" Property="Foreground" Value="{DynamicResource TextOnAccentFillColorPrimaryBrush}"/>
|
||||
<Trigger.EnterActions>
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetName="ThumbOffset" Storyboard.TargetProperty="X" To="20" Duration="0:0:0.15">
|
||||
<DoubleAnimation.EasingFunction>
|
||||
<CubicEase EasingMode="EaseOut"/>
|
||||
</DoubleAnimation.EasingFunction>
|
||||
</DoubleAnimation>
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</Trigger.EnterActions>
|
||||
<Trigger.ExitActions>
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetName="ThumbOffset" Storyboard.TargetProperty="X" To="0" Duration="0:0:0.15">
|
||||
<DoubleAnimation.EasingFunction>
|
||||
<CubicEase EasingMode="EaseOut"/>
|
||||
</DoubleAnimation.EasingFunction>
|
||||
</DoubleAnimation>
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</Trigger.ExitActions>
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter TargetName="Track" Property="BorderBrush" Value="{DynamicResource SoftSelectionBorderBrush}"/>
|
||||
<Setter TargetName="Thumb" Property="Width" Value="14"/>
|
||||
<Setter TargetName="Thumb" Property="Height" Value="14"/>
|
||||
<Setter TargetName="Thumb" Property="Margin" Value="2,0,0,0"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsKeyboardFocused" Value="True">
|
||||
<Setter TargetName="Track" Property="BorderThickness" Value="2"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter TargetName="Track" Property="Background" Value="{DynamicResource ControlFillColorDisabledBrush}"/>
|
||||
<Setter TargetName="Track" Property="BorderBrush" Value="{DynamicResource BorderSubtleBrush}"/>
|
||||
<Setter TargetName="Track" Property="Opacity" Value="0.6"/>
|
||||
<Setter TargetName="Thumb" Property="Fill" Value="{DynamicResource TextSecondaryBrush}"/>
|
||||
<Setter TargetName="Track" Property="Opacity" Value="0.4"/>
|
||||
<Setter TargetName="StateLabel" Property="Foreground" Value="{DynamicResource TextSecondaryBrush}"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
@@ -166,7 +190,7 @@
|
||||
AutomationProperties.Name="{Binding Name}"
|
||||
ToolTip="{DynamicResource SystemTweaksView_TweakTooltip}">
|
||||
<ToggleButton.Style>
|
||||
<Style TargetType="ToggleButton" BasedOn="{StaticResource PillToggleButtonStyle}">
|
||||
<Style TargetType="ToggleButton" BasedOn="{StaticResource Win11ToggleSwitchStyle}">
|
||||
<Setter Property="Visibility" Value="Visible"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsGuidedAction}" Value="True">
|
||||
|
||||
Reference in New Issue
Block a user