mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Added active surface-config management code
Added surface-config creation
This commit is contained in:
parent
1ae103accc
commit
10bc3f84dd
@ -142,6 +142,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Attributes\DataModelProperty.cs" />
|
||||
<Compile Include="Constants.cs" />
|
||||
<Compile Include="Events\DeviceConfigurationEventArgs.cs" />
|
||||
<Compile Include="Events\DeviceEventArgs.cs" />
|
||||
<Compile Include="Exceptions\ArtemisCoreException.cs" />
|
||||
<Compile Include="Extensions\DirectoryInfoExtensions.cs" />
|
||||
|
||||
18
src/Artemis.Core/Events/DeviceConfigurationEventArgs.cs
Normal file
18
src/Artemis.Core/Events/DeviceConfigurationEventArgs.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.Core.Events
|
||||
{
|
||||
public class SurfaceConfigurationEventArgs : EventArgs
|
||||
{
|
||||
public SurfaceConfigurationEventArgs(SurfaceConfiguration surfaceConfiguration, IRGBDevice device)
|
||||
{
|
||||
SurfaceConfiguration = surfaceConfiguration;
|
||||
Device = device;
|
||||
}
|
||||
|
||||
public SurfaceConfiguration SurfaceConfiguration { get; }
|
||||
public IRGBDevice Device { get; }
|
||||
}
|
||||
}
|
||||
@ -1,14 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Storage.Entities;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.Core.Models.Surface
|
||||
{
|
||||
public class SurfaceConfiguration
|
||||
{
|
||||
public SurfaceConfiguration(string name)
|
||||
internal SurfaceConfiguration()
|
||||
{
|
||||
Name = name;
|
||||
DeviceConfigurations = new List<SurfaceDeviceConfiguration>();
|
||||
}
|
||||
|
||||
internal SurfaceConfiguration(SurfaceEntity surfaceEntity)
|
||||
@ -26,7 +26,7 @@ namespace Artemis.Core.Models.Surface
|
||||
|
||||
internal string Guid { get; set; }
|
||||
public string Name { get; set; }
|
||||
public bool IsActive { get; set; }
|
||||
public List<SurfaceDeviceConfiguration> DeviceConfigurations { get; set; }
|
||||
public bool IsActive { get; internal set; }
|
||||
public List<SurfaceDeviceConfiguration> DeviceConfigurations { get; internal set; }
|
||||
}
|
||||
}
|
||||
@ -27,10 +27,11 @@ namespace Artemis.Core.Models.Surface
|
||||
X = position.X;
|
||||
Y = position.Y;
|
||||
Rotation = position.Rotation;
|
||||
ZIndex = position.ZIndex;
|
||||
|
||||
Surface = surfaceConfiguration;
|
||||
}
|
||||
|
||||
|
||||
internal string Guid { get; set; }
|
||||
|
||||
public int DeviceId { get; set; }
|
||||
@ -41,6 +42,7 @@ namespace Artemis.Core.Models.Surface
|
||||
public double X { get; set; }
|
||||
public double Y { get; set; }
|
||||
public double Rotation { get; set; }
|
||||
public int ZIndex { get; set; }
|
||||
|
||||
public SurfaceConfiguration Surface { get; internal set; }
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
|
||||
namespace Artemis.Core.Plugins.Abstract
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core.Exceptions;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Core.Services.Storage;
|
||||
using RGB.NET.Core;
|
||||
using Serilog;
|
||||
using Color = System.Drawing.Color;
|
||||
@ -17,12 +19,14 @@ namespace Artemis.Core.Services
|
||||
private readonly ILogger _logger;
|
||||
private readonly IPluginService _pluginService;
|
||||
private readonly IRgbService _rgbService;
|
||||
private readonly ISurfaceService _surfaceService;
|
||||
|
||||
internal CoreService(ILogger logger, IPluginService pluginService, IRgbService rgbService)
|
||||
internal CoreService(ILogger logger, IPluginService pluginService, IRgbService rgbService, ISurfaceService surfaceService)
|
||||
{
|
||||
_logger = logger;
|
||||
_pluginService = pluginService;
|
||||
_rgbService = rgbService;
|
||||
_surfaceService = surfaceService;
|
||||
_rgbService.Surface.Updating += SurfaceOnUpdating;
|
||||
|
||||
Task.Run(Initialize);
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.RGB.NET;
|
||||
using RGB.NET.Core;
|
||||
|
||||
@ -9,6 +11,8 @@ namespace Artemis.Core.Services.Interfaces
|
||||
{
|
||||
RGBSurface Surface { get; set; }
|
||||
GraphicsDecorator GraphicsDecorator { get; }
|
||||
IReadOnlyCollection<IRGBDevice> LoadedDevices { get; }
|
||||
|
||||
void AddDeviceProvider(IRGBDeviceProvider deviceProvider);
|
||||
void Dispose();
|
||||
|
||||
|
||||
@ -58,14 +58,15 @@ namespace Artemis.Core.Services
|
||||
// Find the matching plugin in the plugin folder
|
||||
var match = pluginDirectory.EnumerateDirectories().FirstOrDefault(d => d.Name == subDirectory.Name);
|
||||
if (match == null)
|
||||
{
|
||||
CopyBuiltInPlugin(subDirectory);
|
||||
}
|
||||
else
|
||||
{
|
||||
var metadataFile = Path.Combine(match.FullName, "plugin.json");
|
||||
if (!File.Exists(metadataFile))
|
||||
CopyBuiltInPlugin(subDirectory);
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
// Compare versions, copy if the same when debugging
|
||||
@ -82,7 +83,6 @@ namespace Artemis.Core.Services
|
||||
{
|
||||
throw new ArtemisPluginException("Failed read plugin metadata needed to install built-in plugin", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -142,7 +142,8 @@ namespace Artemis.Core.Services
|
||||
lock (_plugins)
|
||||
{
|
||||
// Unload all plugins
|
||||
while (_plugins.Count > 0) UnloadPlugin(_plugins[0]);
|
||||
while (_plugins.Count > 0)
|
||||
UnloadPlugin(_plugins[0]);
|
||||
|
||||
// Dispose the child kernel and therefore any leftover plugins instantiated with it
|
||||
if (_childKernel != null)
|
||||
|
||||
@ -1,12 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.RGB.NET;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Core.Services.Storage;
|
||||
using Artemis.Storage.Entities;
|
||||
using RGB.NET.Brushes;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Groups;
|
||||
@ -21,15 +18,12 @@ namespace Artemis.Core.Services
|
||||
{
|
||||
private readonly List<IRGBDevice> _loadedDevices;
|
||||
private readonly ILogger _logger;
|
||||
private readonly ISurfaceService _surfaceService;
|
||||
private readonly TimerUpdateTrigger _updateTrigger;
|
||||
|
||||
internal RgbService(ILogger logger, ISurfaceService surfaceService)
|
||||
internal RgbService(ILogger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_surfaceService = surfaceService;
|
||||
Surface = RGBSurface.Instance;
|
||||
LoadingDevices = false;
|
||||
|
||||
// Let's throw these for now
|
||||
Surface.Exception += SurfaceOnException;
|
||||
@ -39,14 +33,22 @@ namespace Artemis.Core.Services
|
||||
Surface.RegisterUpdateTrigger(_updateTrigger);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool LoadingDevices { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public RGBSurface Surface { get; set; }
|
||||
|
||||
public GraphicsDecorator GraphicsDecorator { get; private set; }
|
||||
|
||||
public IReadOnlyCollection<IRGBDevice> LoadedDevices
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_loadedDevices)
|
||||
{
|
||||
return _loadedDevices.AsReadOnly();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AddDeviceProvider(IRGBDeviceProvider deviceProvider)
|
||||
{
|
||||
Surface.LoadDevices(deviceProvider);
|
||||
@ -56,12 +58,7 @@ namespace Artemis.Core.Services
|
||||
_logger.Warning("Device provider {deviceProvider} has no devices", deviceProvider.GetType().Name);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the currently active surface configuration
|
||||
var surface = _surfaceService.GetActiveSurfaceConfiguration();
|
||||
if (surface == null)
|
||||
_logger.Information("No active surface configuration found, not positioning device");
|
||||
|
||||
|
||||
lock (_loadedDevices)
|
||||
{
|
||||
foreach (var surfaceDevice in deviceProvider.Devices)
|
||||
@ -69,14 +66,10 @@ namespace Artemis.Core.Services
|
||||
if (!_loadedDevices.Contains(surfaceDevice))
|
||||
{
|
||||
_loadedDevices.Add(surfaceDevice);
|
||||
if (surface != null)
|
||||
ApplyDeviceConfiguration(surfaceDevice, surface);
|
||||
OnDeviceLoaded(new DeviceEventArgs(surfaceDevice));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (surface != null)
|
||||
ApplyDeviceConfiguration(surfaceDevice, surface);
|
||||
OnDeviceReloaded(new DeviceEventArgs(surfaceDevice));
|
||||
}
|
||||
}
|
||||
@ -96,31 +89,6 @@ namespace Artemis.Core.Services
|
||||
Surface.Dispose();
|
||||
}
|
||||
|
||||
public void ApplyDeviceConfiguration(IRGBDevice rgbDevice, SurfaceConfiguration surface)
|
||||
{
|
||||
// Determine the device ID by assuming devices are always added to the loaded devices list in the same order
|
||||
lock (_loadedDevices)
|
||||
{
|
||||
var deviceId = _loadedDevices.Where(d => d.DeviceInfo.DeviceName == rgbDevice.DeviceInfo.DeviceName &&
|
||||
d.DeviceInfo.Model == rgbDevice.DeviceInfo.Model &&
|
||||
d.DeviceInfo.Manufacturer == rgbDevice.DeviceInfo.Manufacturer)
|
||||
.ToList()
|
||||
.IndexOf(rgbDevice) + 1;
|
||||
|
||||
var deviceConfig = surface.DeviceConfigurations.FirstOrDefault(d => d.DeviceName == rgbDevice.DeviceInfo.DeviceName &&
|
||||
d.DeviceModel == rgbDevice.DeviceInfo.Model &&
|
||||
d.DeviceManufacturer == rgbDevice.DeviceInfo.Manufacturer &&
|
||||
d.DeviceId == deviceId);
|
||||
if (deviceConfig == null)
|
||||
{
|
||||
_logger.Information("No surface device config found for {deviceInfo}, device ID: {deviceId}", rgbDevice.DeviceInfo, deviceId);
|
||||
return;
|
||||
}
|
||||
|
||||
rgbDevice.Location = new Point(deviceConfig.X, deviceConfig.Y);
|
||||
}
|
||||
}
|
||||
|
||||
private void SurfaceOnException(ExceptionEventArgs args)
|
||||
{
|
||||
throw args.Exception;
|
||||
|
||||
@ -1,22 +1,32 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Storage.Repositories.Interfaces;
|
||||
using RGB.NET.Core;
|
||||
using Serilog;
|
||||
|
||||
namespace Artemis.Core.Services.Storage
|
||||
{
|
||||
public class SurfaceService : ISurfaceService
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ISurfaceRepository _surfaceRepository;
|
||||
private readonly IRgbService _rgbService;
|
||||
|
||||
public SurfaceService(ISurfaceRepository surfaceRepository)
|
||||
public SurfaceService(ILogger logger, ISurfaceRepository surfaceRepository, IRgbService rgbService)
|
||||
{
|
||||
_logger = logger;
|
||||
_surfaceRepository = surfaceRepository;
|
||||
_rgbService = rgbService;
|
||||
|
||||
_rgbService.DeviceLoaded += RgbServiceOnDeviceLoaded;
|
||||
}
|
||||
|
||||
public async Task<List<SurfaceConfiguration>> GetSurfaceConfigurations()
|
||||
public async Task<List<SurfaceConfiguration>> GetSurfaceConfigurationsAsync()
|
||||
{
|
||||
var surfaceEntities = await _surfaceRepository.GetAllAsync();
|
||||
var configs = new List<SurfaceConfiguration>();
|
||||
@ -26,16 +36,127 @@ namespace Artemis.Core.Services.Storage
|
||||
return configs;
|
||||
}
|
||||
|
||||
public async Task<SurfaceConfiguration> GetActiveSurfaceConfigurationAsync()
|
||||
{
|
||||
var entity = (await _surfaceRepository.GetAllAsync()).FirstOrDefault(d => d.IsActive);
|
||||
return entity != null ? new SurfaceConfiguration(entity) : null;
|
||||
}
|
||||
|
||||
public async Task SetActiveSurfaceConfigurationAsync(SurfaceConfiguration surfaceConfiguration)
|
||||
{
|
||||
var surfaceEntities = await _surfaceRepository.GetAllAsync();
|
||||
foreach (var surfaceEntity in surfaceEntities)
|
||||
surfaceEntity.IsActive = surfaceEntity.Guid == surfaceConfiguration.Guid;
|
||||
|
||||
await _surfaceRepository.SaveAsync();
|
||||
}
|
||||
|
||||
public List<SurfaceConfiguration> GetSurfaceConfigurations()
|
||||
{
|
||||
var surfaceEntities = _surfaceRepository.GetAll();
|
||||
var configs = new List<SurfaceConfiguration>();
|
||||
foreach (var surfaceEntity in surfaceEntities)
|
||||
configs.Add(new SurfaceConfiguration(surfaceEntity));
|
||||
|
||||
return configs;
|
||||
}
|
||||
|
||||
public SurfaceConfiguration GetActiveSurfaceConfiguration()
|
||||
{
|
||||
var entity = _surfaceRepository.GetAll().FirstOrDefault(d => d.IsActive);
|
||||
return entity != null ? new SurfaceConfiguration(entity) : null;
|
||||
}
|
||||
|
||||
public void SetActiveSurfaceConfiguration(SurfaceConfiguration surfaceConfiguration)
|
||||
{
|
||||
var surfaceEntities = _surfaceRepository.GetAll();
|
||||
foreach (var surfaceEntity in surfaceEntities)
|
||||
surfaceEntity.IsActive = surfaceEntity.Guid == surfaceConfiguration.Guid;
|
||||
|
||||
_surfaceRepository.Save();
|
||||
}
|
||||
|
||||
public SurfaceConfiguration CreateSurfaceConfiguration(string name)
|
||||
{
|
||||
// Create a blank config
|
||||
var configuration = new SurfaceConfiguration {Name = name, DeviceConfigurations = new List<SurfaceDeviceConfiguration>()};
|
||||
|
||||
// Add all current devices
|
||||
foreach (var rgbDevice in _rgbService.LoadedDevices)
|
||||
{
|
||||
var deviceId = GetDeviceId(rgbDevice);
|
||||
configuration.DeviceConfigurations.Add(new SurfaceDeviceConfiguration(deviceId, rgbDevice.DeviceInfo, configuration));
|
||||
}
|
||||
|
||||
return configuration;
|
||||
}
|
||||
|
||||
private void ApplyDeviceConfiguration(IRGBDevice rgbDevice, SurfaceConfiguration surface)
|
||||
{
|
||||
var deviceId = GetDeviceId(rgbDevice);
|
||||
var deviceConfig = surface.DeviceConfigurations.FirstOrDefault(d => d.DeviceName == rgbDevice.DeviceInfo.DeviceName &&
|
||||
d.DeviceModel == rgbDevice.DeviceInfo.Model &&
|
||||
d.DeviceManufacturer == rgbDevice.DeviceInfo.Manufacturer &&
|
||||
d.DeviceId == deviceId);
|
||||
|
||||
if (deviceConfig == null)
|
||||
{
|
||||
_logger.Information("No active surface config found for {deviceInfo}, device ID: {deviceId}. Adding a new entry.", rgbDevice.DeviceInfo, deviceId);
|
||||
deviceConfig = new SurfaceDeviceConfiguration(deviceId, rgbDevice.DeviceInfo, surface);
|
||||
surface.DeviceConfigurations.Add(deviceConfig);
|
||||
}
|
||||
|
||||
rgbDevice.Location = new Point(deviceConfig.X, deviceConfig.Y);
|
||||
OnDeviceConfigurationApplied(new SurfaceConfigurationEventArgs(surface, rgbDevice));
|
||||
}
|
||||
|
||||
private int GetDeviceId(IRGBDevice rgbDevice)
|
||||
{
|
||||
return _rgbService.LoadedDevices
|
||||
.Where(d => d.DeviceInfo.DeviceName == rgbDevice.DeviceInfo.DeviceName &&
|
||||
d.DeviceInfo.Model == rgbDevice.DeviceInfo.Model &&
|
||||
d.DeviceInfo.Manufacturer == rgbDevice.DeviceInfo.Manufacturer)
|
||||
.ToList()
|
||||
.IndexOf(rgbDevice) + 1;
|
||||
}
|
||||
|
||||
private void RgbServiceOnDeviceLoaded(object sender, DeviceEventArgs e)
|
||||
{
|
||||
var activeConfiguration = GetActiveSurfaceConfiguration();
|
||||
if (activeConfiguration == null)
|
||||
{
|
||||
_logger.Information("No active surface config found, cannot apply settings to {deviceInfo}", e.Device.DeviceInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
ApplyDeviceConfiguration(e.Device, GetActiveSurfaceConfiguration());
|
||||
}
|
||||
|
||||
#region Events
|
||||
|
||||
public event EventHandler<SurfaceConfigurationEventArgs> SurfaceConfigurationApplied;
|
||||
|
||||
private void OnDeviceConfigurationApplied(SurfaceConfigurationEventArgs e)
|
||||
{
|
||||
SurfaceConfigurationApplied?.Invoke(this, e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public interface ISurfaceService : IArtemisService
|
||||
{
|
||||
Task<List<SurfaceConfiguration>> GetSurfaceConfigurations();
|
||||
Task<List<SurfaceConfiguration>> GetSurfaceConfigurationsAsync();
|
||||
Task<SurfaceConfiguration> GetActiveSurfaceConfigurationAsync();
|
||||
Task SetActiveSurfaceConfigurationAsync(SurfaceConfiguration surfaceConfiguration);
|
||||
List<SurfaceConfiguration> GetSurfaceConfigurations();
|
||||
SurfaceConfiguration GetActiveSurfaceConfiguration();
|
||||
SurfaceConfiguration CreateSurfaceConfiguration(string name);
|
||||
void SetActiveSurfaceConfiguration(SurfaceConfiguration surfaceConfiguration);
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when a device has a new surface configuration applied to it
|
||||
/// </summary>
|
||||
event EventHandler<SurfaceConfigurationEventArgs> SurfaceConfigurationApplied;
|
||||
}
|
||||
}
|
||||
@ -75,14 +75,14 @@
|
||||
<Reference Include="MahApps.Metro, Version=1.6.5.1, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MahApps.Metro.1.6.5\lib\net47\MahApps.Metro.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MaterialDesignColors, Version=1.1.3.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MaterialDesignColors.1.1.3\lib\net45\MaterialDesignColors.dll</HintPath>
|
||||
<Reference Include="MaterialDesignColors, Version=1.2.0.325, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MaterialDesignColors.1.2.0\lib\net45\MaterialDesignColors.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MaterialDesignThemes.MahApps, Version=0.0.10.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MaterialDesignThemes.MahApps.0.0.12\lib\net45\MaterialDesignThemes.MahApps.dll</HintPath>
|
||||
<Reference Include="MaterialDesignThemes.MahApps, Version=0.1.0.325, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MaterialDesignThemes.MahApps.0.1.0\lib\net45\MaterialDesignThemes.MahApps.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MaterialDesignThemes.Wpf, Version=2.5.1.1345, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MaterialDesignThemes.2.5.1\lib\net45\MaterialDesignThemes.Wpf.dll</HintPath>
|
||||
<Reference Include="MaterialDesignThemes.Wpf, Version=2.6.0.325, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MaterialDesignThemes.2.6.0\lib\net45\MaterialDesignThemes.Wpf.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Data.Sqlite, Version=2.2.4.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Data.Sqlite.Core.2.2.4\lib\netstandard2.0\Microsoft.Data.Sqlite.dll</HintPath>
|
||||
@ -119,8 +119,8 @@
|
||||
<Reference Include="SQLitePCLRaw.provider.e_sqlite3, Version=1.1.12.351, Culture=neutral, PublicKeyToken=9c301db686d0bd12, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SQLitePCLRaw.provider.e_sqlite3.net45.1.1.12\lib\net45\SQLitePCLRaw.provider.e_sqlite3.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Stylet, Version=1.2.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Stylet.1.2.0\lib\net45\Stylet.dll</HintPath>
|
||||
<Reference Include="Stylet, Version=1.3.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Stylet.1.3.0\lib\net45\Stylet.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
|
||||
@ -11,7 +11,7 @@ namespace Artemis.UI.ViewModels.Screens
|
||||
public SettingsViewModel(IRgbService rgbService)
|
||||
{
|
||||
DeviceSettingsViewModels = new BindableCollection<RgbDeviceSettingsViewModel>();
|
||||
foreach (var device in rgbService.Surface.Devices)
|
||||
foreach (var device in rgbService.LoadedDevices)
|
||||
DeviceSettingsViewModels.Add(new RgbDeviceSettingsViewModel(device));
|
||||
|
||||
rgbService.DeviceLoaded += UpdateDevices;
|
||||
|
||||
@ -32,7 +32,7 @@ namespace Artemis.UI.ViewModels.Screens
|
||||
_surfaceService = surfaceService;
|
||||
_rgbService.DeviceLoaded += RgbServiceOnDeviceLoaded;
|
||||
|
||||
foreach (var surfaceDevice in _rgbService.Surface.Devices)
|
||||
foreach (var surfaceDevice in _rgbService.LoadedDevices)
|
||||
{
|
||||
var device = new SurfaceDeviceViewModel(surfaceDevice) {Cursor = Cursors.Hand};
|
||||
Devices.Add(device);
|
||||
@ -62,15 +62,16 @@ namespace Artemis.UI.ViewModels.Screens
|
||||
|
||||
private async Task LoadSurfaceConfigurations()
|
||||
{
|
||||
Execute.OnUIThread(async () =>
|
||||
await Execute.OnUIThreadAsync(async () =>
|
||||
{
|
||||
SurfaceConfigurations.Clear();
|
||||
|
||||
// Get surface configs
|
||||
var configs = await _surfaceService.GetSurfaceConfigurations();
|
||||
var configs = await _surfaceService.GetSurfaceConfigurationsAsync();
|
||||
// Populate the UI collection
|
||||
foreach (var surfaceConfiguration in configs)
|
||||
SurfaceConfigurations.Add(surfaceConfiguration);
|
||||
|
||||
// Select either the first active surface or the first available surface
|
||||
SelectedSurfaceConfiguration = SurfaceConfigurations.FirstOrDefault(s => s.IsActive) ?? SurfaceConfigurations.FirstOrDefault();
|
||||
|
||||
@ -82,12 +83,12 @@ namespace Artemis.UI.ViewModels.Screens
|
||||
|
||||
public SurfaceConfiguration AddSurfaceConfiguration(string name)
|
||||
{
|
||||
var config = new SurfaceConfiguration(name);
|
||||
var config = _surfaceService.CreateSurfaceConfiguration(name);
|
||||
Execute.OnUIThread(() => SurfaceConfigurations.Add(config));
|
||||
return config;
|
||||
}
|
||||
|
||||
public void ConfigurationDialogClosing()
|
||||
public void ConfirmationDialogClosing()
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(NewConfigurationName))
|
||||
{
|
||||
@ -102,22 +103,56 @@ namespace Artemis.UI.ViewModels.Screens
|
||||
|
||||
public void BringToFront(SurfaceDeviceViewModel surfaceDeviceViewModel)
|
||||
{
|
||||
Console.WriteLine("Bring to front");
|
||||
var original = surfaceDeviceViewModel.ZIndex;
|
||||
surfaceDeviceViewModel.ZIndex = Devices.Count;
|
||||
foreach (var deviceViewModel in Devices)
|
||||
{
|
||||
if (deviceViewModel.ZIndex >= original && deviceViewModel != surfaceDeviceViewModel)
|
||||
deviceViewModel.ZIndex--;
|
||||
}
|
||||
|
||||
foreach (var deviceViewModel in Devices)
|
||||
Console.WriteLine(deviceViewModel.ZIndex);
|
||||
}
|
||||
|
||||
public void BringForward(SurfaceDeviceViewModel surfaceDeviceViewModel)
|
||||
{
|
||||
surfaceDeviceViewModel.ZIndex++;
|
||||
var newIndex = Math.Max(Devices.Count, surfaceDeviceViewModel.ZIndex + 1);
|
||||
var neighbor = Devices.FirstOrDefault(d => d.ZIndex == newIndex);
|
||||
if (neighbor != null)
|
||||
neighbor.ZIndex--;
|
||||
|
||||
surfaceDeviceViewModel.ZIndex = newIndex;
|
||||
|
||||
foreach (var deviceViewModel in Devices)
|
||||
Console.WriteLine(deviceViewModel.ZIndex);
|
||||
}
|
||||
|
||||
public void SendToBack(SurfaceDeviceViewModel surfaceDeviceViewModel)
|
||||
{
|
||||
Console.WriteLine("Send to back");
|
||||
var original = surfaceDeviceViewModel.ZIndex;
|
||||
surfaceDeviceViewModel.ZIndex = 1;
|
||||
foreach (var deviceViewModel in Devices)
|
||||
{
|
||||
if (deviceViewModel.ZIndex <= original && deviceViewModel != surfaceDeviceViewModel)
|
||||
deviceViewModel.ZIndex++;
|
||||
}
|
||||
|
||||
foreach (var deviceViewModel in Devices)
|
||||
Console.WriteLine(deviceViewModel.ZIndex);
|
||||
}
|
||||
|
||||
public void SendBackward(SurfaceDeviceViewModel surfaceDeviceViewModel)
|
||||
{
|
||||
surfaceDeviceViewModel.ZIndex--;
|
||||
var newIndex = Math.Max(0, surfaceDeviceViewModel.ZIndex - 1);
|
||||
var neighbor = Devices.FirstOrDefault(d => d.ZIndex == newIndex);
|
||||
if (neighbor != null)
|
||||
neighbor.ZIndex++;
|
||||
|
||||
surfaceDeviceViewModel.ZIndex = newIndex;
|
||||
|
||||
foreach (var deviceViewModel in Devices)
|
||||
Console.WriteLine(deviceViewModel.ZIndex);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -148,66 +148,39 @@
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</materialDesign:DialogHost.DialogContent>
|
||||
<materialDesign:DialogHost DialogClosing="{s:Action ConfigurationDialogClosing}">
|
||||
<materialDesign:DialogHost.DialogContent>
|
||||
<StackPanel Margin="16">
|
||||
<TextBlock>
|
||||
Add a new surface layout.
|
||||
</TextBlock>
|
||||
<TextBox Margin="0 8 0 0" HorizontalAlignment="Stretch" Text="{Binding NewConfigurationName}" />
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
|
||||
<Button Style="{StaticResource MaterialDesignFlatButton}" IsDefault="True" Margin="0 8 8 0" Command="materialDesign:DialogHost.CloseDialogCommand">
|
||||
<Button.CommandParameter>
|
||||
<system:Boolean xmlns:system="clr-namespace:System;assembly=mscorlib">
|
||||
True
|
||||
</system:Boolean>
|
||||
</Button.CommandParameter>
|
||||
ACCEPT
|
||||
</Button>
|
||||
<Button Style="{StaticResource MaterialDesignFlatButton}" IsCancel="True" Margin="0 8 8 0" Command="materialDesign:DialogHost.CloseDialogCommand">
|
||||
<Button.CommandParameter>
|
||||
<system:Boolean xmlns:system="clr-namespace:System;assembly=mscorlib">
|
||||
False
|
||||
</system:Boolean>
|
||||
</Button.CommandParameter>
|
||||
CANCEL
|
||||
</Button>
|
||||
</StackPanel>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<ListBox Grid.Row="0" ItemsSource="{Binding SurfaceConfigurations}">
|
||||
<ListBox.Resources>
|
||||
<DataTemplate DataType="{x:Type models:SurfaceConfiguration}">
|
||||
<TextBlock Text="{Binding Name}" ToolTip="{Binding Name}" />
|
||||
</DataTemplate>
|
||||
</ListBox.Resources>
|
||||
</ListBox>
|
||||
<materialDesign:PopupBox
|
||||
PopupMode="Click"
|
||||
Grid.Row="0"
|
||||
Style="{StaticResource MaterialDesignMultiFloatingActionPopupBox}"
|
||||
PlacementMode="LeftAndAlignMiddles"
|
||||
UnfurlOrientation="Horizontal"
|
||||
ToolTip="Manage surface layouts"
|
||||
Margin="0 0 10 10"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Bottom">
|
||||
<StackPanel
|
||||
Orientation="Horizontal">
|
||||
<Button ToolTip="Add a new surface layout" Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}">
|
||||
<materialDesign:PackIcon Kind="Add" />
|
||||
</Button>
|
||||
<Button ToolTip="Remove selected surface layout" Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}">
|
||||
<materialDesign:PackIcon Kind="Delete" />
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</materialDesign:DialogHost.DialogContent>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<ListBox Grid.Row="0" ItemsSource="{Binding SurfaceConfigurations}">
|
||||
<ListBox.Resources>
|
||||
<DataTemplate DataType="{x:Type models:SurfaceConfiguration}">
|
||||
<TextBlock Text="{Binding Name}" ToolTip="{Binding Name}" />
|
||||
</DataTemplate>
|
||||
</ListBox.Resources>
|
||||
</ListBox>
|
||||
<materialDesign:PopupBox
|
||||
Grid.Row="0"
|
||||
Style="{StaticResource MaterialDesignMultiFloatingActionPopupBox}"
|
||||
PlacementMode="LeftAndAlignMiddles"
|
||||
UnfurlOrientation="Horizontal"
|
||||
ToolTip="Manage surface layouts"
|
||||
Margin="0 0 10 10"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Bottom">
|
||||
<StackPanel
|
||||
Orientation="Horizontal">
|
||||
<Button ToolTip="Add a new surface layout" Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}">
|
||||
<materialDesign:PackIcon Kind="Add" />
|
||||
</Button>
|
||||
<Button ToolTip="Remove selected surface layout" Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}">
|
||||
<materialDesign:PackIcon Kind="Delete" />
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</materialDesign:PopupBox>
|
||||
</Grid>
|
||||
</materialDesign:DialogHost>
|
||||
</materialDesign:PopupBox>
|
||||
</Grid>
|
||||
</materialDesign:DialogHost>
|
||||
</materialDesign:Card>
|
||||
</Grid>
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
<package id="Fody" version="5.0.6" targetFramework="net472" developmentDependency="true" />
|
||||
<package id="Humanizer.Core" version="2.6.2" targetFramework="net461" />
|
||||
<package id="MahApps.Metro" version="1.6.5" targetFramework="net472" />
|
||||
<package id="MaterialDesignColors" version="1.1.3" targetFramework="net461" />
|
||||
<package id="MaterialDesignThemes" version="2.5.1" targetFramework="net461" />
|
||||
<package id="MaterialDesignThemes.MahApps" version="0.0.12" targetFramework="net461" />
|
||||
<package id="MaterialDesignColors" version="1.2.0" targetFramework="net472" />
|
||||
<package id="MaterialDesignThemes" version="2.6.0" targetFramework="net472" />
|
||||
<package id="MaterialDesignThemes.MahApps" version="0.1.0" targetFramework="net472" />
|
||||
<package id="Microsoft.Data.Sqlite" version="2.2.4" targetFramework="net472" />
|
||||
<package id="Microsoft.Data.Sqlite.Core" version="2.2.4" targetFramework="net472" />
|
||||
<package id="Ninject" version="3.3.4" targetFramework="net461" />
|
||||
@ -20,6 +20,6 @@
|
||||
<package id="SQLitePCLRaw.lib.e_sqlite3.osx" version="1.1.12" targetFramework="net472" />
|
||||
<package id="SQLitePCLRaw.lib.e_sqlite3.v110_xp" version="1.1.12" targetFramework="net472" />
|
||||
<package id="SQLitePCLRaw.provider.e_sqlite3.net45" version="1.1.12" targetFramework="net472" />
|
||||
<package id="Stylet" version="1.2.0" targetFramework="net472" />
|
||||
<package id="Stylet" version="1.3.0" targetFramework="net472" />
|
||||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
|
||||
</packages>
|
||||
Loading…
x
Reference in New Issue
Block a user