1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2026-02-04 02:43:32 +00:00
Artemis/src/Artemis.UI/Screens/Device/DeviceDetectInputViewModel.cs
Robert 55dca6cebb Upgrade packages
Update namespaces
Clean up unused imports
Replace Avalonia.ReactiveUI with ReactiveUI.Avalonia 🙄
2025-12-16 22:28:16 +01:00

67 lines
2.2 KiB
C#

using System;
using System.Linq;
using System.Reactive.Disposables;
using System.Reactive.Disposables.Fluent;
using System.Reactive.Linq;
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Services;
using Artemis.UI.Shared.Services.Builders;
using Avalonia.Threading;
using FluentAvalonia.UI.Controls;
using ReactiveUI;
using RGB.NET.Core;
namespace Artemis.UI.Screens.Device;
public class DeviceDetectInputViewModel : ContentDialogViewModelBase
{
private readonly IInputService _inputService;
private readonly INotificationService _notificationService;
public DeviceDetectInputViewModel(ArtemisDevice device, IInputService inputService, INotificationService notificationService, IRenderService renderService)
{
_inputService = inputService;
_notificationService = notificationService;
Device = device;
// Create a LED group way at the top
ListLedGroup ledGroup = new(renderService.Surface, Device.Leds.Select(l => l.RgbLed))
{
Brush = new SolidColorBrush(new Color(255, 255, 0)),
ZIndex = 999
};
this.WhenActivated(disposables =>
{
_inputService.IdentifyDevice(device);
Observable.FromEventPattern(x => _inputService.DeviceIdentified += x, x => _inputService.DeviceIdentified -= x)
.Subscribe(_ => InputServiceOnDeviceIdentified())
.DisposeWith(disposables);
Disposable.Create(() =>
{
_inputService.StopIdentify();
ledGroup.Detach();
}).DisposeWith(disposables);
});
}
public ArtemisDevice Device { get; }
public bool IsMouse => Device.RgbDevice.DeviceInfo.DeviceType == RGBDeviceType.Mouse;
public bool MadeChanges { get; set; }
private void InputServiceOnDeviceIdentified()
{
Dispatcher.UIThread.Post(() =>
{
ContentDialog?.Hide(ContentDialogResult.Primary);
_notificationService.CreateNotification()
.WithMessage($"{Device.RgbDevice.DeviceInfo.DeviceName} identified 😁")
.WithSeverity(NotificationSeverity.Success)
.Show();
});
}
}