1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-10-16 14:10:45 +00:00
msfs-popout-panel-manager/MainApp/ViewModel/TrayIconViewModel.cs
2024-02-27 21:44:21 -05:00

61 lines
2.5 KiB
C#

using MSFSPopoutPanelManager.Orchestration;
using Prism.Commands;
using System;
using System.Windows;
using System.Windows.Input;
namespace MSFSPopoutPanelManager.MainApp.ViewModel
{
public class TrayIconViewModel : BaseViewModel
{
private readonly AppOrchestrator _appOrchestrator;
private readonly PanelPopOutOrchestrator _panelPopOutOrchestrator;
public DelegateCommand<object> ChangeProfileCommand { get; }
public ICommand StartPopOutCommand { get; }
public ICommand ExitAppCommand { get; }
public TrayIconViewModel(SharedStorage sharedStorage, AppOrchestrator appOrchestrator, PanelPopOutOrchestrator panelPopOutOrchestrator) : base(sharedStorage)
{
_appOrchestrator = appOrchestrator;
_panelPopOutOrchestrator = panelPopOutOrchestrator;
StartPopOutCommand = new DelegateCommand(OnStartPopOut, () => ProfileData != null && ActiveProfile != null && ActiveProfile.PanelConfigs.Count > 0 && !ActiveProfile.HasUnidentifiedPanelSource && !ActiveProfile.IsEditingPanelSource && FlightSimData.IsInCockpit)
.ObservesProperty(() => ActiveProfile)
.ObservesProperty(() => ActiveProfile.PanelConfigs.Count)
.ObservesProperty(() => ActiveProfile.HasUnidentifiedPanelSource)
.ObservesProperty(() => ActiveProfile.IsEditingPanelSource)
.ObservesProperty(() => FlightSimData.IsInCockpit);
ChangeProfileCommand = new DelegateCommand<object>(OnChangeProfile);
ExitAppCommand = new DelegateCommand(OnExitApp);
}
private void OnChangeProfile(object param)
{
var profileId = Convert.ToString(param);
if (string.IsNullOrEmpty(profileId))
return;
ProfileData.ResetActiveProfile();
ProfileData.SetActiveProfile(new Guid(profileId));
}
private async void OnStartPopOut()
{
await _panelPopOutOrchestrator.ManualPopOut();
}
private void OnExitApp()
{
_appOrchestrator.ApplicationClose();
if (Application.Current != null)
Environment.Exit(0);
}
}
}