mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Profiles - Only set imports as changed if they actually had real changes
Default layouts - Added default keyboard and headset layouts
This commit is contained in:
1 parent
9168ac2823
commit
f1eefe0761
145 files changed
+5874
-92
No files matched your search
@@ -76,8 +76,8 @@ namespace Artemis.Core.Services
|
||||
|
||||
public void IdentifyDevice(ArtemisDevice device)
|
||||
{
|
||||
if (device.RgbDevice.DeviceInfo.DeviceType != RGBDeviceType.Keyboard && device.RgbDevice.DeviceInfo.DeviceType != RGBDeviceType.Mouse)
|
||||
throw new ArtemisCoreException($"Cannot initialize input-identification for a device of type {device.RgbDevice.DeviceInfo.DeviceType}. \r\n" +
|
||||
if (device.DeviceType != RGBDeviceType.Keyboard && device.DeviceType != RGBDeviceType.Mouse)
|
||||
throw new ArtemisCoreException($"Cannot initialize input-identification for a device of type {device.DeviceType}. \r\n" +
|
||||
"Only keyboard and mouse is supported.");
|
||||
|
||||
_identifyingDevice = device;
|
||||
@@ -121,7 +121,7 @@ namespace Artemis.Core.Services
|
||||
{
|
||||
if (_cachedFallbackKeyboard != null)
|
||||
return _cachedFallbackKeyboard;
|
||||
_cachedFallbackKeyboard = _rgbService.EnabledDevices.FirstOrDefault(d => d.RgbDevice.DeviceInfo.DeviceType == RGBDeviceType.Keyboard);
|
||||
_cachedFallbackKeyboard = _rgbService.EnabledDevices.FirstOrDefault(d => d.DeviceType == RGBDeviceType.Keyboard);
|
||||
return _cachedFallbackKeyboard;
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ namespace Artemis.Core.Services
|
||||
{
|
||||
if (_cachedFallbackMouse != null)
|
||||
return _cachedFallbackMouse;
|
||||
_cachedFallbackMouse = _rgbService.EnabledDevices.FirstOrDefault(d => d.RgbDevice.DeviceInfo.DeviceType == RGBDeviceType.Mouse);
|
||||
_cachedFallbackMouse = _rgbService.EnabledDevices.FirstOrDefault(d => d.DeviceType == RGBDeviceType.Mouse);
|
||||
return _cachedFallbackMouse;
|
||||
}
|
||||
|
||||
@@ -165,8 +165,8 @@ namespace Artemis.Core.Services
|
||||
{
|
||||
// Don't match if there is no device or if the device type differs from the event device type
|
||||
if (_identifyingDevice == null ||
|
||||
_identifyingDevice.RgbDevice.DeviceInfo.DeviceType == RGBDeviceType.Keyboard && e.DeviceType == InputDeviceType.Mouse ||
|
||||
_identifyingDevice.RgbDevice.DeviceInfo.DeviceType == RGBDeviceType.Mouse && e.DeviceType == InputDeviceType.Keyboard)
|
||||
_identifyingDevice.DeviceType == RGBDeviceType.Keyboard && e.DeviceType == InputDeviceType.Mouse ||
|
||||
_identifyingDevice.DeviceType == RGBDeviceType.Mouse && e.DeviceType == InputDeviceType.Keyboard)
|
||||
return;
|
||||
if (!(sender is InputProvider inputProvider))
|
||||
return;
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace Artemis.Core.Services
|
||||
/// </summary>
|
||||
/// <param name="device">The device to apply the best available layout to</param>
|
||||
/// <returns>The layout that was applied to the device</returns>
|
||||
ArtemisLayout ApplyBestDeviceLayout(ArtemisDevice device);
|
||||
ArtemisLayout? ApplyBestDeviceLayout(ArtemisDevice device);
|
||||
|
||||
/// <summary>
|
||||
/// Apples the provided <see cref="ArtemisLayout" /> to the provided <see cref="ArtemisDevice" />
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Artemis.Core.DeviceProviders;
|
||||
using Artemis.Core.Services.Models;
|
||||
@@ -149,6 +150,7 @@ namespace Artemis.Core.Services
|
||||
RemoveDevice(device);
|
||||
|
||||
List<Exception> providerExceptions = new();
|
||||
|
||||
void DeviceProviderOnException(object? sender, ExceptionEventArgs e)
|
||||
{
|
||||
if (e.IsCritical)
|
||||
@@ -314,15 +316,15 @@ namespace Artemis.Core.Services
|
||||
{
|
||||
SurfaceArrangement surfaceArrangement = SurfaceArrangement.GetDefaultArrangement();
|
||||
surfaceArrangement.Arrange(_devices);
|
||||
foreach (ArtemisDevice artemisDevice in _devices)
|
||||
foreach (ArtemisDevice artemisDevice in _devices)
|
||||
artemisDevice.ApplyDefaultCategories();
|
||||
|
||||
SaveDevices();
|
||||
}
|
||||
|
||||
public ArtemisLayout ApplyBestDeviceLayout(ArtemisDevice device)
|
||||
public ArtemisLayout? ApplyBestDeviceLayout(ArtemisDevice device)
|
||||
{
|
||||
ArtemisLayout layout;
|
||||
ArtemisLayout? layout;
|
||||
|
||||
// Configured layout path takes precedence over all other options
|
||||
if (device.CustomLayoutPath != null)
|
||||
@@ -352,19 +354,19 @@ namespace Artemis.Core.Services
|
||||
}
|
||||
|
||||
// Finally fall back to a default layout
|
||||
layout = LoadDefaultLayout(device);
|
||||
ApplyDeviceLayout(device, layout);
|
||||
layout = ArtemisLayout.GetDefaultLayout(device);
|
||||
if (layout != null)
|
||||
ApplyDeviceLayout(device, layout);
|
||||
return layout;
|
||||
}
|
||||
|
||||
private ArtemisLayout LoadDefaultLayout(ArtemisDevice device)
|
||||
{
|
||||
return new("NYI", LayoutSource.Default);
|
||||
}
|
||||
|
||||
public void ApplyDeviceLayout(ArtemisDevice device, ArtemisLayout layout)
|
||||
{
|
||||
device.ApplyLayout(layout, device.DeviceProvider.CreateMissingLedsSupported, device.DeviceProvider.RemoveExcessiveLedsSupported);
|
||||
if (layout.Source == LayoutSource.Default)
|
||||
device.ApplyLayout(layout, false, false);
|
||||
else
|
||||
device.ApplyLayout(layout, device.DeviceProvider.CreateMissingLedsSupported, device.DeviceProvider.RemoveExcessiveLedsSupported);
|
||||
|
||||
UpdateLedGroup();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,12 +23,12 @@ namespace Artemis.Core.Services.Models
|
||||
|
||||
public bool HasDevices(List<ArtemisDevice> devices)
|
||||
{
|
||||
return devices.Any(d => d.RgbDevice.DeviceInfo.DeviceType == DeviceType);
|
||||
return devices.Any(d => d.DeviceType == DeviceType);
|
||||
}
|
||||
|
||||
public void Arrange(List<ArtemisDevice> devices)
|
||||
{
|
||||
devices = devices.Where(d => d.RgbDevice.DeviceInfo.DeviceType == DeviceType).ToList();
|
||||
devices = devices.Where(d => d.DeviceType == DeviceType).ToList();
|
||||
if (!devices.Any())
|
||||
return;
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace Artemis.Core.Services.Models
|
||||
|
||||
public Point GetEdge(HorizontalArrangementPosition horizontalPosition, VerticalArrangementPosition verticalPosition)
|
||||
{
|
||||
List<ArtemisDevice> devices = SurfaceArrangement.ArrangedDevices.Where(d => d.RgbDevice.DeviceInfo.DeviceType == DeviceType || DeviceType == RGBDeviceType.All).ToList();
|
||||
List<ArtemisDevice> devices = SurfaceArrangement.ArrangedDevices.Where(d => d.DeviceType == DeviceType || DeviceType == RGBDeviceType.All).ToList();
|
||||
if (!devices.Any())
|
||||
return new Point();
|
||||
|
||||
|
||||
@@ -152,7 +152,7 @@ namespace Artemis.Core.Services
|
||||
|
||||
Profile profile = new(profileDescriptor.ProfileModule, profileEntity);
|
||||
InstantiateProfile(profile);
|
||||
|
||||
|
||||
void ActivatingRgbServiceOnLedsChanged(object? sender, EventArgs e)
|
||||
{
|
||||
profile.PopulateLeds(_rgbService.EnabledDevices);
|
||||
@@ -220,12 +220,8 @@ namespace Artemis.Core.Services
|
||||
|
||||
public void UpdateProfile(Profile profile, bool includeChildren)
|
||||
{
|
||||
_logger.Debug("Updating profile " + profile);
|
||||
string memento = JsonConvert.SerializeObject(profile.ProfileEntity, MementoSettings);
|
||||
profile.RedoStack.Clear();
|
||||
profile.UndoStack.Push(memento);
|
||||
|
||||
profile.IsFreshImport = false;
|
||||
profile.Save();
|
||||
if (includeChildren)
|
||||
{
|
||||
@@ -235,6 +231,22 @@ namespace Artemis.Core.Services
|
||||
layer.Save();
|
||||
}
|
||||
|
||||
// If there are no changes, don't bother saving
|
||||
string updatedMemento = JsonConvert.SerializeObject(profile.ProfileEntity, MementoSettings);
|
||||
if (memento.Equals(updatedMemento))
|
||||
{
|
||||
_logger.Debug("Updating profile - Skipping save, no changes");
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.Debug("Updating profile - Saving " + profile);
|
||||
profile.RedoStack.Clear();
|
||||
profile.UndoStack.Push(memento);
|
||||
|
||||
// At this point the user made actual changes, save that
|
||||
profile.IsFreshImport = false;
|
||||
profile.ProfileEntity.IsFreshImport = false;
|
||||
|
||||
_profileRepository.Save(profile.ProfileEntity);
|
||||
}
|
||||
|
||||
@@ -321,9 +333,24 @@ namespace Artemis.Core.Services
|
||||
/// <inheritdoc />
|
||||
public void AdaptProfile(Profile profile)
|
||||
{
|
||||
string memento = JsonConvert.SerializeObject(profile.ProfileEntity, MementoSettings);
|
||||
|
||||
List<ArtemisDevice> devices = _rgbService.EnabledDevices.ToList();
|
||||
foreach (Layer layer in profile.GetAllLayers())
|
||||
layer.Adapter.Adapt(devices);
|
||||
|
||||
profile.Save();
|
||||
|
||||
foreach (Folder folder in profile.GetAllFolders())
|
||||
folder.Save();
|
||||
foreach (Layer layer in profile.GetAllLayers())
|
||||
layer.Save();
|
||||
|
||||
_logger.Debug("Adapt profile - Saving " + profile);
|
||||
profile.RedoStack.Clear();
|
||||
profile.UndoStack.Push(memento);
|
||||
|
||||
_profileRepository.Save(profile.ProfileEntity);
|
||||
}
|
||||
|
||||
#region Event handlers
|
||||
|
||||
Reference in new issue
Block a user