1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Data bindings UI - Update evaluation status of conditional data bindings

Profiles - Don't fail to activate a module when its last profile fails to load
This commit is contained in:
Robert 2021-03-16 19:47:27 +01:00
parent 12227b3530
commit 1a7a7e0582
5 changed files with 43 additions and 14 deletions

View File

@ -20,14 +20,14 @@ namespace Artemis.Core.JsonConverters
{ {
JValue? jsonValue = serializer.Deserialize<JValue>(reader); JValue? jsonValue = serializer.Deserialize<JValue>(reader);
if (jsonValue == null) if (jsonValue == null)
throw new FormatException(); throw new JsonReaderException("Failed to deserialize forgiving int value");
if (jsonValue.Type == JTokenType.Float) if (jsonValue.Type == JTokenType.Float)
return (int) Math.Round(jsonValue.Value<double>()); return (int) Math.Round(jsonValue.Value<double>());
if (jsonValue.Type == JTokenType.Integer) if (jsonValue.Type == JTokenType.Integer)
return jsonValue.Value<int>(); return jsonValue.Value<int>();
throw new FormatException(); throw new JsonReaderException("Failed to deserialize forgiving int value");
} }
} }
} }

View File

@ -47,15 +47,20 @@ namespace Artemis.Core.Services
{ {
module.Activate(false); module.Activate(false);
// If this is a profile module, activate the last active profile after module activation try
if (module is ProfileModule profileModule) {
await _profileService.ActivateLastProfileAnimated(profileModule); // If this is a profile module, activate the last active profile after module activation
if (module is ProfileModule profileModule)
await _profileService.ActivateLastProfileAnimated(profileModule);
}
catch (Exception e)
{
_logger.Warning(e, $"Failed to activate last profile on module {module}");
}
} }
catch (Exception e) catch (Exception e)
{ {
_logger.Error(new ArtemisPluginFeatureException( _logger.Error(new ArtemisPluginFeatureException(module, "Failed to activate module.", e), "Failed to activate module");
module, "Failed to activate module and last profile.", e), "Failed to activate module and last profile"
);
throw; throw;
} }
} }

View File

@ -15,7 +15,7 @@
</ResourceDictionary.MergedDictionaries> </ResourceDictionary.MergedDictionaries>
</ResourceDictionary> </ResourceDictionary>
</UserControl.Resources> </UserControl.Resources>
<Grid Margin="5 10 0 0"> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="*" /> <RowDefinition Height="*" />
@ -26,7 +26,8 @@
Background="{StaticResource PrimaryHueMidBrush}" Background="{StaticResource PrimaryHueMidBrush}"
BorderBrush="{StaticResource PrimaryHueMidBrush}" BorderBrush="{StaticResource PrimaryHueMidBrush}"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Command="{s:Action AddCondition}"> Command="{s:Action AddCondition}"
Margin="0 5">
ADD CONDITION ADD CONDITION
</Button> </Button>
@ -38,7 +39,7 @@
dd:DragDrop.UseDefaultDragAdorner="True" dd:DragDrop.UseDefaultDragAdorner="True"
HorizontalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"
VirtualizingPanel.ScrollUnit="Pixel" VirtualizingPanel.ScrollUnit="Pixel"
Margin="0 5 0 0"> Margin="-10 0 -10 -5">
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<ContentControl s:View.Model="{Binding}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" /> <ContentControl s:View.Model="{Binding}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Linq; using System.Linq;
using Artemis.Core; using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Extensions; using Artemis.UI.Extensions;
using Artemis.UI.Ninject.Factories; using Artemis.UI.Ninject.Factories;
using Artemis.UI.Shared.Services; using Artemis.UI.Shared.Services;
@ -10,16 +11,20 @@ using Stylet;
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.ConditionalDataBinding namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.ConditionalDataBinding
{ {
public sealed class ConditionalDataBindingModeViewModel<TLayerProperty, TProperty> : Conductor<DataBindingConditionViewModel<TLayerProperty, TProperty>>.Collection.AllActive, IDataBindingModeViewModel public sealed class ConditionalDataBindingModeViewModel<TLayerProperty, TProperty> : Conductor<DataBindingConditionViewModel<TLayerProperty, TProperty>>.Collection.AllActive,
IDataBindingModeViewModel
{ {
private readonly IDataBindingsVmFactory _dataBindingsVmFactory; private readonly IDataBindingsVmFactory _dataBindingsVmFactory;
private readonly ICoreService _coreService;
private readonly IProfileEditorService _profileEditorService; private readonly IProfileEditorService _profileEditorService;
private bool _updating; private bool _updating;
public ConditionalDataBindingModeViewModel(ConditionalDataBinding<TLayerProperty, TProperty> conditionalDataBinding, public ConditionalDataBindingModeViewModel(ConditionalDataBinding<TLayerProperty, TProperty> conditionalDataBinding,
ICoreService coreService,
IProfileEditorService profileEditorService, IProfileEditorService profileEditorService,
IDataBindingsVmFactory dataBindingsVmFactory) IDataBindingsVmFactory dataBindingsVmFactory)
{ {
_coreService = coreService;
_profileEditorService = profileEditorService; _profileEditorService = profileEditorService;
_dataBindingsVmFactory = dataBindingsVmFactory; _dataBindingsVmFactory = dataBindingsVmFactory;
@ -41,8 +46,21 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.Conditio
protected override void OnInitialActivate() protected override void OnInitialActivate()
{ {
base.OnInitialActivate();
Initialize(); Initialize();
_coreService.FrameRendered += CoreServiceOnFrameRendered;
base.OnInitialActivate();
}
protected override void OnClose()
{
_coreService.FrameRendered -= CoreServiceOnFrameRendered;
base.OnClose();
}
private void CoreServiceOnFrameRendered(object? sender, FrameRenderedEventArgs e)
{
foreach (DataBindingConditionViewModel<TLayerProperty, TProperty> dataBindingConditionViewModel in Items)
dataBindingConditionViewModel.Evaluate();
} }
private void UpdateItems() private void UpdateItems()
@ -109,7 +127,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.Conditio
} }
#region IDisposable #region IDisposable
/// <inheritdoc /> /// <inheritdoc />
public void Dispose() public void Dispose()
{ {

View File

@ -56,6 +56,11 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.Conditio
_profileEditorService.UpdateSelectedProfileElement(); _profileEditorService.UpdateSelectedProfileElement();
} }
public void Evaluate()
{
ActiveItem?.Evaluate();
}
#region IDisposable #region IDisposable
/// <inheritdoc /> /// <inheritdoc />