/* * 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 . */ namespace ThreadPilot.Services { using System; using System.Collections.Generic; using System.Threading.Tasks; using System.Windows.Input; /// /// Service for managing global keyboard shortcuts. /// public interface IKeyboardShortcutService { /// /// Event raised when a registered shortcut is activated /// event EventHandler? ShortcutActivated; /// /// Register a global keyboard shortcut. /// Task RegisterShortcutAsync(string actionName, Key key, ModifierKeys modifiers); /// /// Unregister a keyboard shortcut. /// Task UnregisterShortcutAsync(string actionName); /// /// Update an existing shortcut with new key combination. /// Task UpdateShortcutAsync(string actionName, Key key, ModifierKeys modifiers); /// /// Get all registered shortcuts. /// Task> GetRegisteredShortcutsAsync(); /// /// Check if a key combination is already registered. /// Task IsShortcutRegisteredAsync(Key key, ModifierKeys modifiers); /// /// Load shortcuts from settings. /// Task LoadShortcutsFromSettingsAsync(); /// /// Save shortcuts to settings. /// Task SaveShortcutsToSettingsAsync(); /// /// Clear all registered shortcuts. /// Task ClearAllShortcutsAsync(); /// /// Get the default shortcuts for the application. /// Dictionary GetDefaultShortcuts(); } /// /// Represents a keyboard shortcut. /// public class KeyboardShortcut { public string ActionName { get; set; } = string.Empty; public Key Key { get; set; } public ModifierKeys Modifiers { get; set; } public string Description { get; set; } = string.Empty; public bool IsEnabled { get; set; } = true; public bool IsGlobal { get; set; } = true; public override string ToString() { var parts = new List(); if (this.Modifiers.HasFlag(ModifierKeys.Control)) { parts.Add("Ctrl"); } if (this.Modifiers.HasFlag(ModifierKeys.Alt)) { parts.Add("Alt"); } if (this.Modifiers.HasFlag(ModifierKeys.Shift)) { parts.Add("Shift"); } if (this.Modifiers.HasFlag(ModifierKeys.Windows)) { parts.Add("Win"); } parts.Add(this.Key.ToString()); return string.Join(" + ", parts); } } /// /// Event args for shortcut activation. /// public class ShortcutActivatedEventArgs : EventArgs { public string ActionName { get; } public KeyboardShortcut Shortcut { get; } public DateTime ActivationTime { get; } public ShortcutActivatedEventArgs(string actionName, KeyboardShortcut shortcut) { this.ActionName = actionName; this.Shortcut = shortcut; this.ActivationTime = DateTime.UtcNow; } } /// /// Predefined shortcut actions. /// public static class ShortcutActions { public const string QuickApply = "QuickApply"; public const string ToggleMonitoring = "ToggleMonitoring"; public const string ShowMainWindow = "ShowMainWindow"; public const string HideToTray = "HideToTray"; public const string PowerPlanBalanced = "PowerPlanBalanced"; public const string PowerPlanHighPerformance = "PowerPlanHighPerformance"; public const string PowerPlanPowerSaver = "PowerPlanPowerSaver"; public const string RefreshProcessList = "RefreshProcessList"; public const string OpenSettings = "OpenSettings"; public const string OpenTweaks = "OpenTweaks"; public const string ExitApplication = "ExitApplication"; } }