1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-23 22:30:09 +00:00
msfs-popout-panel-manager/Orchestration/AppOrchestrator.cs

78 lines
3.4 KiB
C#
Raw Normal View History

2024-02-28 02:44:21 +00:00
using AutoUpdaterDotNET;
using MSFSPopoutPanelManager.Shared;
using MSFSPopoutPanelManager.WindowsAgent;
using System;
using System.IO;
using System.Threading.Tasks;
namespace MSFSPopoutPanelManager.Orchestration
{
public class AppOrchestrator : BaseOrchestrator
{
private readonly PanelConfigurationOrchestrator _panelConfigurationOrchestrator;
private readonly FlightSimOrchestrator _flightSimOrchestrator;
private readonly KeyboardOrchestrator _keyboardOrchestrator;
public AppOrchestrator(SharedStorage sharedStorage, PanelConfigurationOrchestrator panelConfigurationOrchestrator, FlightSimOrchestrator flightSimOrchestrator, HelpOrchestrator helpOrchestrator, KeyboardOrchestrator keyboardOrchestrator) : base(sharedStorage)
{
_panelConfigurationOrchestrator = panelConfigurationOrchestrator;
_flightSimOrchestrator = flightSimOrchestrator;
_keyboardOrchestrator = keyboardOrchestrator;
ProfileData.FlightSimDataRef = FlightSimData;
ProfileData.AppSettingDataRef = AppSettingData;
FlightSimData.ProfileDataRef = ProfileData;
_flightSimOrchestrator.OnSimulatorExited += (_, _) => { ApplicationClose(); Environment.Exit(0); };
// Delete all existing cache version of app
helpOrchestrator.DeleteAppCache();
}
public ProfileOrchestrator Profile { get; set; }
public void Initialize()
{
// Add default dynamic LOD configs
if (!AppSettingData.ApplicationSetting.DynamicLodSetting.IsEnabled &&
AppSettingData.ApplicationSetting.DynamicLodSetting.TlodConfigs.Count == 0 &&
AppSettingData.ApplicationSetting.DynamicLodSetting.OlodConfigs.Count == 0)
{
AppSettingData.ApplicationSetting.DynamicLodSetting.AddDefaultTLodConfigs();
AppSettingData.ApplicationSetting.DynamicLodSetting.AddDefaultOLodConfigs();
}
if (AppSettingData.ApplicationSetting.GeneralSetting.CheckForUpdate)
CheckForAutoUpdate();
ProfileData.SetActiveProfile(AppSettingData.ApplicationSetting.SystemSetting.LastUsedProfileId); // Load last used profile
2024-03-01 11:28:09 +00:00
Task.Run(() => _flightSimOrchestrator.StartSimConnectServer()); // Start the SimConnect server
2024-02-28 02:44:21 +00:00
_keyboardOrchestrator.Initialize();
}
public void ApplicationClose()
{
// Force unhook all win events
_panelConfigurationOrchestrator.EndConfiguration();
_panelConfigurationOrchestrator.EndTouchHook();
2024-03-03 05:02:21 +00:00
InputHookManager.EndKeyboardHook();
_keyboardOrchestrator.EndGlobalKeyboardHookForced();
2024-02-28 02:44:21 +00:00
_flightSimOrchestrator.EndSimConnectServer(true);
}
private void CheckForAutoUpdate()
{
var jsonPath = Path.Combine(Path.Combine(FileIo.GetUserDataFilePath(), "autoupdate.json"));
AutoUpdater.PersistenceProvider = new JsonFilePersistenceProvider(jsonPath);
AutoUpdater.Synchronous = true;
AutoUpdater.AppTitle = "MSFS Pop Out Panel Manager";
AutoUpdater.RunUpdateAsAdmin = false;
AutoUpdater.UpdateFormSize = new System.Drawing.Size(1024, 660);
AutoUpdater.Start(AppSettingData.ApplicationSetting.SystemSetting.AutoUpdaterUrl);
}
}
}