1ab85b21bd
Bump release to v1.1.1 and add release/build packaging, installer and onboarding enhancements. Key changes: - Version bump across csproj, README and release assets to 1.1.1. - CI/workflow: copy bundled Powerplans into single-file output, install Inno Setup, build Inno Setup installer, include installer artifacts in GitHub release, and stage unified package zips with uninstall/license files. - Installer: update InstallScript (setup.iss) to point to staged artifacts, include Powerplans folder, and output installer to artifacts/release/installer. - App startup/elevation: requireAdministrator manifest and App.xaml.cs now requests elevation early, terminating non-elevated instance when elevation is requested/declined. - UX: add Performance first-run onboarding overlay (modal with blurred background), updated loading overlay visuals, and related MainWindow logic to show/hide intro and persist seen state. - Settings & config: implement export/import configuration bundle (JSON) with Save/Open dialogs, add ReplaceConfigurationAsync and CloneConfiguration in association service, and adjust settings view labels. - Power plan features: add PowerPlanService.AddCustomPowerPlanFileAsync and UI/command to add .pow files; adjust Import/Apply button labels. - Performance tweaks: reduce power plan change delay from 1000ms to 250ms in config, models and viewmodels. - Theme detection: improve ThemeService to resolve registry values and fallback to system theme helper. - Misc: various logging/status improvements, packaging script fixes (build-release/build-msix), and added package-release-zips script. These changes prepare the project for a formal 1.1.1 release with installer distribution, improved elevation handling and onboarding, plus enhanced import/export and custom power plan support.
215 lines
7.8 KiB
C#
215 lines
7.8 KiB
C#
/*
|
|
* ThreadPilot - Advanced Windows Process and Power Plan Manager
|
|
* Copyright (C) 2025 Prime Build
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
* the Free Software Foundation, version 3 only.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
namespace ThreadPilot
|
|
{
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using Microsoft.Extensions.Logging;
|
|
using ThreadPilot.Models;
|
|
using ThreadPilot.Services;
|
|
using ThreadPilot.ViewModels;
|
|
|
|
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;
|
|
|
|
[ObservableProperty]
|
|
private string initializationStage = "Starting ThreadPilot...";
|
|
|
|
[ObservableProperty]
|
|
private string initializationDetails = "Preparing startup sequence.";
|
|
|
|
[ObservableProperty]
|
|
private bool isDarkTheme = false;
|
|
|
|
public MainWindowViewModel(
|
|
ILogger<MainWindowViewModel> logger,
|
|
IEnhancedLoggingService? enhancedLoggingService = null,
|
|
IProcessMonitorManagerService? processMonitorManagerService = null,
|
|
INotificationService? notificationService = null,
|
|
IElevationService? elevationService = null,
|
|
ISecurityService? securityService = null)
|
|
: base(logger, enhancedLoggingService)
|
|
{
|
|
this.processMonitorManagerService = processMonitorManagerService;
|
|
this.notificationService = notificationService;
|
|
this.elevationService = elevationService;
|
|
this.securityService = securityService;
|
|
}
|
|
|
|
public override async Task InitializeAsync()
|
|
{
|
|
await this.ExecuteAsync(
|
|
async () =>
|
|
{
|
|
// Subscribe to service events
|
|
if (this.processMonitorManagerService != null)
|
|
{
|
|
this.processMonitorManagerService.ServiceStatusChanged += this.OnServiceStatusChanged;
|
|
}
|
|
|
|
// Initialize status
|
|
await this.UpdateStatusAsync();
|
|
this.UpdateElevationStatus();
|
|
|
|
await this.LogUserActionAsync("MainWindow", "Initialized main window", "Application startup");
|
|
}, "Initializing main window...");
|
|
}
|
|
|
|
[RelayCommand]
|
|
private async Task ToggleProcessMonitoringAsync()
|
|
{
|
|
if (this.processMonitorManagerService == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
await this.ExecuteAsync(
|
|
async () =>
|
|
{
|
|
if (this.IsProcessMonitoringActive)
|
|
{
|
|
await this.processMonitorManagerService.StopAsync();
|
|
await this.LogUserActionAsync("ProcessMonitoring", "Stopped process monitoring", "User action");
|
|
}
|
|
else
|
|
{
|
|
await this.processMonitorManagerService.StartAsync();
|
|
await this.LogUserActionAsync("ProcessMonitoring", "Started process monitoring", "User action");
|
|
}
|
|
}, this.IsProcessMonitoringActive ? "Stopping monitoring..." : "Starting monitoring...");
|
|
}
|
|
|
|
[RelayCommand]
|
|
private async Task RequestElevationAsync()
|
|
{
|
|
if (this.elevationService == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
await this.ExecuteAsync(
|
|
async () =>
|
|
{
|
|
var success = await this.elevationService.RequestElevationIfNeeded();
|
|
if (success)
|
|
{
|
|
await this.LogUserActionAsync("Elevation", "Requested elevation", "User action");
|
|
}
|
|
else
|
|
{
|
|
await this.LogUserActionAsync("Elevation", "Elevation request failed or cancelled", "User action");
|
|
}
|
|
}, "Requesting elevation...");
|
|
}
|
|
|
|
private async Task UpdateStatusAsync()
|
|
{
|
|
try
|
|
{
|
|
// Update process monitoring status
|
|
if (this.processMonitorManagerService != null)
|
|
{
|
|
this.IsProcessMonitoringActive = this.processMonitorManagerService.IsRunning;
|
|
this.ProcessMonitoringStatusText = this.IsProcessMonitoringActive
|
|
? "Process Monitoring: Active"
|
|
: "Process Monitoring: Inactive";
|
|
}
|
|
|
|
// Update elevation status
|
|
this.UpdateElevationStatus();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.SetError("Failed to update status", ex);
|
|
}
|
|
}
|
|
|
|
private void UpdateElevationStatus()
|
|
{
|
|
if (this.elevationService == null)
|
|
{
|
|
this.IsRunningAsAdministrator = false;
|
|
this.ElevationStatusText = "Elevation service not available";
|
|
this.ShowElevationPrompt = false;
|
|
return;
|
|
}
|
|
|
|
this.IsRunningAsAdministrator = this.elevationService.IsRunningAsAdministrator();
|
|
this.ElevationStatusText = this.elevationService.GetElevationStatus();
|
|
this.ShowElevationPrompt = !this.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(() =>
|
|
{
|
|
this.IsProcessMonitoringActive = e.IsRunning;
|
|
this.ProcessMonitoringStatusText = $"Process Monitoring: {e.Status}";
|
|
});
|
|
}
|
|
|
|
public void UpdateProcessMonitoringStatus(bool isActive, string status)
|
|
{
|
|
if (System.Windows.Application.Current.Dispatcher.CheckAccess())
|
|
{
|
|
this.IsProcessMonitoringActive = isActive;
|
|
this.ProcessMonitoringStatusText = $"Process Monitoring: {status}";
|
|
}
|
|
else
|
|
{
|
|
System.Windows.Application.Current.Dispatcher.InvokeAsync(() =>
|
|
{
|
|
this.IsProcessMonitoringActive = isActive;
|
|
this.ProcessMonitoringStatusText = $"Process Monitoring: {status}";
|
|
});
|
|
}
|
|
}
|
|
|
|
protected override void OnDispose()
|
|
{
|
|
if (this.processMonitorManagerService != null)
|
|
{
|
|
this.processMonitorManagerService.ServiceStatusChanged -= this.OnServiceStatusChanged;
|
|
}
|
|
|
|
base.OnDispose();
|
|
}
|
|
}
|
|
}
|