mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Plugins - Load features by their info before enabling plugins
General - Added missing XML comments
This commit is contained in:
1 parent
fa26e6b7da
commit
d5d1211649
24 files changed
+241
-180
No files matched your search
+1
-1
@@ -136,7 +136,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
|
||||
RenderProfileElement.DisplayCondition.ChildRemoved += DisplayConditionOnChildrenModified;
|
||||
}
|
||||
|
||||
private void CoreServiceOnFrameRendered(object? sender, FrameRenderedEventArgs e)
|
||||
private void CoreServiceOnFrameRendered(object sender, FrameRenderedEventArgs e)
|
||||
{
|
||||
ActiveItem?.Evaluate();
|
||||
}
|
||||
|
||||
+2
-3
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
@@ -14,7 +13,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
{
|
||||
private readonly IDataBindingsVmFactory _dataBindingsVmFactory;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private ILayerProperty? _selectedDataBinding;
|
||||
private ILayerProperty _selectedDataBinding;
|
||||
private int _selectedItemIndex;
|
||||
private bool _updating;
|
||||
|
||||
@@ -95,7 +94,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
SubscribeToSelectedDataBinding();
|
||||
base.OnInitialActivate();
|
||||
}
|
||||
|
||||
|
||||
protected override void OnActivate()
|
||||
{
|
||||
SelectedItemIndex = 0;
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
<!-- Icon column -->
|
||||
<shared:ArtemisIcon Grid.Column="0"
|
||||
Icon="{Binding Feature.Info.Icon}"
|
||||
Icon="{Binding FeatureInfo.Icon}"
|
||||
Width="20"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Center"
|
||||
@@ -42,12 +42,12 @@
|
||||
</Button>
|
||||
|
||||
<!-- Display name column -->
|
||||
<TextBlock Grid.Column="1" Text="{Binding Feature.Info.Name}" Style="{StaticResource MaterialDesignTextBlock}" VerticalAlignment="Center" ToolTip="{Binding Feature.Info.Description}" />
|
||||
<TextBlock Grid.Column="1" Text="{Binding FeatureInfo.Name}" Style="{StaticResource MaterialDesignTextBlock}" VerticalAlignment="Center" ToolTip="{Binding FeatureInfo.Description}" />
|
||||
|
||||
<!-- Enable toggle column -->
|
||||
<StackPanel Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="8"
|
||||
Visibility="{Binding Enabling, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay, FallbackValue=Collapsed}">
|
||||
<CheckBox Style="{StaticResource MaterialDesignCheckBox}" IsChecked="{Binding IsEnabled}">
|
||||
<CheckBox Style="{StaticResource MaterialDesignCheckBox}" IsChecked="{Binding IsEnabled}" IsEnabled="{Binding FeatureInfo.Plugin.IsEnabled}">
|
||||
Feature enabled
|
||||
</CheckBox>
|
||||
</StackPanel>
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
private bool _enabling;
|
||||
private readonly IMessageService _messageService;
|
||||
|
||||
public PluginFeatureViewModel(PluginFeature feature,
|
||||
public PluginFeatureViewModel(PluginFeatureInfo pluginFeatureInfo,
|
||||
IDialogService dialogService,
|
||||
IPluginManagementService pluginManagementService,
|
||||
IMessageService messageService)
|
||||
@@ -25,11 +25,11 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
_pluginManagementService = pluginManagementService;
|
||||
_messageService = messageService;
|
||||
|
||||
Feature = feature;
|
||||
FeatureInfo = pluginFeatureInfo;
|
||||
}
|
||||
|
||||
public PluginFeature Feature { get; }
|
||||
public Exception LoadException => Feature.LoadException;
|
||||
public PluginFeatureInfo FeatureInfo { get; }
|
||||
public Exception LoadException => FeatureInfo.Instance?.LoadException;
|
||||
|
||||
public bool Enabling
|
||||
{
|
||||
@@ -39,7 +39,7 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get => Feature.IsEnabled;
|
||||
get => FeatureInfo.Instance != null && FeatureInfo.Instance.IsEnabled;
|
||||
set => Task.Run(() => UpdateEnabled(value));
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
if (LoadException == null)
|
||||
return;
|
||||
|
||||
_dialogService.ShowExceptionDialog("Feature failed to enable", Feature.LoadException);
|
||||
_dialogService.ShowExceptionDialog("Feature failed to enable", LoadException);
|
||||
}
|
||||
|
||||
protected override void OnInitialActivate()
|
||||
@@ -83,7 +83,7 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
|
||||
private async Task UpdateEnabled(bool enable)
|
||||
{
|
||||
if (IsEnabled == enable)
|
||||
if (IsEnabled == enable || FeatureInfo.Instance == null)
|
||||
{
|
||||
NotifyOfPropertyChange(nameof(IsEnabled));
|
||||
return;
|
||||
@@ -95,11 +95,11 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
|
||||
try
|
||||
{
|
||||
await Task.Run(() => _pluginManagementService.EnablePluginFeature(Feature, true));
|
||||
await Task.Run(() => _pluginManagementService.EnablePluginFeature(FeatureInfo.Instance, true));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_messageService.ShowMessage($"Failed to enable {Feature.Info.Name}\r\n{e.Message}", "VIEW LOGS", ShowLogsFolder);
|
||||
_messageService.ShowMessage($"Failed to enable {FeatureInfo.Name}\r\n{e.Message}", "VIEW LOGS", ShowLogsFolder);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -108,7 +108,7 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
}
|
||||
else
|
||||
{
|
||||
_pluginManagementService.DisablePluginFeature(Feature, true);
|
||||
_pluginManagementService.DisablePluginFeature(FeatureInfo.Instance, true);
|
||||
NotifyOfPropertyChange(nameof(IsEnabled));
|
||||
}
|
||||
}
|
||||
@@ -117,13 +117,13 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
|
||||
private void OnFeatureEnabling(object sender, PluginFeatureEventArgs e)
|
||||
{
|
||||
if (e.PluginFeature != Feature) return;
|
||||
if (e.PluginFeature != FeatureInfo.Instance) return;
|
||||
Enabling = true;
|
||||
}
|
||||
|
||||
private void OnFeatureEnableStopped(object sender, PluginFeatureEventArgs e)
|
||||
{
|
||||
if (e.PluginFeature != Feature) return;
|
||||
if (e.PluginFeature != FeatureInfo.Instance) return;
|
||||
Enabling = false;
|
||||
|
||||
NotifyOfPropertyChange(nameof(IsEnabled));
|
||||
|
||||
@@ -116,21 +116,11 @@
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Margin="10 10 0 5" Style="{StaticResource MaterialDesignBody2TextBlock}">Plugin features</TextBlock>
|
||||
<TextBlock Grid.Row="1"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="0 30 0 0"
|
||||
Style="{StaticResource MaterialDesignTextBlock}"
|
||||
Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}"
|
||||
Visibility="{Binding IsEnabled, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}">
|
||||
Enable the plugin to view its features
|
||||
</TextBlock>
|
||||
|
||||
<ListBox Grid.Row="1"
|
||||
MaxHeight="135"
|
||||
ItemsSource="{Binding Items}"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
VirtualizingPanel.ScrollUnit="Pixel"
|
||||
Visibility="{Binding IsEnabled, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}">
|
||||
VirtualizingPanel.ScrollUnit="Pixel">
|
||||
<b:Interaction.Behaviors>
|
||||
<shared:ScrollParentWhenAtMax />
|
||||
</b:Interaction.Behaviors>
|
||||
|
||||
@@ -117,22 +117,12 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
|
||||
protected override void OnInitialActivate()
|
||||
{
|
||||
Plugin.FeatureAdded += PluginOnFeatureAdded;
|
||||
Plugin.FeatureRemoved += PluginOnFeatureRemoved;
|
||||
foreach (PluginFeature pluginFeature in Plugin.Features)
|
||||
Items.Add(_settingsVmFactory.CreatePluginFeatureViewModel(pluginFeature));
|
||||
foreach (PluginFeatureInfo pluginFeatureInfo in Plugin.Features)
|
||||
Items.Add(_settingsVmFactory.CreatePluginFeatureViewModel(pluginFeatureInfo));
|
||||
|
||||
base.OnInitialActivate();
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
Plugin.FeatureAdded -= PluginOnFeatureAdded;
|
||||
Plugin.FeatureRemoved -= PluginOnFeatureRemoved;
|
||||
|
||||
base.OnClose();
|
||||
}
|
||||
|
||||
private async Task UpdateEnabled(bool enable)
|
||||
{
|
||||
if (IsEnabled == enable)
|
||||
@@ -178,17 +168,5 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
NotifyOfPropertyChange(nameof(IsEnabled));
|
||||
NotifyOfPropertyChange(nameof(CanOpenSettings));
|
||||
}
|
||||
|
||||
private void PluginOnFeatureRemoved(object sender, PluginFeatureEventArgs e)
|
||||
{
|
||||
PluginFeatureViewModel viewModel = Items.FirstOrDefault(i => i.Feature == e.PluginFeature);
|
||||
if (viewModel != null)
|
||||
Items.Remove(viewModel);
|
||||
}
|
||||
|
||||
private void PluginOnFeatureAdded(object sender, PluginFeatureEventArgs e)
|
||||
{
|
||||
Items.Add(_settingsVmFactory.CreatePluginFeatureViewModel(e.PluginFeature));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.DeviceProviders;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
@@ -27,9 +28,8 @@ namespace Artemis.UI.Screens.StartupWizard.Steps
|
||||
Items.Clear();
|
||||
|
||||
// _pluginManagementService.GetFeaturesOfType<>() will only give us enabled features so lets get all of them this way
|
||||
IEnumerable<DeviceProvider> features = _pluginManagementService.GetAllPlugins()
|
||||
.SelectMany(p => p.Features.Where(f => f is DeviceProvider))
|
||||
.Cast<DeviceProvider>()
|
||||
IEnumerable<PluginFeatureInfo> features = _pluginManagementService.GetAllPlugins()
|
||||
.SelectMany(p => p.Features.Where(f => typeof(DeviceProvider).IsAssignableFrom(f.FeatureType)))
|
||||
.OrderBy(d => d.GetType().Name);
|
||||
Items.AddRange(features.Select(d => _settingsVmFactory.CreatePluginFeatureViewModel(d)));
|
||||
|
||||
|
||||
Reference in new issue
Block a user