JD2022-TU1/main/tools/modules/Orbit.Module/ViewModel/ConnectionWatcherViewModel.cs

43 lines
No EOL
1.4 KiB
C#

using System;
using System.Threading.Tasks;
using JD.Adobe.Service.API;
using JD.Adobe.Service.TargetMemories;
using Plume.WPF.Mvvm;
namespace Orbit.Module.ViewModel
{
public class ConnectionWatcherViewModel : BindableBase
{
private readonly IPhotoshopService _photoshopService;
private readonly ITargetMemory _targetMemory;
private bool _isPhotoshopRunning;
public bool IsPhotoshopRunning
{
get => _isPhotoshopRunning;
set => SetProperty(ref _isPhotoshopRunning, value);
}
public bool IsShuttleConnected => _targetMemory.HasTarget;
public ConnectionWatcherViewModel(ITargetMemory targetMemory, IPhotoshopService photoshopService)
{
_targetMemory = targetMemory ?? throw new ArgumentNullException(nameof(targetMemory));
_photoshopService = photoshopService ?? throw new ArgumentNullException(nameof(photoshopService));
StartWatchingPhotoshop();
}
private void StartWatchingPhotoshop()
{
Task.Run(async () =>
{
while (true)
{
IsPhotoshopRunning = _photoshopService.IsPhotoshopRunning;
OnPropertyChanged(nameof(IsShuttleConnected));
await Task.Delay(TimeSpan.FromSeconds(1));
}
});
}
}
}