ea350bf7fd
Introduces a new core mask system for managing CPU affinity, including models, services, and Windows platform handlers. Adds a dedicated Core Masks tab and related views/viewmodels. Removes all Game Boost related code, settings, and UI. Updates process association models to support core masks and process priority. Improves graceful shutdown to clear masks and restore power plans. Refines affinity display and default settings for better usability.
169 lines
6.0 KiB
C#
169 lines
6.0 KiB
C#
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using ThreadPilot.Models;
|
|
using ThreadPilot.Services;
|
|
using ThreadPilot.ViewModels;
|
|
|
|
namespace ThreadPilot
|
|
{
|
|
public partial class MainWindowViewModel : BaseViewModel
|
|
{
|
|
private readonly IProcessMonitorManagerService? _processMonitorManagerService;
|
|
private readonly INotificationService? _notificationService;
|
|
private readonly IElevationService? _elevationService;
|
|
private readonly ISecurityService? _securityService;
|
|
|
|
[ObservableProperty]
|
|
private bool isProcessMonitoringActive = false;
|
|
|
|
[ObservableProperty]
|
|
private string processMonitoringStatusText = "Process Monitoring: Inactive";
|
|
|
|
[ObservableProperty]
|
|
private bool isRunningAsAdministrator = false;
|
|
|
|
[ObservableProperty]
|
|
private string elevationStatusText = "Checking elevation status...";
|
|
|
|
[ObservableProperty]
|
|
private bool showElevationPrompt = false;
|
|
|
|
public MainWindowViewModel(
|
|
ILogger<MainWindowViewModel> logger,
|
|
IEnhancedLoggingService? enhancedLoggingService = null,
|
|
IProcessMonitorManagerService? processMonitorManagerService = null,
|
|
INotificationService? notificationService = null,
|
|
IElevationService? elevationService = null,
|
|
ISecurityService? securityService = null)
|
|
: base(logger, enhancedLoggingService)
|
|
{
|
|
_processMonitorManagerService = processMonitorManagerService;
|
|
_notificationService = notificationService;
|
|
_elevationService = elevationService;
|
|
_securityService = securityService;
|
|
}
|
|
|
|
public override async Task InitializeAsync()
|
|
{
|
|
await ExecuteAsync(async () =>
|
|
{
|
|
// Subscribe to service events
|
|
if (_processMonitorManagerService != null)
|
|
{
|
|
_processMonitorManagerService.ServiceStatusChanged += OnServiceStatusChanged;
|
|
}
|
|
|
|
// Initialize status
|
|
await UpdateStatusAsync();
|
|
UpdateElevationStatus();
|
|
|
|
await LogUserActionAsync("MainWindow", "Initialized main window", "Application startup");
|
|
}, "Initializing main window...");
|
|
}
|
|
|
|
[RelayCommand]
|
|
private async Task ToggleProcessMonitoringAsync()
|
|
{
|
|
if (_processMonitorManagerService == null) return;
|
|
|
|
await ExecuteAsync(async () =>
|
|
{
|
|
if (IsProcessMonitoringActive)
|
|
{
|
|
await _processMonitorManagerService.StopAsync();
|
|
await LogUserActionAsync("ProcessMonitoring", "Stopped process monitoring", "User action");
|
|
}
|
|
else
|
|
{
|
|
await _processMonitorManagerService.StartAsync();
|
|
await LogUserActionAsync("ProcessMonitoring", "Started process monitoring", "User action");
|
|
}
|
|
}, IsProcessMonitoringActive ? "Stopping monitoring..." : "Starting monitoring...");
|
|
}
|
|
|
|
[RelayCommand]
|
|
private async Task RequestElevationAsync()
|
|
{
|
|
if (_elevationService == null) return;
|
|
|
|
await ExecuteAsync(async () =>
|
|
{
|
|
var success = await _elevationService.RequestElevationIfNeeded();
|
|
if (success)
|
|
{
|
|
await LogUserActionAsync("Elevation", "Requested elevation", "User action");
|
|
}
|
|
else
|
|
{
|
|
await LogUserActionAsync("Elevation", "Elevation request failed or cancelled", "User action");
|
|
}
|
|
}, "Requesting elevation...");
|
|
}
|
|
|
|
private async Task UpdateStatusAsync()
|
|
{
|
|
try
|
|
{
|
|
// Update process monitoring status
|
|
if (_processMonitorManagerService != null)
|
|
{
|
|
IsProcessMonitoringActive = _processMonitorManagerService.IsRunning;
|
|
ProcessMonitoringStatusText = IsProcessMonitoringActive
|
|
? "Process Monitoring: Active"
|
|
: "Process Monitoring: Inactive";
|
|
}
|
|
|
|
// Update elevation status
|
|
UpdateElevationStatus();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
SetError("Failed to update status", ex);
|
|
}
|
|
}
|
|
|
|
private void UpdateElevationStatus()
|
|
{
|
|
if (_elevationService == null)
|
|
{
|
|
IsRunningAsAdministrator = false;
|
|
ElevationStatusText = "Elevation service not available";
|
|
ShowElevationPrompt = false;
|
|
return;
|
|
}
|
|
|
|
IsRunningAsAdministrator = _elevationService.IsRunningAsAdministrator();
|
|
ElevationStatusText = _elevationService.GetElevationStatus();
|
|
ShowElevationPrompt = !IsRunningAsAdministrator;
|
|
}
|
|
|
|
private void OnServiceStatusChanged(object? sender, ServiceStatusEventArgs e)
|
|
{
|
|
// Marshal UI updates to the UI thread to prevent cross-thread access exceptions
|
|
System.Windows.Application.Current.Dispatcher.InvokeAsync(() =>
|
|
{
|
|
IsProcessMonitoringActive = e.IsRunning;
|
|
ProcessMonitoringStatusText = $"Process Monitoring: {e.Status}";
|
|
});
|
|
}
|
|
|
|
public void UpdateProcessMonitoringStatus(bool isActive, string status)
|
|
{
|
|
IsProcessMonitoringActive = isActive;
|
|
ProcessMonitoringStatusText = $"Process Monitoring: {status}";
|
|
}
|
|
|
|
protected override void OnDispose()
|
|
{
|
|
if (_processMonitorManagerService != null)
|
|
{
|
|
_processMonitorManagerService.ServiceStatusChanged -= OnServiceStatusChanged;
|
|
}
|
|
|
|
base.OnDispose();
|
|
}
|
|
}
|
|
} |