1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-21 13:20:11 +00:00

Update timing code

This commit is contained in:
hawkeye 2023-08-01 23:39:03 -04:00
parent 988ffae245
commit d169223912
4 changed files with 62 additions and 57 deletions

View file

@ -5,6 +5,9 @@ using MSFSPopoutPanelManager.Orchestration;
using MSFSPopoutPanelManager.Shared; using MSFSPopoutPanelManager.Shared;
using MSFSPopoutPanelManager.WindowsAgent; using MSFSPopoutPanelManager.WindowsAgent;
using System; using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -26,58 +29,7 @@ namespace MSFSPopoutPanelManager.MainApp
DpiAwareness.Enable(); DpiAwareness.Enable();
// Must run this first // Must run this first
Initialize(); if(IsRunning())
// Setup dependency injections
AppHost = Host.CreateDefaultBuilder()
.ConfigureServices((hostContext, services) =>
{
services.AddSingleton<AppWindow>();
services.AddSingleton<MainOrchestrator>();
services.AddSingleton<OrchestratorUIHelper>(s => new OrchestratorUIHelper(s.GetRequiredService<MainOrchestrator>()));
services.AddSingleton<ApplicationViewModel>(s => new ApplicationViewModel(s.GetRequiredService<MainOrchestrator>()));
services.AddSingleton<HelpViewModel>(s => new HelpViewModel(s.GetRequiredService<MainOrchestrator>()));
services.AddSingleton<ProfileCardListViewModel>(s => new ProfileCardListViewModel(s.GetRequiredService<MainOrchestrator>()));
services.AddSingleton<ProfileCardViewModel>(s => new ProfileCardViewModel(s.GetRequiredService<MainOrchestrator>()));
services.AddSingleton<TrayIconViewModel>(s => new TrayIconViewModel(s.GetRequiredService<MainOrchestrator>()));
services.AddTransient<AddProfileViewModel>(s => new AddProfileViewModel(s.GetRequiredService<MainOrchestrator>()));
services.AddTransient<PopOutPanelListViewModel>(s => new PopOutPanelListViewModel(s.GetRequiredService<MainOrchestrator>()));
services.AddTransient<PopOutPanelCardViewModel>(s => new PopOutPanelCardViewModel(s.GetRequiredService<MainOrchestrator>()));
services.AddTransient<PanelConfigFieldViewModel>(s => new PanelConfigFieldViewModel(s.GetRequiredService<MainOrchestrator>()));
services.AddTransient<PanelCoorOverlayViewModel>(s => new PanelCoorOverlayViewModel(s.GetRequiredService<MainOrchestrator>()));
services.AddTransient<MessageWindowViewModel>(s => new MessageWindowViewModel(s.GetRequiredService<MainOrchestrator>()));
services.AddTransient<HudBarViewModel>(s => new HudBarViewModel(s.GetRequiredService<MainOrchestrator>()));
}).Build();
await AppHost!.StartAsync();
// Startup window (must come after DPI setup above)
MainWindow = AppHost.Services.GetRequiredService<AppWindow>();
MainWindow.Show();
base.OnStartup(e);
// Setup orchestration UI handler
var orchestrationUIHelper = App.AppHost.Services.GetRequiredService<OrchestratorUIHelper>();
// Setup message window dialog
var messageWindow = new MessageWindow();
messageWindow.Show();
}
private void Initialize()
{
const string appName = "MSFS PopOut Panel Manager";
bool createdNew;
var mutex = new Mutex(true, appName, out createdNew);
if (!createdNew)
{ {
//app is already running! Exiting the application //app is already running! Exiting the application
Application.Current.Shutdown(); Application.Current.Shutdown();
@ -88,9 +40,55 @@ namespace MSFSPopoutPanelManager.MainApp
Dispatcher.UnhandledException += HandleDispatcherException; Dispatcher.UnhandledException += HandleDispatcherException;
TaskScheduler.UnobservedTaskException += HandleTaskSchedulerUnobservedTaskException; TaskScheduler.UnobservedTaskException += HandleTaskSchedulerUnobservedTaskException;
AppDomain.CurrentDomain.UnhandledException += HandledDomainException; AppDomain.CurrentDomain.UnhandledException += HandledDomainException;
// Setup dependency injections
AppHost = Host.CreateDefaultBuilder()
.ConfigureServices((hostContext, services) =>
{
services.AddSingleton<AppWindow>();
services.AddSingleton<MainOrchestrator>();
services.AddSingleton<OrchestratorUIHelper>(s => new OrchestratorUIHelper(s.GetRequiredService<MainOrchestrator>()));
services.AddSingleton<ApplicationViewModel>(s => new ApplicationViewModel(s.GetRequiredService<MainOrchestrator>()));
services.AddSingleton<HelpViewModel>(s => new HelpViewModel(s.GetRequiredService<MainOrchestrator>()));
services.AddSingleton<ProfileCardListViewModel>(s => new ProfileCardListViewModel(s.GetRequiredService<MainOrchestrator>()));
services.AddSingleton<ProfileCardViewModel>(s => new ProfileCardViewModel(s.GetRequiredService<MainOrchestrator>()));
services.AddSingleton<TrayIconViewModel>(s => new TrayIconViewModel(s.GetRequiredService<MainOrchestrator>()));
services.AddTransient<AddProfileViewModel>(s => new AddProfileViewModel(s.GetRequiredService<MainOrchestrator>()));
services.AddTransient<PopOutPanelListViewModel>(s => new PopOutPanelListViewModel(s.GetRequiredService<MainOrchestrator>()));
services.AddTransient<PopOutPanelCardViewModel>(s => new PopOutPanelCardViewModel(s.GetRequiredService<MainOrchestrator>()));
services.AddTransient<PanelConfigFieldViewModel>(s => new PanelConfigFieldViewModel(s.GetRequiredService<MainOrchestrator>()));
services.AddTransient<PanelCoorOverlayViewModel>(s => new PanelCoorOverlayViewModel(s.GetRequiredService<MainOrchestrator>()));
services.AddTransient<MessageWindowViewModel>(s => new MessageWindowViewModel(s.GetRequiredService<MainOrchestrator>()));
services.AddTransient<HudBarViewModel>(s => new HudBarViewModel(s.GetRequiredService<MainOrchestrator>()));
}).Build();
await AppHost!.StartAsync();
// Startup window (must come after DPI setup above)
MainWindow = AppHost.Services.GetRequiredService<AppWindow>();
MainWindow.Show();
// Setup orchestration UI handler
var orchestrationUIHelper = App.AppHost.Services.GetRequiredService<OrchestratorUIHelper>();
// Setup message window dialog
var messageWindow = new MessageWindow();
messageWindow.Show();
base.OnStartup(e);
} }
} }
private bool IsRunning()
{
return Process.GetProcesses().Count(p => p.ProcessName.Contains(Assembly.GetEntryAssembly().GetName().Name)) > 1;
}
private void HandleTaskSchedulerUnobservedTaskException(object? sender, UnobservedTaskExceptionEventArgs e) private void HandleTaskSchedulerUnobservedTaskException(object? sender, UnobservedTaskExceptionEventArgs e)
{ {
FileLogger.WriteException(e.Exception.Message, e.Exception); FileLogger.WriteException(e.Exception.Message, e.Exception);

View file

@ -186,6 +186,7 @@ namespace MSFSPopoutPanelManager.Orchestration
// Remember current game's zoom level to be recall after pop out // Remember current game's zoom level to be recall after pop out
_prePopOutCockpitZoomLevel = _flightSimData.CockpitCameraZoom; _prePopOutCockpitZoomLevel = _flightSimData.CockpitCameraZoom;
InputEmulationManager.LoadCustomView(AppSetting.PopOutSetting.AutoPanning.KeyBinding); InputEmulationManager.LoadCustomView(AppSetting.PopOutSetting.AutoPanning.KeyBinding);
Thread.Sleep(1000);
FlightSimOrchestrator.SetCockpitCameraZoomLevel(50); FlightSimOrchestrator.SetCockpitCameraZoomLevel(50);
StatusMessageWriter.WriteOkStatusMessage(); StatusMessageWriter.WriteOkStatusMessage();
} }
@ -482,12 +483,13 @@ namespace MSFSPopoutPanelManager.Orchestration
switch (AppSetting.PopOutSetting.AfterPopOutCameraView.CameraView) switch (AppSetting.PopOutSetting.AfterPopOutCameraView.CameraView)
{ {
case AfterPopOutCameraViewType.CockpitCenterView: case AfterPopOutCameraViewType.CockpitCenterView:
FlightSimOrchestrator.SetCockpitCameraZoomLevel(_prePopOutCockpitZoomLevel);
InputEmulationManager.CenterView(); InputEmulationManager.CenterView();
Thread.Sleep(500);
FlightSimOrchestrator.SetCockpitCameraZoomLevel(_prePopOutCockpitZoomLevel);
break; break;
case AfterPopOutCameraViewType.CustomCameraView: case AfterPopOutCameraViewType.CustomCameraView:
FlightSimOrchestrator.SetCockpitCameraZoomLevel(_prePopOutCockpitZoomLevel);
InputEmulationManager.LoadCustomView(AppSetting.PopOutSetting.AfterPopOutCameraView.KeyBinding); InputEmulationManager.LoadCustomView(AppSetting.PopOutSetting.AfterPopOutCameraView.KeyBinding);
FlightSimOrchestrator.SetCockpitCameraZoomLevel(_prePopOutCockpitZoomLevel);
break; break;
} }
} }

