1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-12-01 18:20:10 +00:00
msfs-popout-panel-manager/MainApp/ViewModel/ApplicationViewModel.cs

65 lines
2.3 KiB
C#
Raw Normal View History

2023-07-12 22:41:31 +00:00
using MSFSPopoutPanelManager.DomainModel.Profile;
using MSFSPopoutPanelManager.Orchestration;
using MSFSPopoutPanelManager.Shared;
using MSFSPopoutPanelManager.WindowsAgent;
using PropertyChanged;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Documents;
namespace MSFSPopoutPanelManager.MainApp.ViewModel
{
[SuppressPropertyChangedWarnings]
public class ApplicationViewModel : BaseViewModel
{
public IntPtr ApplicationHandle
{
get => Orchestrator.ApplicationHandle;
set => Orchestrator.ApplicationHandle = value;
}
public Window ApplicationWindow { set => Orchestrator.ApplicationWindow = value; }
public WindowState InitialWindowState { get; private set; }
public event EventHandler<(List<Run>, int)> OnStatusMessageUpdated;
public ApplicationViewModel(MainOrchestrator orchestrator) : base(orchestrator)
{
StatusMessageWriter.OnStatusMessage += (sender, e) =>
{
Application.Current.Dispatcher.Invoke(() =>
{
OnStatusMessageUpdated?.Invoke(this, (FormatStatusMessages(e.Messages), e.Duration));
});
};
}
public void Initialize()
{
// Set title bar color
WindowActionManager.SetWindowTitleBarColor(ApplicationHandle, "303030");
Orchestrator.Initialize();
Orchestrator.AppSettingData.AlwaysOnTopChanged += (sender, e) => WindowActionManager.ApplyAlwaysOnTop(ApplicationHandle, PanelType.PopOutManager, e);
// Set window state
if (Orchestrator.AppSettingData.ApplicationSetting.GeneralSetting.StartMinimized)
InitialWindowState = WindowState.Minimized;
// Set Always on Top
if (Orchestrator.AppSettingData.ApplicationSetting.GeneralSetting.AlwaysOnTop)
WindowActionManager.ApplyAlwaysOnTop(ApplicationHandle, PanelType.PopOutManager, Orchestrator.AppSettingData.ApplicationSetting.GeneralSetting.AlwaysOnTop);
}
public void WindowClosing()
{
Orchestrator.ApplicationClose();
if (Application.Current != null)
Environment.Exit(0);
}
}
}