1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-12-04 11:40:10 +00:00

Refactor code

This commit is contained in:
hawkeye 2024-03-03 22:10:13 -05:00
parent 57baed9291
commit e460a85c1a
9 changed files with 27 additions and 86 deletions

View file

@ -52,13 +52,13 @@ namespace MSFSPopoutPanelManager.MainApp
services.AddSingleton<AppMainWindow>(); services.AddSingleton<AppMainWindow>();
services.AddSingleton(s => new AppOrchestrator(SharedStorage, s.GetRequiredService<PanelConfigurationOrchestrator>(), s.GetRequiredService<FlightSimOrchestrator>(), s.GetRequiredService<HelpOrchestrator>(), s.GetRequiredService<KeyboardOrchestrator>())); services.AddSingleton(s => new AppOrchestrator(SharedStorage, s.GetRequiredService<PanelConfigurationOrchestrator>(), s.GetRequiredService<FlightSimOrchestrator>(), s.GetRequiredService<HelpOrchestrator>(), s.GetRequiredService<KeyboardOrchestrator>()));
services.AddSingleton(s => new ProfileOrchestrator(SharedStorage)); services.AddSingleton(_ => new ProfileOrchestrator(SharedStorage));
services.AddSingleton(s => new PanelSourceOrchestrator(SharedStorage, s.GetRequiredService<FlightSimOrchestrator>())); services.AddSingleton(s => new PanelSourceOrchestrator(SharedStorage, s.GetRequiredService<FlightSimOrchestrator>()));
services.AddSingleton(s => new PanelPopOutOrchestrator(SharedStorage, s.GetRequiredService<FlightSimOrchestrator>(), s.GetRequiredService<PanelSourceOrchestrator>(), s.GetRequiredService<PanelConfigurationOrchestrator>(), s.GetRequiredService<KeyboardOrchestrator>())); services.AddSingleton(s => new PanelPopOutOrchestrator(SharedStorage, s.GetRequiredService<FlightSimOrchestrator>(), s.GetRequiredService<PanelSourceOrchestrator>(), s.GetRequiredService<PanelConfigurationOrchestrator>(), s.GetRequiredService<KeyboardOrchestrator>()));
services.AddSingleton(s => new PanelConfigurationOrchestrator(SharedStorage, s.GetRequiredService<FlightSimOrchestrator>(), s.GetRequiredService<KeyboardOrchestrator>())); services.AddSingleton(s => new PanelConfigurationOrchestrator(SharedStorage, s.GetRequiredService<FlightSimOrchestrator>(), s.GetRequiredService<KeyboardOrchestrator>()));
services.AddSingleton(s => new FlightSimOrchestrator(SharedStorage)); services.AddSingleton(_ => new FlightSimOrchestrator(SharedStorage));
services.AddSingleton(s => new KeyboardOrchestrator(SharedStorage)); services.AddSingleton(_ => new KeyboardOrchestrator(SharedStorage));
services.AddSingleton(s => new HelpOrchestrator()); services.AddSingleton(_ => new HelpOrchestrator());
services.AddSingleton(s => new OrchestratorUiHelper(SharedStorage, s.GetRequiredService<PanelSourceOrchestrator>(), s.GetRequiredService<PanelPopOutOrchestrator>())); services.AddSingleton(s => new OrchestratorUiHelper(SharedStorage, s.GetRequiredService<PanelSourceOrchestrator>(), s.GetRequiredService<PanelPopOutOrchestrator>()));
services.AddSingleton(s => new ApplicationViewModel(SharedStorage, s.GetRequiredService<AppOrchestrator>())); services.AddSingleton(s => new ApplicationViewModel(SharedStorage, s.GetRequiredService<AppOrchestrator>()));
@ -69,16 +69,16 @@ namespace MSFSPopoutPanelManager.MainApp
services.AddSingleton(s => new PreferenceDrawerViewModel(SharedStorage, s.GetRequiredService<KeyboardOrchestrator>())); services.AddSingleton(s => new PreferenceDrawerViewModel(SharedStorage, s.GetRequiredService<KeyboardOrchestrator>()));
services.AddTransient(s => new AddProfileViewModel(SharedStorage, s.GetRequiredService<ProfileOrchestrator>(), s.GetRequiredService<PanelSourceOrchestrator>())); services.AddTransient(s => new AddProfileViewModel(SharedStorage, s.GetRequiredService<ProfileOrchestrator>(), s.GetRequiredService<PanelSourceOrchestrator>()));
services.AddTransient(s => new PopOutPanelListViewModel(SharedStorage)); services.AddTransient(_ => new PopOutPanelListViewModel(SharedStorage));
services.AddTransient(s => new PopOutPanelConfigCardViewModel(SharedStorage, s.GetRequiredService<PanelSourceOrchestrator>(), s.GetRequiredService<PanelConfigurationOrchestrator>(), s.GetRequiredService<KeyboardOrchestrator>())); services.AddTransient(s => new PopOutPanelConfigCardViewModel(SharedStorage, s.GetRequiredService<PanelSourceOrchestrator>(), s.GetRequiredService<PanelConfigurationOrchestrator>()));
services.AddTransient(s => new PopOutPanelSourceCardViewModel(SharedStorage, s.GetRequiredService<PanelSourceOrchestrator>(), s.GetRequiredService<PanelConfigurationOrchestrator>())); services.AddTransient(s => new PopOutPanelSourceCardViewModel(SharedStorage, s.GetRequiredService<PanelSourceOrchestrator>(), s.GetRequiredService<PanelConfigurationOrchestrator>()));
services.AddTransient(s => new PopOutPanelSourceLegacyCardViewModel(SharedStorage, s.GetRequiredService<PanelSourceOrchestrator>(), s.GetRequiredService<PanelConfigurationOrchestrator>())); services.AddTransient(s => new PopOutPanelSourceLegacyCardViewModel(SharedStorage, s.GetRequiredService<PanelSourceOrchestrator>(), s.GetRequiredService<PanelConfigurationOrchestrator>()));
services.AddTransient(s => new PanelConfigFieldViewModel(SharedStorage, s.GetRequiredService<PanelConfigurationOrchestrator>())); services.AddTransient(s => new PanelConfigFieldViewModel(SharedStorage, s.GetRequiredService<PanelConfigurationOrchestrator>()));
services.AddTransient(s => new PanelCoorOverlayViewModel(SharedStorage)); services.AddTransient(_ => new PanelCoorOverlayViewModel(SharedStorage));
services.AddTransient(s => new MessageWindowViewModel(SharedStorage, s.GetRequiredService<PanelSourceOrchestrator>(), s.GetRequiredService<PanelPopOutOrchestrator>())); services.AddTransient(s => new MessageWindowViewModel(SharedStorage, s.GetRequiredService<PanelSourceOrchestrator>(), s.GetRequiredService<PanelPopOutOrchestrator>()));
services.AddTransient(s => new HudBarViewModel(SharedStorage, s.GetRequiredService<FlightSimOrchestrator>())); services.AddTransient(s => new HudBarViewModel(SharedStorage, s.GetRequiredService<FlightSimOrchestrator>()));
services.AddTransient(s => new NumPadViewModel(SharedStorage)); services.AddTransient(_ => new NumPadViewModel(SharedStorage));
}).Build(); }).Build();

