Plugins - Load features by their info before enabling plugins

General - Added missing XML comments
This commit is contained in:
Robert committed 2021-03-10 20:53:37 +01:00
1 parent fa26e6b7da
commit d5d1211649
24 files changed
+241 -180

No files matched your search

@@ -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));
}
}
}