From 7be4cef428d80467d64de46e390fd6bbd87b76e5 Mon Sep 17 00:00:00 2001 From: PrimeBuild-pc Date: Sat, 11 Apr 2026 17:41:13 +0200 Subject: [PATCH] Enhance theming, UI behavior, perf & add CI Multiple improvements across theming, UI flow, performance refresh logic, and CI: - Add CI DevSecOps GH Action workflow: .NET restore/build (Debug/Release), dependency audit, and gitleaks secret scan. - Theming: preload and apply theme at startup; add HasUserThemePreference to settings model; detect legacy theme flag when loading settings; ThemeService now reads system theme from registry (GetSystemUsesDarkTheme) and exposes system-use check. - Richer theme resources: major updates to FluentDark.xaml and FluentLight.xaml (expanded color palette, control styles/templates, system brushes) to modernize visuals and controls. - Startup/UI behavior: improved autostart/minimize-to-tray handling, consistent ShowInTaskbar/Visibility logic, OnSourceInitialized hook to reapply caption theme, and apply DWM immersive dark caption via DwmSetWindowAttribute. - Robust UI error handling: throttle dispatcher exception dialog to avoid multiple dialogs using an interlocked flag and short time window. - MainWindow refactor: introduce ShowWindowFromTray helper, unify show/activate flows, apply caption theming, and adjust several shortcut handlers to use the helper. - Tab switching: add SemaphoreSlim guard and improved selection logic to debounce concurrent tab changes; prompt/save/discard unsaved settings when switching away from Settings; dispose semaphore on shutdown. - PerformanceViewModel: debounce/gate top-process refreshes with SemaphoreSlim and a pending flag to avoid overlapping refreshes; update TopCpuProcesses on UI dispatcher and refresh selected process impact safely. - Misc: small XAML cleanups (Settings tab header simplification), add COMPLIANCE_AUDIT.md to .gitignore, and various logging/error message tweaks. These changes aim to reduce UI flicker on startup, respect user/system theme preferences, harden UI interactions, prevent concurrent refresh race conditions, and add CI/DevSecOps checks. --- .github/workflows/ci-devsecops.yml | 36 ++ .gitignore | 1 + App.xaml.cs | 65 ++- MainWindow.xaml | 20 +- MainWindow.xaml.cs | 223 +++++--- Models/ApplicationSettingsModel.cs | 4 + Services/ApplicationSettingsService.cs | 22 + Services/IThemeService.cs | 2 + Services/ThemeService.cs | 28 + Themes/FluentDark.xaml | 263 ++++++++- Themes/FluentLight.xaml | 261 ++++++++- ViewModels/PerformanceViewModel.cs | 160 ++++-- ViewModels/ProcessViewModel.cs | 107 ++-- ViewModels/SettingsViewModel.cs | 23 +- Views/PerformanceView.xaml | 615 +++++++++++---------- Views/ProcessPowerPlanAssociationView.xaml | 2 +- Views/SettingsView.xaml | 2 +- 17 files changed, 1283 insertions(+), 551 deletions(-) create mode 100644 .github/workflows/ci-devsecops.yml diff --git a/.github/workflows/ci-devsecops.yml b/.github/workflows/ci-devsecops.yml new file mode 100644 index 0000000..cd51dba --- /dev/null +++ b/.github/workflows/ci-devsecops.yml @@ -0,0 +1,36 @@ +name: CI DevSecOps + +on: + push: + branches: ["main", "master"] + pull_request: + +jobs: + build-and-scan: + runs-on: windows-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: "8.0.x" + + - name: Restore + run: dotnet restore "ThreadPilot.csproj" + + - name: Build Debug + run: dotnet build "ThreadPilot.csproj" --configuration Debug --no-restore + + - name: Build Release + run: dotnet build "ThreadPilot.csproj" --configuration Release --no-restore + + - name: Dependency Audit + run: dotnet list "ThreadPilot.csproj" package --vulnerable --include-transitive + + - name: Secret Scan + uses: gitleaks/gitleaks-action@v2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index e3733b6..3105e88 100644 --- a/.gitignore +++ b/.gitignore @@ -131,3 +131,4 @@ GAME_BOOST_VALIDATION.md PROJECT_STRUCTURE.md TRADEMARK.md UI_STYLE_GUIDE.md +COMPLIANCE_AUDIT.md diff --git a/App.xaml.cs b/App.xaml.cs index 563ab20..1c963a4 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -34,6 +34,8 @@ namespace ThreadPilot public partial class App : System.Windows.Application { private Mutex? _singleInstanceMutex; + private int _uiExceptionDialogOpen; + private DateTime _lastUiExceptionDialogUtc = DateTime.MinValue; public IServiceProvider ServiceProvider { get; private set; } public App() @@ -135,6 +137,24 @@ namespace ThreadPilot } #endif + try + { + var settingsService = ServiceProvider.GetRequiredService(); + var themeService = ServiceProvider.GetRequiredService(); + + Task.Run(async () => await settingsService.LoadSettingsAsync()).GetAwaiter().GetResult(); + var settings = settingsService.Settings; + var useDarkTheme = settings.HasUserThemePreference + ? settings.UseDarkTheme + : themeService.GetSystemUsesDarkTheme(); + + themeService.ApplyTheme(useDarkTheme); + } + catch (Exception ex) + { + logger.LogWarning(ex, "Failed to preload theme settings during startup"); + } + var mainWindow = ServiceProvider.GetRequiredService(); // Handle startup behavior with comprehensive error handling @@ -148,15 +168,27 @@ namespace ThreadPilot throw new InvalidOperationException("MainWindow could not be created"); } - // Show the window with explicit visibility settings - mainWindow.Visibility = Visibility.Visible; - mainWindow.WindowState = (startMinimized || isAutostart) - ? WindowState.Minimized - : WindowState.Normal; - mainWindow.Show(); - if (mainWindow.WindowState != WindowState.Minimized) + if (isAutostart) { - mainWindow.Activate(); + mainWindow.ShowInTaskbar = false; + mainWindow.Visibility = Visibility.Hidden; + mainWindow.WindowState = WindowState.Minimized; + mainWindow.Show(); + mainWindow.Hide(); + } + else + { + // Show the window with explicit visibility settings + mainWindow.ShowInTaskbar = true; + mainWindow.Visibility = Visibility.Visible; + mainWindow.WindowState = startMinimized + ? WindowState.Minimized + : WindowState.Normal; + mainWindow.Show(); + if (mainWindow.WindowState != WindowState.Minimized) + { + mainWindow.Activate(); + } } logger.LogInformation("Main window displayed successfully"); @@ -247,6 +279,21 @@ namespace ThreadPilot logger?.LogError(e.Exception, "Unhandled dispatcher exception occurred"); + if (Interlocked.CompareExchange(ref _uiExceptionDialogOpen, 1, 0) != 0) + { + e.Handled = true; + return; + } + + if (DateTime.UtcNow - _lastUiExceptionDialogUtc < TimeSpan.FromSeconds(2)) + { + e.Handled = true; + Interlocked.Exchange(ref _uiExceptionDialogOpen, 0); + return; + } + + _lastUiExceptionDialogUtc = DateTime.UtcNow; + var errorMessage = $"An error occurred in the user interface:\n\n{e.Exception.Message}\n\nDo you want to continue?"; var result = System.Windows.MessageBox.Show(errorMessage, "UI Error", MessageBoxButton.YesNo, MessageBoxImage.Error); @@ -259,6 +306,8 @@ namespace ThreadPilot { e.Handled = false; // Let the application crash } + + Interlocked.Exchange(ref _uiExceptionDialogOpen, 0); } } } diff --git a/MainWindow.xaml b/MainWindow.xaml index 0378015..54a021f 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -13,18 +13,6 @@ WindowStartupLocation="CenterScreen"> - - - - + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + - - - - - - - - + + - - - - - - - - - - - - -