1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-28 08:40:09 +00:00
msfs-popout-panel-manager/MainApp/ViewModel/TrayIconViewModel.cs

62 lines
2.5 KiB
C#
Raw Normal View History

2023-07-12 22:41:31 +00:00
using MSFSPopoutPanelManager.Orchestration;
using Prism.Commands;
using System;
using System.Windows;
using System.Windows.Input;
namespace MSFSPopoutPanelManager.MainApp.ViewModel
{
public class TrayIconViewModel : BaseViewModel
{
2024-02-28 02:44:21 +00:00
private readonly AppOrchestrator _appOrchestrator;
private readonly PanelPopOutOrchestrator _panelPopOutOrchestrator;
2023-07-12 22:41:31 +00:00
public DelegateCommand<object> ChangeProfileCommand { get; }
public ICommand StartPopOutCommand { get; }
public ICommand ExitAppCommand { get; }
2024-02-28 02:44:21 +00:00
public TrayIconViewModel(SharedStorage sharedStorage, AppOrchestrator appOrchestrator, PanelPopOutOrchestrator panelPopOutOrchestrator) : base(sharedStorage)
2023-07-12 22:41:31 +00:00
{
2024-02-28 02:44:21 +00:00
_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)
2023-07-12 22:41:31 +00:00
.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));
}
2024-02-28 02:44:21 +00:00
private async void OnStartPopOut()
2023-07-12 22:41:31 +00:00
{
2024-02-28 02:44:21 +00:00
await _panelPopOutOrchestrator.ManualPopOut();
2023-07-12 22:41:31 +00:00
}
private void OnExitApp()
{
2024-02-28 02:44:21 +00:00
_appOrchestrator.ApplicationClose();
2023-07-12 22:41:31 +00:00
if (Application.Current != null)
Environment.Exit(0);
}
}
}