View file

@ -7,8 +7,6 @@ namespace MSFSPopoutPanelManager.MainApp.AppUserControl
{ {
public partial class PreferenceDrawer public partial class PreferenceDrawer
{ {
private readonly PreferenceDrawerViewModel _viewModel;
public PreferenceDrawer() public PreferenceDrawer()
{ {
if (DesignerProperties.GetIsInDesignMode(new DependencyObject())) if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
@ -17,10 +15,10 @@ namespace MSFSPopoutPanelManager.MainApp.AppUserControl
return; return;
} }
_viewModel = App.AppHost.Services.GetRequiredService<PreferenceDrawerViewModel>(); var viewModel = App.AppHost.Services.GetRequiredService<PreferenceDrawerViewModel>();
Loaded += (_, _) => Loaded += (_, _) =>
{ {
DataContext = _viewModel; DataContext = viewModel;
InitializeComponent(); InitializeComponent();
}; };
} }

View file

@ -39,7 +39,7 @@ namespace MSFSPopoutPanelManager.MainApp.AppWindow
Closing += HudBar_Closing; 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); _viewModel.CloseCommand.Execute(null);
} }

View file

@ -13,7 +13,6 @@ namespace MSFSPopoutPanelManager.MainApp.ViewModel
{ {
private readonly PanelSourceOrchestrator _panelSourceOrchestrator; private readonly PanelSourceOrchestrator _panelSourceOrchestrator;
private readonly PanelConfigurationOrchestrator _panelConfigurationOrchestrator; private readonly PanelConfigurationOrchestrator _panelConfigurationOrchestrator;
private readonly KeyboardOrchestrator _keyboardOrchestrator;
public PanelConfig DataItem { get; set; } public PanelConfig DataItem { get; set; }
@ -31,11 +30,10 @@ namespace MSFSPopoutPanelManager.MainApp.ViewModel
public DelegateCommand<string> PanelAttributeUpdatedCommand { get; set; } public DelegateCommand<string> 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; _panelSourceOrchestrator = panelSourceOrchestrator;
_panelConfigurationOrchestrator = panelConfigurationOrchestrator; _panelConfigurationOrchestrator = panelConfigurationOrchestrator;
_keyboardOrchestrator = keyboardOrchestrator;
DataItem = new PanelConfig(); DataItem = new PanelConfig();

View file

@ -22,7 +22,7 @@ namespace MSFSPopoutPanelManager.Orchestration
public class GlobalKeyboardHook : IDisposable public class GlobalKeyboardHook : IDisposable
{ {
public event EventHandler<GlobalKeyboardHookEventArgs> KeyboardPressed; public event EventHandler<GlobalKeyboardHookEventArgs> OnKeyboardPressed;
public GlobalKeyboardHook() public GlobalKeyboardHook()
{ {
@ -100,36 +100,12 @@ namespace MSFSPopoutPanelManager.Orchestration
[DllImport("kernel32.dll", CharSet = CharSet.Auto)] [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
private static extern bool FreeLibrary(IntPtr hModule); private static extern bool FreeLibrary(IntPtr hModule);
/// <summary>
/// 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.
/// </summary>
/// <param name="idHook">hook type</param>
/// <param name="lpfn">hook procedure</param>
/// <param name="hMod">handle to application instance</param>
/// <param name="dwThreadId">thread identifier</param>
/// <returns>If the function succeeds, the return value is the handle to the hook procedure.</returns>
[DllImport("USER32", SetLastError = true)] [DllImport("USER32", SetLastError = true)]
static extern IntPtr SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hMod, int dwThreadId); static extern IntPtr SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hMod, int dwThreadId);
/// <summary>
/// The UnhookWindowsHookEx function removes a hook procedure installed in a hook chain by the SetWindowsHookEx function.
/// </summary>
/// <param name="hhk">handle to hook procedure</param>
/// <returns>If the function succeeds, the return value is true.</returns>
[DllImport("USER32", SetLastError = true)] [DllImport("USER32", SetLastError = true)]
public static extern bool UnhookWindowsHookEx(IntPtr hHook); public static extern bool UnhookWindowsHookEx(IntPtr hHook);
/// <summary>
/// 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.
/// </summary>
/// <param name="hHook">handle to current hook</param>
/// <param name="code">hook code passed to hook procedure</param>
/// <param name="wParam">value passed to hook procedure</param>
/// <param name="lParam">value passed to hook procedure</param>
/// <returns>If the function succeeds, the return value is true.</returns>
[DllImport("USER32", SetLastError = true)] [DllImport("USER32", SetLastError = true)]
static extern IntPtr CallNextHookEx(IntPtr hHook, int code, IntPtr wParam, IntPtr lParam); static extern IntPtr CallNextHookEx(IntPtr hHook, int code, IntPtr wParam, IntPtr lParam);
@ -175,29 +151,19 @@ namespace MSFSPopoutPanelManager.Orchestration
SysKeyUp = 0x0105 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) public IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam)
{ {
bool fEatKeyStroke = false; var fEatKeyStroke = false;
var wparamTyped = wParam.ToInt32(); var wParamTyped = wParam.ToInt32();
if (Enum.IsDefined(typeof(KeyboardState), wparamTyped)) if (Enum.IsDefined(typeof(KeyboardState), wParamTyped))
{ {
object o = Marshal.PtrToStructure(lParam, typeof(LowLevelKeyboardInputEvent)); var o = Marshal.PtrToStructure(lParam, typeof(LowLevelKeyboardInputEvent));
LowLevelKeyboardInputEvent p = (LowLevelKeyboardInputEvent)o; var p = (LowLevelKeyboardInputEvent)o;
var eventArguments = new GlobalKeyboardHookEventArgs(p, (KeyboardState)wparamTyped); var eventArguments = new GlobalKeyboardHookEventArgs(p, (KeyboardState)wParamTyped);
EventHandler<GlobalKeyboardHookEventArgs> handler = KeyboardPressed; OnKeyboardPressed?.Invoke(this, eventArguments);
handler?.Invoke(this, eventArguments);
fEatKeyStroke = eventArguments.Handled; fEatKeyStroke = eventArguments.Handled;
} }

View file

@ -51,8 +51,8 @@ namespace MSFSPopoutPanelManager.Orchestration
Debug.WriteLine("Starts Global Keyboard Hook"); Debug.WriteLine("Starts Global Keyboard Hook");
_globalKeyboardHook ??= new GlobalKeyboardHook(); _globalKeyboardHook ??= new GlobalKeyboardHook();
_globalKeyboardHook.KeyboardPressed -= HandleGlobalKeyboardHookOnKeyboardPressed; _globalKeyboardHook.OnKeyboardPressed -= HandleGlobalKeyboardHookOnKeyboardPressed;
_globalKeyboardHook.KeyboardPressed += HandleGlobalKeyboardHookOnKeyboardPressed; _globalKeyboardHook.OnKeyboardPressed += HandleGlobalKeyboardHookOnKeyboardPressed;
} }
public void EndGlobalKeyboardHook(KeyboardHookClientType clientType) public void EndGlobalKeyboardHook(KeyboardHookClientType clientType)
@ -69,7 +69,7 @@ namespace MSFSPopoutPanelManager.Orchestration
{ {
Debug.WriteLine("Ends Global Keyboard Hook (Forced)"); Debug.WriteLine("Ends Global Keyboard Hook (Forced)");
_keyPressCaptureList = new List<string>(); _keyPressCaptureList = new List<string>();
_globalKeyboardHook.KeyboardPressed -= HandleGlobalKeyboardHookOnKeyboardPressed; _globalKeyboardHook.OnKeyboardPressed -= HandleGlobalKeyboardHookOnKeyboardPressed;
_globalKeyboardHook?.Dispose(); _globalKeyboardHook?.Dispose();
_globalKeyboardHook = null; _globalKeyboardHook = null;
} }
@ -138,7 +138,6 @@ namespace MSFSPopoutPanelManager.Orchestration
Unknown, Unknown,
PreferenceConfigurationDetection, PreferenceConfigurationDetection,
StartPopOutKeyboardShortcut, StartPopOutKeyboardShortcut,
PanelPositionConfiguration,
FloatingPanelDetection, FloatingPanelDetection,
FloatingPanel, FloatingPanel,

View file

@ -17,8 +17,6 @@ namespace MSFSPopoutPanelManager.Orchestration
private const int CAMERA_VIEW_HOME_COCKPIT_MODE = 8; private const int CAMERA_VIEW_HOME_COCKPIT_MODE = 8;
private const int CAMERA_VIEW_CUSTOM_CAMERA = 7; private const int CAMERA_VIEW_CUSTOM_CAMERA = 7;
private bool _isPopOutExecuting = false;
private readonly FlightSimOrchestrator _flightSimOrchestrator; private readonly FlightSimOrchestrator _flightSimOrchestrator;
private readonly PanelSourceOrchestrator _panelSourceOrchestrator; private readonly PanelSourceOrchestrator _panelSourceOrchestrator;
private readonly PanelConfigurationOrchestrator _panelConfigurationOrchestrator; private readonly PanelConfigurationOrchestrator _panelConfigurationOrchestrator;
@ -37,10 +35,10 @@ namespace MSFSPopoutPanelManager.Orchestration
await AutoPopOut(); await AutoPopOut();
}; };
_keyboardOrchestrator.OnKeystrokeDetected += (_, e) => _keyboardOrchestrator.OnKeystrokeDetected += async (_, e) =>
{ {
if (e.KeyBinding == AppSetting.KeyboardShortcutSetting.PopOutKeyboardBinding && !ActiveProfile.IsDisabledStartPopOut) if (e.KeyBinding == AppSetting.KeyboardShortcutSetting.PopOutKeyboardBinding && !ActiveProfile.IsDisabledStartPopOut)
ManualPopOut(); await ManualPopOut();
}; };
} }
@ -66,8 +64,6 @@ namespace MSFSPopoutPanelManager.Orchestration
public async Task AutoPopOut() public async Task AutoPopOut()
{ {
_isPopOutExecuting = true;
await Application.Current.Dispatcher.Invoke(async () => await Application.Current.Dispatcher.Invoke(async () =>
{ {
ProfileData.AutoSwitchProfile(); ProfileData.AutoSwitchProfile();

View file

@ -50,12 +50,6 @@ namespace MSFSPopoutPanelManager.WindowsAgent
[DllImport("user32.dll", SetLastError = true)] [DllImport("user32.dll", SetLastError = true)]
public static extern int EnumWindows(CallBack callback, int lParam); 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)] [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern int GetClassName(IntPtr hWnd, StringBuilder strPtrClassName, Int32 nMaxCount); private static extern int GetClassName(IntPtr hWnd, StringBuilder strPtrClassName, Int32 nMaxCount);
@ -108,15 +102,10 @@ namespace MSFSPopoutPanelManager.WindowsAgent
catch { return string.Empty; } catch { return string.Empty; }
} }
[DllImport("user32.dll", SetLastError = true)]
public static extern bool GetClientRect(IntPtr hWnd, out Rectangle lpRect);
[DllImport("user32.dll", SetLastError = true)] [DllImport("user32.dll", SetLastError = true)]
public static extern bool MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint); 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)] [DllImport("user32.dll", SetLastError = true)]
public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo); public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);

View file

@ -62,11 +62,6 @@ namespace MSFSPopoutPanelManager.WindowsAgent
} }
} }
public static IntPtr FindWindowByClass(string className)
{
return PInvoke.FindWindow(className, null);
}
public static void CloseWindow(IntPtr hwnd) public static void CloseWindow(IntPtr hwnd)
{ {
PInvoke.SendMessage(hwnd, PInvokeConstant.WM_CLOSE, IntPtr.Zero, IntPtr.Zero); PInvoke.SendMessage(hwnd, PInvokeConstant.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);