diff --git a/MainApp/App.xaml.cs b/MainApp/App.xaml.cs index 532f358..5ec511d 100644 --- a/MainApp/App.xaml.cs +++ b/MainApp/App.xaml.cs @@ -52,13 +52,13 @@ namespace MSFSPopoutPanelManager.MainApp services.AddSingleton(); services.AddSingleton(s => new AppOrchestrator(SharedStorage, s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService())); - services.AddSingleton(s => new ProfileOrchestrator(SharedStorage)); + services.AddSingleton(_ => new ProfileOrchestrator(SharedStorage)); services.AddSingleton(s => new PanelSourceOrchestrator(SharedStorage, s.GetRequiredService())); services.AddSingleton(s => new PanelPopOutOrchestrator(SharedStorage, s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService())); services.AddSingleton(s => new PanelConfigurationOrchestrator(SharedStorage, s.GetRequiredService(), s.GetRequiredService())); - services.AddSingleton(s => new FlightSimOrchestrator(SharedStorage)); - services.AddSingleton(s => new KeyboardOrchestrator(SharedStorage)); - services.AddSingleton(s => new HelpOrchestrator()); + services.AddSingleton(_ => new FlightSimOrchestrator(SharedStorage)); + services.AddSingleton(_ => new KeyboardOrchestrator(SharedStorage)); + services.AddSingleton(_ => new HelpOrchestrator()); services.AddSingleton(s => new OrchestratorUiHelper(SharedStorage, s.GetRequiredService(), s.GetRequiredService())); services.AddSingleton(s => new ApplicationViewModel(SharedStorage, s.GetRequiredService())); @@ -69,16 +69,16 @@ namespace MSFSPopoutPanelManager.MainApp services.AddSingleton(s => new PreferenceDrawerViewModel(SharedStorage, s.GetRequiredService())); services.AddTransient(s => new AddProfileViewModel(SharedStorage, s.GetRequiredService(), s.GetRequiredService())); - services.AddTransient(s => new PopOutPanelListViewModel(SharedStorage)); - services.AddTransient(s => new PopOutPanelConfigCardViewModel(SharedStorage, s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService())); + services.AddTransient(_ => new PopOutPanelListViewModel(SharedStorage)); + services.AddTransient(s => new PopOutPanelConfigCardViewModel(SharedStorage, s.GetRequiredService(), s.GetRequiredService())); services.AddTransient(s => new PopOutPanelSourceCardViewModel(SharedStorage, s.GetRequiredService(), s.GetRequiredService())); services.AddTransient(s => new PopOutPanelSourceLegacyCardViewModel(SharedStorage, s.GetRequiredService(), s.GetRequiredService())); services.AddTransient(s => new PanelConfigFieldViewModel(SharedStorage, s.GetRequiredService())); - services.AddTransient(s => new PanelCoorOverlayViewModel(SharedStorage)); + services.AddTransient(_ => new PanelCoorOverlayViewModel(SharedStorage)); services.AddTransient(s => new MessageWindowViewModel(SharedStorage, s.GetRequiredService(), s.GetRequiredService())); services.AddTransient(s => new HudBarViewModel(SharedStorage, s.GetRequiredService())); - services.AddTransient(s => new NumPadViewModel(SharedStorage)); + services.AddTransient(_ => new NumPadViewModel(SharedStorage)); }).Build(); diff --git a/MainApp/AppUserControl/PreferenceDrawer.xaml.cs b/MainApp/AppUserControl/PreferenceDrawer.xaml.cs index 49f33f5..f84f2fa 100644 --- a/MainApp/AppUserControl/PreferenceDrawer.xaml.cs +++ b/MainApp/AppUserControl/PreferenceDrawer.xaml.cs @@ -7,8 +7,6 @@ namespace MSFSPopoutPanelManager.MainApp.AppUserControl { public partial class PreferenceDrawer { - private readonly PreferenceDrawerViewModel _viewModel; - public PreferenceDrawer() { if (DesignerProperties.GetIsInDesignMode(new DependencyObject())) @@ -17,10 +15,10 @@ namespace MSFSPopoutPanelManager.MainApp.AppUserControl return; } - _viewModel = App.AppHost.Services.GetRequiredService(); + var viewModel = App.AppHost.Services.GetRequiredService(); Loaded += (_, _) => { - DataContext = _viewModel; + DataContext = viewModel; InitializeComponent(); }; } diff --git a/MainApp/AppWindow/HudBar.xaml.cs b/MainApp/AppWindow/HudBar.xaml.cs index 7833a6f..6f5bb3f 100644 --- a/MainApp/AppWindow/HudBar.xaml.cs +++ b/MainApp/AppWindow/HudBar.xaml.cs @@ -39,7 +39,7 @@ namespace MSFSPopoutPanelManager.MainApp.AppWindow Closing += HudBar_Closing; } - private void HudBar_Closing(object sender, System.ComponentModel.CancelEventArgs e) + private void HudBar_Closing(object sender, CancelEventArgs e) { _viewModel.CloseCommand.Execute(null); } diff --git a/MainApp/ViewModel/PopOutPanelConfigCardViewModel.cs b/MainApp/ViewModel/PopOutPanelConfigCardViewModel.cs index bd567b5..7ca4b6f 100644 --- a/MainApp/ViewModel/PopOutPanelConfigCardViewModel.cs +++ b/MainApp/ViewModel/PopOutPanelConfigCardViewModel.cs @@ -13,7 +13,6 @@ namespace MSFSPopoutPanelManager.MainApp.ViewModel { private readonly PanelSourceOrchestrator _panelSourceOrchestrator; private readonly PanelConfigurationOrchestrator _panelConfigurationOrchestrator; - private readonly KeyboardOrchestrator _keyboardOrchestrator; public PanelConfig DataItem { get; set; } @@ -31,11 +30,10 @@ namespace MSFSPopoutPanelManager.MainApp.ViewModel public DelegateCommand PanelAttributeUpdatedCommand { get; set; } - public PopOutPanelConfigCardViewModel(SharedStorage sharedStorage, PanelSourceOrchestrator panelSourceOrchestrator, PanelConfigurationOrchestrator panelConfigurationOrchestrator, KeyboardOrchestrator keyboardOrchestrator) : base(sharedStorage) + public PopOutPanelConfigCardViewModel(SharedStorage sharedStorage, PanelSourceOrchestrator panelSourceOrchestrator, PanelConfigurationOrchestrator panelConfigurationOrchestrator) : base(sharedStorage) { _panelSourceOrchestrator = panelSourceOrchestrator; _panelConfigurationOrchestrator = panelConfigurationOrchestrator; - _keyboardOrchestrator = keyboardOrchestrator; DataItem = new PanelConfig(); diff --git a/Orchestration/GlobalKeyboardHook.cs b/Orchestration/GlobalKeyboardHook.cs index ba14909..488bfde 100644 --- a/Orchestration/GlobalKeyboardHook.cs +++ b/Orchestration/GlobalKeyboardHook.cs @@ -22,7 +22,7 @@ namespace MSFSPopoutPanelManager.Orchestration public class GlobalKeyboardHook : IDisposable { - public event EventHandler KeyboardPressed; + public event EventHandler OnKeyboardPressed; public GlobalKeyboardHook() { @@ -100,36 +100,12 @@ namespace MSFSPopoutPanelManager.Orchestration [DllImport("kernel32.dll", CharSet = CharSet.Auto)] private static extern bool FreeLibrary(IntPtr hModule); - /// - /// The SetWindowsHookEx function installs an application-defined hook procedure into a hook chain. - /// You would install a hook procedure to monitor the system for certain types of events. These events are - /// associated either with a specific thread or with all threads in the same desktop as the calling thread. - /// - /// hook type - /// hook procedure - /// handle to application instance - /// thread identifier - /// If the function succeeds, the return value is the handle to the hook procedure. [DllImport("USER32", SetLastError = true)] static extern IntPtr SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hMod, int dwThreadId); - - /// - /// The UnhookWindowsHookEx function removes a hook procedure installed in a hook chain by the SetWindowsHookEx function. - /// - /// handle to hook procedure - /// If the function succeeds, the return value is true. + [DllImport("USER32", SetLastError = true)] public static extern bool UnhookWindowsHookEx(IntPtr hHook); - /// - /// The CallNextHookEx function passes the hook information to the next hook procedure in the current hook chain. - /// A hook procedure can call this function either before or after processing the hook information. - /// - /// handle to current hook - /// hook code passed to hook procedure - /// value passed to hook procedure - /// value passed to hook procedure - /// If the function succeeds, the return value is true. [DllImport("USER32", SetLastError = true)] static extern IntPtr CallNextHookEx(IntPtr hHook, int code, IntPtr wParam, IntPtr lParam); @@ -175,29 +151,19 @@ namespace MSFSPopoutPanelManager.Orchestration SysKeyUp = 0x0105 } - public const int VkSnapshot = 0x2c; - //const int VkLwin = 0x5b; - //const int VkRwin = 0x5c; - //const int VkTab = 0x09; - //const int VkEscape = 0x18; - //const int VkControl = 0x11; - const int KfAltdown = 0x2000; - public const int LlkhfAltdown = (KfAltdown >> 8); - public IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam) { - bool fEatKeyStroke = false; + var fEatKeyStroke = false; - var wparamTyped = wParam.ToInt32(); - if (Enum.IsDefined(typeof(KeyboardState), wparamTyped)) + var wParamTyped = wParam.ToInt32(); + if (Enum.IsDefined(typeof(KeyboardState), wParamTyped)) { - object o = Marshal.PtrToStructure(lParam, typeof(LowLevelKeyboardInputEvent)); - LowLevelKeyboardInputEvent p = (LowLevelKeyboardInputEvent)o; + var o = Marshal.PtrToStructure(lParam, typeof(LowLevelKeyboardInputEvent)); + var p = (LowLevelKeyboardInputEvent)o; - var eventArguments = new GlobalKeyboardHookEventArgs(p, (KeyboardState)wparamTyped); + var eventArguments = new GlobalKeyboardHookEventArgs(p, (KeyboardState)wParamTyped); - EventHandler handler = KeyboardPressed; - handler?.Invoke(this, eventArguments); + OnKeyboardPressed?.Invoke(this, eventArguments); fEatKeyStroke = eventArguments.Handled; } diff --git a/Orchestration/KeyboardOrchestrator.cs b/Orchestration/KeyboardOrchestrator.cs index e90bb51..e208b38 100644 --- a/Orchestration/KeyboardOrchestrator.cs +++ b/Orchestration/KeyboardOrchestrator.cs @@ -51,8 +51,8 @@ namespace MSFSPopoutPanelManager.Orchestration Debug.WriteLine("Starts Global Keyboard Hook"); _globalKeyboardHook ??= new GlobalKeyboardHook(); - _globalKeyboardHook.KeyboardPressed -= HandleGlobalKeyboardHookOnKeyboardPressed; - _globalKeyboardHook.KeyboardPressed += HandleGlobalKeyboardHookOnKeyboardPressed; + _globalKeyboardHook.OnKeyboardPressed -= HandleGlobalKeyboardHookOnKeyboardPressed; + _globalKeyboardHook.OnKeyboardPressed += HandleGlobalKeyboardHookOnKeyboardPressed; } public void EndGlobalKeyboardHook(KeyboardHookClientType clientType) @@ -69,7 +69,7 @@ namespace MSFSPopoutPanelManager.Orchestration { Debug.WriteLine("Ends Global Keyboard Hook (Forced)"); _keyPressCaptureList = new List(); - _globalKeyboardHook.KeyboardPressed -= HandleGlobalKeyboardHookOnKeyboardPressed; + _globalKeyboardHook.OnKeyboardPressed -= HandleGlobalKeyboardHookOnKeyboardPressed; _globalKeyboardHook?.Dispose(); _globalKeyboardHook = null; } @@ -138,7 +138,6 @@ namespace MSFSPopoutPanelManager.Orchestration Unknown, PreferenceConfigurationDetection, StartPopOutKeyboardShortcut, - PanelPositionConfiguration, FloatingPanelDetection, FloatingPanel, diff --git a/Orchestration/PanelPopOutOrchestrator.cs b/Orchestration/PanelPopOutOrchestrator.cs index 8ad22ac..aa3120b 100644 --- a/Orchestration/PanelPopOutOrchestrator.cs +++ b/Orchestration/PanelPopOutOrchestrator.cs @@ -17,8 +17,6 @@ namespace MSFSPopoutPanelManager.Orchestration private const int CAMERA_VIEW_HOME_COCKPIT_MODE = 8; private const int CAMERA_VIEW_CUSTOM_CAMERA = 7; - private bool _isPopOutExecuting = false; - private readonly FlightSimOrchestrator _flightSimOrchestrator; private readonly PanelSourceOrchestrator _panelSourceOrchestrator; private readonly PanelConfigurationOrchestrator _panelConfigurationOrchestrator; @@ -37,10 +35,10 @@ namespace MSFSPopoutPanelManager.Orchestration await AutoPopOut(); }; - _keyboardOrchestrator.OnKeystrokeDetected += (_, e) => + _keyboardOrchestrator.OnKeystrokeDetected += async (_, e) => { if (e.KeyBinding == AppSetting.KeyboardShortcutSetting.PopOutKeyboardBinding && !ActiveProfile.IsDisabledStartPopOut) - ManualPopOut(); + await ManualPopOut(); }; } @@ -66,8 +64,6 @@ namespace MSFSPopoutPanelManager.Orchestration public async Task AutoPopOut() { - _isPopOutExecuting = true; - await Application.Current.Dispatcher.Invoke(async () => { ProfileData.AutoSwitchProfile(); diff --git a/WindowsAgent/PInvoke.cs b/WindowsAgent/PInvoke.cs index 4d3d7de..97a7909 100644 --- a/WindowsAgent/PInvoke.cs +++ b/WindowsAgent/PInvoke.cs @@ -50,12 +50,6 @@ namespace MSFSPopoutPanelManager.WindowsAgent [DllImport("user32.dll", SetLastError = true)] public static extern int EnumWindows(CallBack callback, int lParam); - [DllImport("user32.dll", SetLastError = true)] - public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); - - [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)] - public static extern IntPtr FindWindowByCaption(IntPtr zeroOnly, string lpWindowName); - [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern int GetClassName(IntPtr hWnd, StringBuilder strPtrClassName, Int32 nMaxCount); @@ -108,15 +102,10 @@ namespace MSFSPopoutPanelManager.WindowsAgent catch { return string.Empty; } } - [DllImport("user32.dll", SetLastError = true)] - public static extern bool GetClientRect(IntPtr hWnd, out Rectangle lpRect); [DllImport("user32.dll", SetLastError = true)] public static extern bool MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint); - - [DllImport("user32.dll", SetLastError = true)] - [return: MarshalAs(UnmanagedType.Bool)] - public static extern bool IsWindow(IntPtr hWnd); + [DllImport("user32.dll", SetLastError = true)] public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo); diff --git a/WindowsAgent/WindowActionManager.cs b/WindowsAgent/WindowActionManager.cs index 3783015..2656e06 100644 --- a/WindowsAgent/WindowActionManager.cs +++ b/WindowsAgent/WindowActionManager.cs @@ -62,11 +62,6 @@ namespace MSFSPopoutPanelManager.WindowsAgent } } - public static IntPtr FindWindowByClass(string className) - { - return PInvoke.FindWindow(className, null); - } - public static void CloseWindow(IntPtr hwnd) { PInvoke.SendMessage(hwnd, PInvokeConstant.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);