View file

@ -100,20 +100,22 @@ namespace MSFSPopoutPanelManager.Orchestration
// Recenter game or return to after pop out camera view // Recenter game or return to after pop out camera view
if (!AppSetting.PopOutSetting.AfterPopOutCameraView.IsEnabled) if (!AppSetting.PopOutSetting.AfterPopOutCameraView.IsEnabled)
{ {
FlightSimOrchestrator.SetCockpitCameraZoomLevel(_prePanelConfigurationCockpitZoomLevel);
InputEmulationManager.CenterView(); InputEmulationManager.CenterView();
Thread.Sleep(500);
FlightSimOrchestrator.SetCockpitCameraZoomLevel(_prePanelConfigurationCockpitZoomLevel);
} }
else else
{ {
switch (AppSetting.PopOutSetting.AfterPopOutCameraView.CameraView) switch (AppSetting.PopOutSetting.AfterPopOutCameraView.CameraView)
{ {
case AfterPopOutCameraViewType.CockpitCenterView: case AfterPopOutCameraViewType.CockpitCenterView:
FlightSimOrchestrator.SetCockpitCameraZoomLevel(_prePanelConfigurationCockpitZoomLevel);
InputEmulationManager.CenterView(); InputEmulationManager.CenterView();
Thread.Sleep(500);
FlightSimOrchestrator.SetCockpitCameraZoomLevel(_prePanelConfigurationCockpitZoomLevel);
break; break;
case AfterPopOutCameraViewType.CustomCameraView: case AfterPopOutCameraViewType.CustomCameraView:
FlightSimOrchestrator.SetCockpitCameraZoomLevel(_prePanelConfigurationCockpitZoomLevel);
InputEmulationManager.LoadCustomView(AppSetting.PopOutSetting.AfterPopOutCameraView.KeyBinding); InputEmulationManager.LoadCustomView(AppSetting.PopOutSetting.AfterPopOutCameraView.KeyBinding);
FlightSimOrchestrator.SetCockpitCameraZoomLevel(_prePanelConfigurationCockpitZoomLevel);
break; break;
} }
} }

View file

@ -141,6 +141,9 @@ namespace MSFSPopoutPanelManager.WindowsAgent
PInvoke.keybd_event(Convert.ToByte(customViewKey), 0, KEYEVENTF_KEYUP, 0); PInvoke.keybd_event(Convert.ToByte(customViewKey), 0, KEYEVENTF_KEYUP, 0);
PInvoke.keybd_event(Convert.ToByte(VK_LMENU), 0, KEYEVENTF_KEYUP, 0); PInvoke.keybd_event(Convert.ToByte(VK_LMENU), 0, KEYEVENTF_KEYUP, 0);
Thread.Sleep(200); Thread.Sleep(200);
// Small delay to let load custom view finish
Thread.Sleep(500);
} }
public static void ToggleFullScreenPanel(IntPtr hwnd) public static void ToggleFullScreenPanel(IntPtr hwnd)