1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00
Artemis/src/Artemis.UI/Screens/Workshop/Profile/ProfilePreviewViewModel.cs
Robert 4737173c2a Revert "Revert "Merge branch 'development'""
This reverts commit ebf40992bcdd75d6024d4bce25410511cbf88287.
2023-10-17 19:54:19 +02:00

55 lines
1.7 KiB
C#

using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive.Disposables;
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Services;
using ReactiveUI;
namespace Artemis.UI.Screens.Workshop.Profile;
public class ProfilePreviewViewModel : ActivatableViewModelBase
{
private readonly IProfileService _profileService;
private readonly IWindowService _windowService;
private ProfileConfiguration? _profileConfiguration;
public ProfilePreviewViewModel(IProfileService profileService, IDeviceService deviceService, IWindowService windowService)
{
_profileService = profileService;
_windowService = windowService;
Devices = new ObservableCollection<ArtemisDevice>(deviceService.EnabledDevices.OrderBy(d => d.ZIndex));
this.WhenAnyValue(vm => vm.ProfileConfiguration).Subscribe(_ => Update());
this.WhenActivated(d => Disposable.Create(() => PreviewProfile(null)).DisposeWith(d));
}
public ObservableCollection<ArtemisDevice> Devices { get; }
public ProfileConfiguration? ProfileConfiguration
{
get => _profileConfiguration;
set => RaiseAndSetIfChanged(ref _profileConfiguration, value);
}
private void Update()
{
try
{
PreviewProfile(ProfileConfiguration);
}
catch (Exception e)
{
_windowService.ShowExceptionDialog("Failed to load preview", e);
}
}
private void PreviewProfile(ProfileConfiguration? profileConfiguration)
{
_profileService.FocusProfile = profileConfiguration;
_profileService.UpdateFocusProfile = profileConfiguration != null;
}
}