mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Plugins - Ported prerequisites UI
Scripting - Ported scripting UI
This commit is contained in:
1 parent
0256a0d625
commit
3b4194cb9d
56 files changed
+1301
-274
No files matched your search
@@ -0,0 +1,84 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:plugins="clr-namespace:Artemis.UI.Screens.Plugins"
|
||||
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Plugins.PluginPrerequisitesInstallDialogView"
|
||||
x:DataType="plugins:PluginPrerequisitesInstallDialogViewModel">
|
||||
<UserControl.Styles>
|
||||
<Styles>
|
||||
<Style Selector="Border.status-border">
|
||||
<Setter Property="Width" Value="32" />
|
||||
<Setter Property="Height" Value="32" />
|
||||
<Setter Property="CornerRadius" Value="16" />
|
||||
</Style>
|
||||
|
||||
<Style Selector="Border.status-border avalonia|MaterialIcon">
|
||||
<Setter Property="Width" Value="16" />
|
||||
<Setter Property="Height" Value="16" />
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
<Setter Property="HorizontalAlignment" Value="Center" />
|
||||
</Style>
|
||||
</Styles>
|
||||
</UserControl.Styles>
|
||||
<Grid ColumnDefinitions="250,*">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition MinHeight="200" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<ListBox Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Items="{CompiledBinding Prerequisites}"
|
||||
SelectedItem="{CompiledBinding ActivePrerequisite, Mode=OneWay}"
|
||||
IsHitTestVisible="False">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type plugins:PluginPrerequisiteViewModel}">
|
||||
<Grid ColumnDefinitions="Auto,*" Margin="0 6">
|
||||
<Border Grid.Row="0" Grid.Column="0" Classes="status-border" IsVisible="{CompiledBinding !IsMet}" Background="#ff3838">
|
||||
<avalonia:MaterialIcon Kind="Close" />
|
||||
</Border>
|
||||
<Border Grid.Row="0" Grid.Column="0" Classes="status-border" IsVisible="{CompiledBinding IsMet}" Background="#32a852">
|
||||
<avalonia:MaterialIcon Kind="Check" />
|
||||
</Border>
|
||||
|
||||
<StackPanel Margin="8 0 0 0" Grid.Column="1" VerticalAlignment="Stretch">
|
||||
<TextBlock FontWeight="Bold" Text="{CompiledBinding PluginPrerequisite.Name}" TextWrapping="Wrap" />
|
||||
<TextBlock Text="{CompiledBinding PluginPrerequisite.Description}" TextWrapping="Wrap" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
|
||||
<ContentControl Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
Content="{CompiledBinding ActivePrerequisite}"
|
||||
VerticalContentAlignment="Stretch"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
Margin="10 0"
|
||||
IsTabStop="False"
|
||||
IsVisible="{CompiledBinding ShowProgress, Mode=OneWay}" />
|
||||
|
||||
<TextBlock Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
TextWrapping="Wrap"
|
||||
Margin="10 0"
|
||||
IsVisible="{CompiledBinding ShowIntro, Mode=OneWay}">
|
||||
In order for this plugin to work the prerequisites on the left must be met. Clicking install will automatically set everything up for you.
|
||||
</TextBlock>
|
||||
|
||||
<StackPanel Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
Margin="10 0"
|
||||
IsVisible="{CompiledBinding ShowFailed, Mode=OneWay}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock>Installing</TextBlock>
|
||||
<TextBlock Text="{CompiledBinding ActivePrerequisite.PluginPrerequisite.Name, Mode=OneWay}" FontWeight="SemiBold" TextWrapping="Wrap" />
|
||||
<TextBlock>failed.</TextBlock>
|
||||
</StackPanel>
|
||||
<TextBlock TextWrapping="Wrap">You may try again to see if that helps, otherwise install the prerequisite manually or contact the plugin developer.</TextBlock>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,19 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Plugins;
|
||||
|
||||
public partial class PluginPrerequisitesInstallDialogView : ReactiveUserControl<PluginPrerequisitesInstallDialogViewModel>
|
||||
{
|
||||
public PluginPrerequisitesInstallDialogView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
+30
-19
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -9,11 +10,14 @@ using Artemis.Core;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Avalonia.Threading;
|
||||
using FluentAvalonia.UI.Controls;
|
||||
using ReactiveUI;
|
||||
using ContentDialogButton = Artemis.UI.Shared.Services.Builders.ContentDialogButton;
|
||||
|
||||
namespace Artemis.UI.Screens.Plugins
|
||||
{
|
||||
public class PluginPrerequisitesInstallDialogViewModel : DialogViewModelBase<bool>
|
||||
public class PluginPrerequisitesInstallDialogViewModel : ContentDialogViewModelBase
|
||||
{
|
||||
private PluginPrerequisiteViewModel? _activePrerequisite;
|
||||
private bool _canInstall;
|
||||
@@ -26,22 +30,23 @@ namespace Artemis.UI.Screens.Plugins
|
||||
public PluginPrerequisitesInstallDialogViewModel(List<IPrerequisitesSubject> subjects, IPrerequisitesVmFactory prerequisitesVmFactory)
|
||||
{
|
||||
Prerequisites = new ObservableCollection<PluginPrerequisiteViewModel>();
|
||||
foreach (PluginPrerequisite prerequisite in subjects.SelectMany(prerequisitesSubject => prerequisitesSubject.Prerequisites))
|
||||
foreach (PluginPrerequisite prerequisite in subjects.SelectMany(prerequisitesSubject => prerequisitesSubject.PlatformPrerequisites))
|
||||
Prerequisites.Add(prerequisitesVmFactory.PluginPrerequisiteViewModel(prerequisite, false));
|
||||
Install = ReactiveCommand.CreateFromTask(ExecuteInstall, this.WhenAnyValue(vm => vm.CanInstall));
|
||||
|
||||
CanInstall = false;
|
||||
Task.Run(() => CanInstall = Prerequisites.Any(p => !p.PluginPrerequisite.IsMet()));
|
||||
|
||||
Dispatcher.UIThread.Post(() => CanInstall = Prerequisites.Any(p => !p.PluginPrerequisite.IsMet()), DispatcherPriority.Background);
|
||||
this.WhenActivated(d =>
|
||||
{
|
||||
Disposable.Create(() =>
|
||||
{
|
||||
_tokenSource?.Cancel();
|
||||
_tokenSource?.Dispose();
|
||||
_tokenSource = null;
|
||||
}).DisposeWith(d);
|
||||
});
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit, Unit> Install { get; }
|
||||
public ObservableCollection<PluginPrerequisiteViewModel> Prerequisites { get; }
|
||||
|
||||
public PluginPrerequisiteViewModel? ActivePrerequisite
|
||||
@@ -80,13 +85,18 @@ namespace Artemis.UI.Screens.Plugins
|
||||
set => RaiseAndSetIfChanged(ref _canInstall, value);
|
||||
}
|
||||
|
||||
public async Task Install()
|
||||
private async Task ExecuteInstall()
|
||||
{
|
||||
ContentDialogClosingDeferral? deferral = null;
|
||||
if (ContentDialog != null)
|
||||
ContentDialog.Closing += (_, args) => deferral = args.GetDeferral();
|
||||
|
||||
CanInstall = false;
|
||||
ShowFailed = false;
|
||||
ShowIntro = false;
|
||||
ShowProgress = true;
|
||||
|
||||
_tokenSource?.Dispose();
|
||||
_tokenSource = new CancellationTokenSource();
|
||||
|
||||
try
|
||||
@@ -110,30 +120,31 @@ namespace Artemis.UI.Screens.Plugins
|
||||
|
||||
// Wait after the task finished for the user to process what happened
|
||||
if (pluginPrerequisiteViewModel != Prerequisites.Last())
|
||||
await Task.Delay(250);
|
||||
else
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
|
||||
ShowInstall = false;
|
||||
if (deferral != null)
|
||||
deferral.Complete();
|
||||
else
|
||||
ContentDialog?.Hide(ContentDialogResult.Primary);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
finally
|
||||
{
|
||||
_tokenSource.Dispose();
|
||||
_tokenSource = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Accept()
|
||||
public static async Task Show(IWindowService windowService, List<IPrerequisitesSubject> subjects)
|
||||
{
|
||||
Close(true);
|
||||
}
|
||||
|
||||
public static async Task<bool> Show(IWindowService windowService, List<IPrerequisitesSubject> subjects)
|
||||
{
|
||||
return await windowService.ShowDialogAsync<PluginPrerequisitesInstallDialogViewModel, bool>(("subjects", subjects));
|
||||
await windowService.CreateContentDialog()
|
||||
.WithTitle("Plugin prerequisites")
|
||||
.WithViewModel(out PluginPrerequisitesInstallDialogViewModel vm, ("subjects", subjects))
|
||||
.WithCloseButtonText("Cancel")
|
||||
.HavingPrimaryButton(b => b.WithText("Install").WithCommand(vm.Install))
|
||||
.WithDefaultButton(ContentDialogButton.Primary)
|
||||
.ShowAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:plugins="clr-namespace:Artemis.UI.Screens.Plugins"
|
||||
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Plugins.PluginPrerequisitesUninstallDialogView"
|
||||
x:DataType="plugins:PluginPrerequisitesUninstallDialogViewModel">
|
||||
<UserControl.Styles>
|
||||
<Styles>
|
||||
<Style Selector="Border.status-border">
|
||||
<Setter Property="Width" Value="32" />
|
||||
<Setter Property="Height" Value="32" />
|
||||
<Setter Property="CornerRadius" Value="16" />
|
||||
</Style>
|
||||
|
||||
<Style Selector="Border.status-border avalonia|MaterialIcon">
|
||||
<Setter Property="Width" Value="16" />
|
||||
<Setter Property="Height" Value="16" />
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
<Setter Property="HorizontalAlignment" Value="Center" />
|
||||
</Style>
|
||||
</Styles>
|
||||
</UserControl.Styles>
|
||||
<Grid ColumnDefinitions="250,*">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition MinHeight="200" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<ListBox Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Items="{CompiledBinding Prerequisites}"
|
||||
SelectedItem="{CompiledBinding ActivePrerequisite, Mode=OneWay}"
|
||||
IsHitTestVisible="False">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type plugins:PluginPrerequisiteViewModel}">
|
||||
<Grid ColumnDefinitions="Auto,*" Margin="0 6">
|
||||
<Border Grid.Row="0" Grid.Column="0" Classes="status-border" IsVisible="{CompiledBinding !IsMet}" Background="#ff3838">
|
||||
<avalonia:MaterialIcon Kind="Close" />
|
||||
</Border>
|
||||
<Border Grid.Row="0" Grid.Column="0" Classes="status-border" IsVisible="{CompiledBinding IsMet}" Background="#32a852">
|
||||
<avalonia:MaterialIcon Kind="Check" />
|
||||
</Border>
|
||||
|
||||
<StackPanel Margin="8 0 0 0" Grid.Column="1" VerticalAlignment="Stretch">
|
||||
<TextBlock FontWeight="Bold" Text="{CompiledBinding PluginPrerequisite.Name}" TextWrapping="Wrap" />
|
||||
<TextBlock Text="{CompiledBinding PluginPrerequisite.Description}" TextWrapping="Wrap" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
|
||||
<ContentControl Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
Content="{CompiledBinding ActivePrerequisite}"
|
||||
VerticalContentAlignment="Stretch"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
Margin="10 0"
|
||||
IsTabStop="False"
|
||||
IsVisible="{CompiledBinding ActivePrerequisite, Converter={x:Static ObjectConverters.IsNotNull}}" />
|
||||
|
||||
<TextBlock Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
TextWrapping="Wrap"
|
||||
Margin="10 0"
|
||||
IsVisible="{CompiledBinding ActivePrerequisite, Converter={x:Static ObjectConverters.IsNull}}">
|
||||
This plugin/feature installed certain prerequisites in order to function. In this screen you can chose to remove these, this will mean the plugin/feature will no longer work until you reinstall the prerequisites.
|
||||
</TextBlock>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Plugins;
|
||||
|
||||
public partial class PluginPrerequisitesUninstallDialogView : ReactiveUserControl<PluginPrerequisitesUninstallDialogViewModel>
|
||||
{
|
||||
public PluginPrerequisitesUninstallDialogView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
+49
-38
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -10,34 +11,38 @@ using Artemis.Core.Services;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Avalonia.Threading;
|
||||
using FluentAvalonia.UI.Controls;
|
||||
using ReactiveUI;
|
||||
using ContentDialogButton = Artemis.UI.Shared.Services.Builders.ContentDialogButton;
|
||||
|
||||
namespace Artemis.UI.Screens.Plugins
|
||||
{
|
||||
public class PluginPrerequisitesUninstallDialogViewModel : DialogViewModelBase<bool>
|
||||
public class PluginPrerequisitesUninstallDialogViewModel : ContentDialogViewModelBase
|
||||
{
|
||||
private readonly IPluginManagementService _pluginManagementService;
|
||||
private readonly List<IPrerequisitesSubject> _subjects;
|
||||
private readonly IWindowService _windowService;
|
||||
private PluginPrerequisiteViewModel? _activePrerequisite;
|
||||
private bool _canUninstall;
|
||||
private bool _isFinished;
|
||||
private CancellationTokenSource? _tokenSource;
|
||||
|
||||
public PluginPrerequisitesUninstallDialogViewModel(List<IPrerequisitesSubject> subjects, string cancelLabel, IPrerequisitesVmFactory prerequisitesVmFactory, IWindowService windowService,
|
||||
public PluginPrerequisitesUninstallDialogViewModel(List<IPrerequisitesSubject> subjects,
|
||||
IPrerequisitesVmFactory prerequisitesVmFactory,
|
||||
IWindowService windowService,
|
||||
IPluginManagementService pluginManagementService)
|
||||
{
|
||||
_subjects = subjects;
|
||||
_windowService = windowService;
|
||||
_pluginManagementService = pluginManagementService;
|
||||
|
||||
CancelLabel = cancelLabel;
|
||||
Prerequisites = new ObservableCollection<PluginPrerequisiteViewModel>();
|
||||
foreach (PluginPrerequisite prerequisite in subjects.SelectMany(prerequisitesSubject => prerequisitesSubject.Prerequisites))
|
||||
foreach (PluginPrerequisite prerequisite in subjects.SelectMany(prerequisitesSubject => prerequisitesSubject.PlatformPrerequisites))
|
||||
Prerequisites.Add(prerequisitesVmFactory.PluginPrerequisiteViewModel(prerequisite, true));
|
||||
Uninstall = ReactiveCommand.CreateFromTask(ExecuteUninstall, this.WhenAnyValue(vm => vm.CanUninstall));
|
||||
|
||||
// Could be slow so take it off of the UI thread
|
||||
Task.Run(() => CanUninstall = Prerequisites.Any(p => p.PluginPrerequisite.IsMet()));
|
||||
Dispatcher.UIThread.Post(() => CanUninstall = Prerequisites.Any(p => p.PluginPrerequisite.IsMet()), DispatcherPriority.Background);
|
||||
|
||||
this.WhenActivated(d =>
|
||||
{
|
||||
@@ -45,11 +50,12 @@ namespace Artemis.UI.Screens.Plugins
|
||||
{
|
||||
_tokenSource?.Cancel();
|
||||
_tokenSource?.Dispose();
|
||||
_tokenSource = null;
|
||||
}).DisposeWith(d);
|
||||
});
|
||||
}
|
||||
|
||||
public string CancelLabel { get; }
|
||||
public ReactiveCommand<Unit, Unit> Uninstall { get; }
|
||||
public ObservableCollection<PluginPrerequisiteViewModel> Prerequisites { get; }
|
||||
|
||||
public PluginPrerequisiteViewModel? ActivePrerequisite
|
||||
@@ -64,20 +70,19 @@ namespace Artemis.UI.Screens.Plugins
|
||||
set => RaiseAndSetIfChanged(ref _canUninstall, value);
|
||||
}
|
||||
|
||||
public bool IsFinished
|
||||
private async Task ExecuteUninstall()
|
||||
{
|
||||
get => _isFinished;
|
||||
set => RaiseAndSetIfChanged(ref _isFinished, value);
|
||||
}
|
||||
ContentDialogClosingDeferral? deferral = null;
|
||||
if (ContentDialog != null)
|
||||
ContentDialog.Closing += (_, args) => deferral = args.GetDeferral();
|
||||
|
||||
public async Task Uninstall()
|
||||
{
|
||||
CanUninstall = false;
|
||||
|
||||
// Disable all subjects that are plugins, this will disable their features too
|
||||
foreach (IPrerequisitesSubject prerequisitesSubject in _subjects)
|
||||
{
|
||||
if (prerequisitesSubject is PluginInfo pluginInfo) _pluginManagementService.DisablePlugin(pluginInfo.Plugin, true);
|
||||
if (prerequisitesSubject is PluginInfo pluginInfo)
|
||||
_pluginManagementService.DisablePlugin(pluginInfo.Plugin, true);
|
||||
}
|
||||
|
||||
// Disable all subjects that are features if still required
|
||||
@@ -88,9 +93,11 @@ namespace Artemis.UI.Screens.Plugins
|
||||
// Disable the parent plugin if the feature is AlwaysEnabled
|
||||
if (featureInfo.AlwaysEnabled)
|
||||
_pluginManagementService.DisablePlugin(featureInfo.Plugin, true);
|
||||
else if (featureInfo.Instance != null) _pluginManagementService.DisablePluginFeature(featureInfo.Instance, true);
|
||||
else if (featureInfo.Instance != null)
|
||||
_pluginManagementService.DisablePluginFeature(featureInfo.Instance, true);
|
||||
}
|
||||
|
||||
_tokenSource?.Dispose();
|
||||
_tokenSource = new CancellationTokenSource();
|
||||
|
||||
try
|
||||
@@ -98,29 +105,34 @@ namespace Artemis.UI.Screens.Plugins
|
||||
foreach (PluginPrerequisiteViewModel pluginPrerequisiteViewModel in Prerequisites)
|
||||
{
|
||||
pluginPrerequisiteViewModel.IsMet = pluginPrerequisiteViewModel.PluginPrerequisite.IsMet();
|
||||
if (!pluginPrerequisiteViewModel.IsMet) continue;
|
||||
if (!pluginPrerequisiteViewModel.IsMet)
|
||||
continue;
|
||||
|
||||
ActivePrerequisite = pluginPrerequisiteViewModel;
|
||||
await ActivePrerequisite.Uninstall(_tokenSource.Token);
|
||||
|
||||
// Wait after the task finished for the user to process what happened
|
||||
if (pluginPrerequisiteViewModel != Prerequisites.Last()) await Task.Delay(1000);
|
||||
}
|
||||
|
||||
if (Prerequisites.All(p => !p.IsMet))
|
||||
{
|
||||
IsFinished = true;
|
||||
return;
|
||||
if (pluginPrerequisiteViewModel != Prerequisites.Last())
|
||||
await Task.Delay(250);
|
||||
else
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
|
||||
if (deferral != null)
|
||||
deferral.Complete();
|
||||
else
|
||||
ContentDialog?.Hide(ContentDialogResult.Primary);
|
||||
|
||||
// This shouldn't be happening and the experience isn't very nice for the user (too lazy to make a nice UI for such an edge case)
|
||||
// but at least give some feedback
|
||||
Close(false);
|
||||
await _windowService.CreateContentDialog()
|
||||
.WithTitle("Plugin prerequisites")
|
||||
.WithContent("The plugin was not able to fully remove all prerequisites. \r\nPlease try again or contact the plugin creator.")
|
||||
.ShowAsync();
|
||||
await Show(_windowService, _subjects);
|
||||
if (Prerequisites.Any(p => p.IsMet))
|
||||
{
|
||||
await _windowService.CreateContentDialog()
|
||||
.WithTitle("Plugin prerequisites")
|
||||
.WithContent("The plugin was not able to fully remove all prerequisites. \r\nPlease try again or contact the plugin creator.")
|
||||
.ShowAsync();
|
||||
await Show(_windowService, _subjects);
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
@@ -129,19 +141,18 @@ namespace Artemis.UI.Screens.Plugins
|
||||
finally
|
||||
{
|
||||
CanUninstall = true;
|
||||
_tokenSource.Dispose();
|
||||
_tokenSource = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Accept()
|
||||
public static async Task Show(IWindowService windowService, List<IPrerequisitesSubject> subjects, string cancelLabel = "Cancel")
|
||||
{
|
||||
Close(true);
|
||||
}
|
||||
|
||||
public static async Task<object> Show(IWindowService windowService, List<IPrerequisitesSubject> subjects, string cancelLabel = "Cancel")
|
||||
{
|
||||
return await windowService.ShowDialogAsync<PluginPrerequisitesUninstallDialogViewModel, bool>(("subjects", subjects), ("cancelLabel", cancelLabel));
|
||||
await windowService.CreateContentDialog()
|
||||
.WithTitle("Plugin prerequisites")
|
||||
.WithViewModel(out PluginPrerequisitesUninstallDialogViewModel vm, ("subjects", subjects))
|
||||
.WithCloseButtonText(cancelLabel)
|
||||
.HavingPrimaryButton(b => b.WithText("Uninstall").WithCommand(vm.Uninstall))
|
||||
.WithDefaultButton(ContentDialogButton.Primary)
|
||||
.ShowAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,8 +76,8 @@ namespace Artemis.UI.Screens.Plugins
|
||||
}
|
||||
|
||||
public bool CanToggleEnabled => FeatureInfo.Plugin.IsEnabled && !FeatureInfo.AlwaysEnabled;
|
||||
public bool CanInstallPrerequisites => FeatureInfo.Prerequisites.Any();
|
||||
public bool CanRemovePrerequisites => FeatureInfo.Prerequisites.Any(p => p.UninstallActions.Any());
|
||||
public bool CanInstallPrerequisites => FeatureInfo.PlatformPrerequisites.Any();
|
||||
public bool CanRemovePrerequisites => FeatureInfo.PlatformPrerequisites.Any(p => p.UninstallActions.Any());
|
||||
public bool IsPopupEnabled => CanInstallPrerequisites || CanRemovePrerequisites;
|
||||
|
||||
public void ShowLogsFolder()
|
||||
@@ -100,13 +100,13 @@ namespace Artemis.UI.Screens.Plugins
|
||||
|
||||
public async Task InstallPrerequisites()
|
||||
{
|
||||
if (FeatureInfo.Prerequisites.Any())
|
||||
if (FeatureInfo.PlatformPrerequisites.Any())
|
||||
await PluginPrerequisitesInstallDialogViewModel.Show(_windowService, new List<IPrerequisitesSubject> {FeatureInfo});
|
||||
}
|
||||
|
||||
public async Task RemovePrerequisites()
|
||||
{
|
||||
if (FeatureInfo.Prerequisites.Any(p => p.UninstallActions.Any()))
|
||||
if (FeatureInfo.PlatformPrerequisites.Any(p => p.UninstallActions.Any()))
|
||||
{
|
||||
await PluginPrerequisitesUninstallDialogViewModel.Show(_windowService, new List<IPrerequisitesSubject> {FeatureInfo});
|
||||
this.RaisePropertyChanged(nameof(IsEnabled));
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:plugins="clr-namespace:Artemis.UI.Screens.Plugins"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Plugins.PluginPrerequisiteActionView"
|
||||
x:DataType="plugins:PluginPrerequisiteActionViewModel">
|
||||
<StackPanel>
|
||||
<ProgressBar Value="{CompiledBinding Action.Progress.Percentage, Mode=OneWay}"
|
||||
IsIndeterminate="{CompiledBinding Action.ProgressIndeterminate, Mode=OneWay}"
|
||||
IsVisible="{CompiledBinding Action.ShowProgressBar, Mode=OneWay}"
|
||||
Margin="0 10"/>
|
||||
<ProgressBar Value="{CompiledBinding Action.SubProgress.Percentage, Mode=OneWay}"
|
||||
IsIndeterminate="{CompiledBinding Action.SubProgressIndeterminate, Mode=OneWay}"
|
||||
IsVisible="{CompiledBinding Action.ShowSubProgressBar, Mode=OneWay}"
|
||||
Margin="0 10"/>
|
||||
|
||||
<TextBlock TextWrapping="Wrap" Text="{CompiledBinding Action.Status, Mode=OneWay}" />
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,18 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Artemis.UI.Screens.Plugins;
|
||||
|
||||
public partial class PluginPrerequisiteActionView : UserControl
|
||||
{
|
||||
public PluginPrerequisiteActionView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:plugins="clr-namespace:Artemis.UI.Screens.Plugins"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Plugins.PluginPrerequisiteView"
|
||||
x:DataType="plugins:PluginPrerequisiteViewModel">
|
||||
<StackPanel>
|
||||
<TextBlock TextWrapping="Wrap" Text="{CompiledBinding PluginPrerequisite.Name, Mode=OneWay}" />
|
||||
<TextBlock Classes="subtitle" TextWrapping="Wrap" Text="{CompiledBinding PluginPrerequisite.Description, Mode=OneWay}" Margin="0 0 0 15" />
|
||||
|
||||
<StackPanel Orientation="Horizontal" IsVisible="{CompiledBinding ActiveAction, Converter={x:Static ObjectConverters.IsNotNull}}">
|
||||
<TextBlock Text="Step " />
|
||||
<TextBlock Text="{CompiledBinding ActiveStepNumber, Mode=OneWay}" />
|
||||
<TextBlock Text="/" />
|
||||
<TextBlock Text="{CompiledBinding Actions.Count, Mode=OneWay}" />
|
||||
<TextBlock Text=" - " />
|
||||
<TextBlock Text="{CompiledBinding ActiveAction.Action.Name, Mode=OneWay, FallbackValue=''}" />
|
||||
</StackPanel>
|
||||
<TextBlock Foreground="{DynamicResource MaterialDesignBodyLight}" TextWrapping="Wrap" IsVisible="{CompiledBinding Actions.Count}">
|
||||
|
||||
</TextBlock>
|
||||
<TextBlock Classes="h4" TextWrapping="Wrap" Text="{CompiledBinding ActiveAction.Action.Name, Mode=OneWay}" IsVisible="{CompiledBinding !Actions.Count}" />
|
||||
<ContentControl Content="{CompiledBinding ActiveAction}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,19 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Plugins;
|
||||
|
||||
public partial class PluginPrerequisiteView : ReactiveUserControl<PluginPrerequisiteViewModel>
|
||||
{
|
||||
public PluginPrerequisiteView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,6 @@ namespace Artemis.UI.Screens.Plugins
|
||||
|
||||
public bool Busy => _busy.Value;
|
||||
public int ActiveStepNumber => _activeStepNumber.Value;
|
||||
public bool HasMultipleActions => Actions.Count > 1;
|
||||
|
||||
public async Task Install(CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
@@ -5,12 +5,14 @@
|
||||
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
|
||||
xmlns:controls="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
|
||||
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
||||
xmlns:plugins="clr-namespace:Artemis.UI.Screens.Plugins"
|
||||
mc:Ignorable="d" d:DesignWidth="900" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Plugins.PluginSettingsView">
|
||||
x:Class="Artemis.UI.Screens.Plugins.PluginSettingsView"
|
||||
x:DataType="plugins:PluginSettingsViewModel">
|
||||
<Border Classes="card" Padding="15" Margin="0 5">
|
||||
<Grid RowDefinitions="*,Auto" ColumnDefinitions="4*,5*">
|
||||
<Grid Grid.Row="0" RowDefinitions="Auto,Auto,*" ColumnDefinitions="80,*">
|
||||
<shared:ArtemisIcon Icon="{Binding Plugin.Info.ResolvedIcon}"
|
||||
<shared:ArtemisIcon Icon="{CompiledBinding Plugin.Info.ResolvedIcon}"
|
||||
Width="48"
|
||||
Height="48"
|
||||
Margin="0 5 0 0"
|
||||
@@ -18,52 +20,52 @@
|
||||
Grid.RowSpan="3"
|
||||
VerticalAlignment="Top" />
|
||||
|
||||
<TextBlock Grid.Column="1" Grid.Row="0" Classes="h5 no-margin" Text="{Binding Plugin.Info.Name}" />
|
||||
<TextBlock Grid.Column="1" Grid.Row="0" Classes="h5 no-margin" Text="{CompiledBinding Plugin.Info.Name}" />
|
||||
|
||||
<TextBlock Grid.Column="1"
|
||||
Grid.Row="1"
|
||||
Classes="subtitle"
|
||||
Text="{Binding Plugin.Info.Author}"
|
||||
IsVisible="{Binding Plugin.Info.Author, Converter={x:Static StringConverters.IsNotNullOrEmpty}}" />
|
||||
Text="{CompiledBinding Plugin.Info.Author}"
|
||||
IsVisible="{CompiledBinding Plugin.Info.Author, Converter={x:Static StringConverters.IsNotNullOrEmpty}}" />
|
||||
|
||||
<TextBlock Grid.Column="1"
|
||||
Grid.Row="2"
|
||||
TextWrapping="Wrap"
|
||||
Margin="0 5"
|
||||
Text="{Binding Plugin.Info.Description}" />
|
||||
Text="{CompiledBinding Plugin.Info.Description}" />
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Row="1" Grid.Column="0" ColumnDefinitions="*,Auto">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<controls:SplitButton Content="Settings" Command="{Binding OpenSettings}">
|
||||
<controls:SplitButton Content="Settings" Command="{CompiledBinding OpenSettings}">
|
||||
<controls:SplitButton.Flyout>
|
||||
<MenuFlyout Placement="Bottom">
|
||||
<MenuItem Header="Open plugin directory" Command="{Binding OpenPluginDirectory}">
|
||||
<MenuFlyout Placement="Bottom" IsOpen="{CompiledBinding IsSettingsPopupOpen, Mode=OneWayToSource}">
|
||||
<MenuItem Header="Open plugin directory" Command="{CompiledBinding OpenPluginDirectory}">
|
||||
<MenuItem.Icon>
|
||||
<avalonia:MaterialIcon Kind="FolderOpen" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Reload plugin" Command="{Binding Reload}">
|
||||
<MenuItem Header="Reload plugin" Command="{CompiledBinding Reload}">
|
||||
<MenuItem.Icon>
|
||||
<avalonia:MaterialIcon Kind="Reload" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Install prerequisites" Command="{Binding InstallPrerequisites}">
|
||||
<MenuItem Header="Install prerequisites" Command="{CompiledBinding InstallPrerequisites}">
|
||||
<MenuItem.Icon>
|
||||
<avalonia:MaterialIcon Kind="CheckAll" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Remove prerequisites" Command="{Binding RemovePrerequisites}">
|
||||
<MenuItem Header="Remove prerequisites" Command="{CompiledBinding RemovePrerequisites}">
|
||||
<MenuItem.Icon>
|
||||
<avalonia:MaterialIcon Kind="Delete" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Clear plugin settings" Command="{Binding RemoveSettings}">
|
||||
<MenuItem Header="Clear plugin settings" Command="{CompiledBinding RemoveSettings}">
|
||||
<MenuItem.Icon>
|
||||
<avalonia:MaterialIcon Kind="DatabaseRemove" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Remove plugin" Command="{Binding Remove}">
|
||||
<MenuItem Header="Remove plugin" Command="{CompiledBinding Remove}">
|
||||
<MenuItem.Icon>
|
||||
<avalonia:MaterialIcon Kind="DeleteForever" />
|
||||
</MenuItem.Icon>
|
||||
@@ -74,14 +76,14 @@
|
||||
|
||||
<controls:HyperlinkButton Classes="icon-button icon-button-large"
|
||||
Margin="5 0"
|
||||
IsVisible="{Binding Plugin.Info.Website, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
|
||||
NavigateUri="{Binding Plugin.Info.Website}">
|
||||
IsVisible="{CompiledBinding Plugin.Info.Website, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
|
||||
NavigateUri="{CompiledBinding Plugin.Info.Website}">
|
||||
<avalonia:MaterialIcon Kind="Web" />
|
||||
</controls:HyperlinkButton>
|
||||
<controls:HyperlinkButton Classes="icon-button icon-button-large"
|
||||
Margin="5 0"
|
||||
IsVisible="{Binding Plugin.Info.Repository, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
|
||||
NavigateUri="{Binding Plugin.Info.Repository}">
|
||||
IsVisible="{CompiledBinding Plugin.Info.Repository, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
|
||||
NavigateUri="{CompiledBinding Plugin.Info.Repository}">
|
||||
<avalonia:MaterialIcon Kind="Git" />
|
||||
</controls:HyperlinkButton>
|
||||
</StackPanel>
|
||||
@@ -89,28 +91,28 @@
|
||||
<CheckBox Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="Right"
|
||||
IsVisible="{Binding !Enabling}"
|
||||
IsChecked="{Binding IsEnabled}">
|
||||
IsVisible="{CompiledBinding !Enabling}"
|
||||
IsChecked="{CompiledBinding IsEnabled}">
|
||||
<StackPanel x:Name="EnableText" Orientation="Horizontal">
|
||||
<TextBlock>Plugin enabled</TextBlock>
|
||||
<avalonia:MaterialIcon Kind="ShieldHalfFull"
|
||||
Margin="5 0 0 0"
|
||||
ToolTip.Tip="Plugin requires admin rights"
|
||||
IsVisible="{Binding Plugin.Info.RequiresAdmin}" />
|
||||
IsVisible="{CompiledBinding Plugin.Info.RequiresAdmin}" />
|
||||
</StackPanel>
|
||||
</CheckBox>
|
||||
|
||||
<ProgressBar Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="Right"
|
||||
IsVisible="{Binding Enabling}"
|
||||
IsVisible="{CompiledBinding Enabling}"
|
||||
IsIndeterminate="True" />
|
||||
</Grid>
|
||||
|
||||
<Border Grid.Column="1" Grid.Row="0" Grid.RowSpan="2" BorderBrush="{DynamicResource ButtonBorderBrush}" BorderThickness="1 0 0 0" Margin="10 0 0 0" Padding="10 0 0 0">
|
||||
<Grid RowDefinitions="Auto,*">
|
||||
<TextBlock Classes="h5">Plugin features</TextBlock>
|
||||
<ListBox Grid.Row="1" MaxHeight="135" Items="{Binding PluginFeatures}" />
|
||||
<ListBox Grid.Row="1" MaxHeight="135" Items="{CompiledBinding PluginFeatures}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
@@ -49,13 +49,16 @@ namespace Artemis.UI.Screens.Plugins
|
||||
PluginFeatures = new ObservableCollection<PluginFeatureViewModel>();
|
||||
foreach (PluginFeatureInfo pluginFeatureInfo in Plugin.Features)
|
||||
PluginFeatures.Add(_settingsVmFactory.CreatePluginFeatureViewModel(pluginFeatureInfo, false));
|
||||
|
||||
|
||||
|
||||
Reload = ReactiveCommand.CreateFromTask(ExecuteReload);
|
||||
OpenSettings = ReactiveCommand.Create(ExecuteOpenSettings, this.WhenAnyValue(x => x.IsEnabled).Select(isEnabled => isEnabled && Plugin.ConfigurationDialog != null));
|
||||
RemoveSettings = ReactiveCommand.CreateFromTask(ExecuteRemoveSettings);
|
||||
Remove = ReactiveCommand.CreateFromTask(ExecuteRemove);
|
||||
InstallPrerequisites = ReactiveCommand.CreateFromTask(ExecuteInstallPrerequisites, this.WhenAnyValue(x => x.CanInstallPrerequisites));
|
||||
RemovePrerequisites = ReactiveCommand.CreateFromTask<bool>(ExecuteRemovePrerequisites, this.WhenAnyValue(x => x.CanRemovePrerequisites));
|
||||
|
||||
ShowLogsFolder = ReactiveCommand.Create(ExecuteShowLogsFolder);
|
||||
OpenPluginDirectory = ReactiveCommand.Create(ExecuteOpenPluginDirectory);
|
||||
|
||||
this.WhenActivated(d =>
|
||||
{
|
||||
_pluginManagementService.PluginDisabled += PluginManagementServiceOnPluginToggled;
|
||||
@@ -69,10 +72,15 @@ namespace Artemis.UI.Screens.Plugins
|
||||
});
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit,Unit> Reload { get; }
|
||||
public ReactiveCommand<Unit, Unit> OpenSettings { get; }
|
||||
public ReactiveCommand<Unit,Unit> RemoveSettings { get; }
|
||||
public ReactiveCommand<Unit,Unit> Remove { get;}
|
||||
public ReactiveCommand<Unit, Unit> InstallPrerequisites { get; }
|
||||
public ReactiveCommand<bool, Unit> RemovePrerequisites { get; }
|
||||
|
||||
public ReactiveCommand<Unit,Unit> ShowLogsFolder { get; }
|
||||
public ReactiveCommand<Unit,Unit> OpenPluginDirectory { get; }
|
||||
|
||||
public ObservableCollection<PluginFeatureViewModel> PluginFeatures { get; }
|
||||
|
||||
public Plugin Plugin
|
||||
@@ -137,7 +145,7 @@ namespace Artemis.UI.Screens.Plugins
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenPluginDirectory()
|
||||
private void ExecuteOpenPluginDirectory()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -149,7 +157,7 @@ namespace Artemis.UI.Screens.Plugins
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Reload()
|
||||
private async Task ExecuteReload()
|
||||
{
|
||||
bool wasEnabled = IsEnabled;
|
||||
|
||||
@@ -167,28 +175,28 @@ namespace Artemis.UI.Screens.Plugins
|
||||
_notificationService.CreateNotification().WithTitle("Reloaded plugin.").Show();
|
||||
}
|
||||
|
||||
public async Task ExecuteInstallPrerequisites()
|
||||
private async Task ExecuteInstallPrerequisites()
|
||||
{
|
||||
List<IPrerequisitesSubject> subjects = new() {Plugin.Info};
|
||||
subjects.AddRange(Plugin.Features.Where(f => f.AlwaysEnabled));
|
||||
|
||||
if (subjects.Any(s => s.Prerequisites.Any()))
|
||||
if (subjects.Any(s => s.PlatformPrerequisites.Any()))
|
||||
await PluginPrerequisitesInstallDialogViewModel.Show(_windowService, subjects);
|
||||
}
|
||||
|
||||
public async Task ExecuteRemovePrerequisites(bool forPluginRemoval = false)
|
||||
private async Task ExecuteRemovePrerequisites(bool forPluginRemoval = false)
|
||||
{
|
||||
List<IPrerequisitesSubject> subjects = new() {Plugin.Info};
|
||||
subjects.AddRange(!forPluginRemoval ? Plugin.Features.Where(f => f.AlwaysEnabled) : Plugin.Features);
|
||||
|
||||
if (subjects.Any(s => s.Prerequisites.Any(p => p.UninstallActions.Any())))
|
||||
if (subjects.Any(s => s.PlatformPrerequisites.Any(p => p.UninstallActions.Any())))
|
||||
{
|
||||
await PluginPrerequisitesUninstallDialogViewModel.Show(_windowService, subjects, forPluginRemoval ? "Skip, remove plugin" : "Cancel");
|
||||
this.RaisePropertyChanged(nameof(IsEnabled));
|
||||
}
|
||||
}
|
||||
|
||||
public async Task RemoveSettings()
|
||||
private async Task ExecuteRemoveSettings()
|
||||
{
|
||||
bool confirmed = await _windowService.ShowConfirmContentDialog("Clear plugin settings", "Are you sure you want to clear the settings of this plugin?");
|
||||
if (!confirmed)
|
||||
@@ -207,7 +215,7 @@ namespace Artemis.UI.Screens.Plugins
|
||||
_notificationService.CreateNotification().WithTitle("Cleared plugin settings.").Show();
|
||||
}
|
||||
|
||||
public async Task Remove()
|
||||
private async Task ExecuteRemove()
|
||||
{
|
||||
bool confirmed = await _windowService.ShowConfirmContentDialog("Remove plugin", "Are you sure you want to remove this plugin?");
|
||||
if (!confirmed)
|
||||
@@ -216,7 +224,7 @@ namespace Artemis.UI.Screens.Plugins
|
||||
// If the plugin or any of its features has uninstall actions, offer to run these
|
||||
List<IPrerequisitesSubject> subjects = new() {Plugin.Info};
|
||||
subjects.AddRange(Plugin.Features);
|
||||
if (subjects.Any(s => s.Prerequisites.Any(p => p.UninstallActions.Any())))
|
||||
if (subjects.Any(s => s.PlatformPrerequisites.Any(p => p.UninstallActions.Any())))
|
||||
await ExecuteRemovePrerequisites(true);
|
||||
|
||||
try
|
||||
@@ -232,7 +240,7 @@ namespace Artemis.UI.Screens.Plugins
|
||||
_notificationService.CreateNotification().WithTitle("Removed plugin.").Show();
|
||||
}
|
||||
|
||||
public void ShowLogsFolder()
|
||||
private void ExecuteShowLogsFolder()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -244,11 +252,6 @@ namespace Artemis.UI.Screens.Plugins
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenUri(Uri uri)
|
||||
{
|
||||
Utilities.OpenUrl(uri.ToString());
|
||||
}
|
||||
|
||||
private void PluginManagementServiceOnPluginToggled(object? sender, PluginEventArgs e)
|
||||
{
|
||||
this.RaisePropertyChanged(nameof(IsEnabled));
|
||||
@@ -300,7 +303,7 @@ namespace Artemis.UI.Screens.Plugins
|
||||
{
|
||||
await Dispatcher.UIThread.InvokeAsync(() => _notificationService.CreateNotification()
|
||||
.WithMessage($"Failed to enable plugin {Plugin.Info.Name}\r\n{e.Message}")
|
||||
.HavingButton(b => b.WithText("View logs").WithAction(ShowLogsFolder))
|
||||
.HavingButton(b => b.WithText("View logs").WithCommand(ShowLogsFolder))
|
||||
.Show());
|
||||
}
|
||||
finally
|
||||
@@ -325,10 +328,10 @@ namespace Artemis.UI.Screens.Plugins
|
||||
|
||||
private void CheckPrerequisites()
|
||||
{
|
||||
CanInstallPrerequisites = Plugin.Info.Prerequisites.Any() ||
|
||||
Plugin.Features.Where(f => f.AlwaysEnabled).Any(f => f.Prerequisites.Any());
|
||||
CanRemovePrerequisites = Plugin.Info.Prerequisites.Any(p => p.UninstallActions.Any()) ||
|
||||
Plugin.Features.Where(f => f.AlwaysEnabled).Any(f => f.Prerequisites.Any(p => p.UninstallActions.Any()));
|
||||
CanInstallPrerequisites = Plugin.Info.PlatformPrerequisites.Any() ||
|
||||
Plugin.Features.Where(f => f.AlwaysEnabled).Any(f => f.PlatformPrerequisites.Any());
|
||||
CanRemovePrerequisites = Plugin.Info.PlatformPrerequisites.Any(p => p.UninstallActions.Any()) ||
|
||||
Plugin.Features.Where(f => f.AlwaysEnabled).Any(f => f.PlatformPrerequisites.Any(p => p.UninstallActions.Any()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@
|
||||
<avalonia:MaterialIcon Kind="Settings" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="_View Scripts" Command="{Binding ViewScripts}">
|
||||
<MenuItem Header="_View Scripts" Command="{CompiledBinding ViewScripts}">
|
||||
<MenuItem.Icon>
|
||||
<avalonia:MaterialIcon Kind="BookEdit" />
|
||||
</MenuItem.Icon>
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Screens.Scripting;
|
||||
using Artemis.UI.Screens.Sidebar;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
@@ -54,6 +55,7 @@ public class MenuBarViewModel : ActivatableViewModelBase
|
||||
AddFolder = ReactiveCommand.Create(ExecuteAddFolder);
|
||||
AddLayer = ReactiveCommand.Create(ExecuteAddLayer);
|
||||
ViewProperties = ReactiveCommand.CreateFromTask(ExecuteViewProperties, this.WhenAnyValue(vm => vm.ProfileConfiguration).Select(c => c != null));
|
||||
ViewScripts = ReactiveCommand.CreateFromTask(ExecuteViewScripts, this.WhenAnyValue(vm => vm.ProfileConfiguration).Select(c => c != null));
|
||||
AdaptProfile = ReactiveCommand.CreateFromTask(ExecuteAdaptProfile, this.WhenAnyValue(vm => vm.ProfileConfiguration).Select(c => c != null));
|
||||
ToggleSuspended = ReactiveCommand.Create(ExecuteToggleSuspended, this.WhenAnyValue(vm => vm.ProfileConfiguration).Select(c => c != null));
|
||||
DeleteProfile = ReactiveCommand.CreateFromTask(ExecuteDeleteProfile, this.WhenAnyValue(vm => vm.ProfileConfiguration).Select(c => c != null));
|
||||
@@ -68,6 +70,7 @@ public class MenuBarViewModel : ActivatableViewModelBase
|
||||
public ReactiveCommand<Unit, Unit> AddLayer { get; }
|
||||
public ReactiveCommand<Unit, Unit> ToggleSuspended { get; }
|
||||
public ReactiveCommand<Unit, Unit> ViewProperties { get; }
|
||||
public ReactiveCommand<Unit, Unit> ViewScripts { get; }
|
||||
public ReactiveCommand<Unit, Unit> AdaptProfile { get; }
|
||||
public ReactiveCommand<Unit, Unit> DeleteProfile { get; }
|
||||
public ReactiveCommand<Unit, Unit> ExportProfile { get; }
|
||||
@@ -122,6 +125,14 @@ public class MenuBarViewModel : ActivatableViewModelBase
|
||||
("profileConfiguration", ProfileConfiguration)
|
||||
);
|
||||
}
|
||||
|
||||
private async Task ExecuteViewScripts()
|
||||
{
|
||||
if (ProfileConfiguration?.Profile == null)
|
||||
return;
|
||||
|
||||
await _windowService.ShowDialogAsync<ScriptsDialogViewModel, object?>(("profile", ProfileConfiguration.Profile));
|
||||
}
|
||||
|
||||
private async Task ExecuteAdaptProfile()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:dialogs="clr-namespace:Artemis.UI.Screens.Scripting.Dialogs"
|
||||
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Scripting.Dialogs.ScriptConfigurationCreateView"
|
||||
x:DataType="dialogs:ScriptConfigurationCreateViewModel">
|
||||
<Panel>
|
||||
<StackPanel IsVisible="{CompiledBinding ScriptingProviders.Count}">
|
||||
<TextBlock Classes="label" Margin="0 5">Script name</TextBlock>
|
||||
<TextBox Watermark="Name" Text="{CompiledBinding ScriptName}" />
|
||||
<TextBlock Classes="label" Margin="0 5">Script type</TextBlock>
|
||||
<ComboBox SelectedItem="{CompiledBinding SelectedScriptingProvider}" Items="{CompiledBinding ScriptingProviders}" HorizontalAlignment="Stretch">
|
||||
<ComboBox.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<VirtualizingStackPanel />
|
||||
</ItemsPanelTemplate>
|
||||
</ComboBox.ItemsPanel>
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<shared:ArtemisIcon Icon="{CompiledBinding Info.ResolvedIcon}" Width="16" Height="16" Margin="0 0 5 0" />
|
||||
<TextBlock Text="{CompiledBinding LanguageName}" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
<TextBlock IsVisible="{CompiledBinding !ScriptingProviders.Count}">
|
||||
You don't have any scripting providers installed or enabled, therefore you cannot use scripts.
|
||||
</TextBlock>
|
||||
</Panel>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,19 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Scripting.Dialogs;
|
||||
|
||||
public partial class ScriptConfigurationCreateView : ReactiveUserControl<ScriptConfigurationCreateViewModel>
|
||||
{
|
||||
public ScriptConfigurationCreateView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reactive;
|
||||
using Artemis.Core.ScriptingProviders;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Shared;
|
||||
using FluentAvalonia.UI.Controls;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Validation.Extensions;
|
||||
|
||||
namespace Artemis.UI.Screens.Scripting.Dialogs;
|
||||
|
||||
public class ScriptConfigurationCreateViewModel : ContentDialogViewModelBase
|
||||
{
|
||||
private string? _scriptName;
|
||||
private ScriptingProvider _selectedScriptingProvider;
|
||||
|
||||
public ScriptConfigurationCreateViewModel(IScriptingService scriptingService)
|
||||
{
|
||||
ScriptingProviders = new List<ScriptingProvider>(scriptingService.ScriptingProviders);
|
||||
Submit = ReactiveCommand.Create(ExecuteSubmit, ValidationContext.Valid);
|
||||
_selectedScriptingProvider = ScriptingProviders.First();
|
||||
|
||||
this.ValidationRule(vm => vm.ScriptName, s => !string.IsNullOrWhiteSpace(s), "Script name cannot be empty.");
|
||||
}
|
||||
|
||||
public ScriptConfiguration? ScriptConfiguration { get; private set; }
|
||||
public List<ScriptingProvider> ScriptingProviders { get; }
|
||||
|
||||
public string? ScriptName
|
||||
{
|
||||
get => _scriptName;
|
||||
set => RaiseAndSetIfChanged(ref _scriptName, value);
|
||||
}
|
||||
|
||||
public ScriptingProvider SelectedScriptingProvider
|
||||
{
|
||||
get => _selectedScriptingProvider;
|
||||
set => RaiseAndSetIfChanged(ref _selectedScriptingProvider, value);
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit, Unit> Submit { get; }
|
||||
|
||||
private void ExecuteSubmit()
|
||||
{
|
||||
if (ScriptName == null)
|
||||
return;
|
||||
|
||||
ScriptConfiguration = new ScriptConfiguration(SelectedScriptingProvider, ScriptName, ScriptType.Profile);
|
||||
ContentDialog?.Hide(ContentDialogResult.Primary);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:dialogs="clr-namespace:Artemis.UI.Screens.Scripting.Dialogs"
|
||||
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Scripting.Dialogs.ScriptConfigurationEditView"
|
||||
x:DataType="dialogs:ScriptConfigurationEditViewModel">
|
||||
<TextBox Watermark="Name" Name="Input" Text="{CompiledBinding ScriptName}" />
|
||||
</UserControl>
|
||||
@@ -0,0 +1,25 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Scripting.Dialogs;
|
||||
|
||||
public partial class ScriptConfigurationEditView : ReactiveUserControl<ScriptConfigurationEditViewModel>
|
||||
{
|
||||
public ScriptConfigurationEditView()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.WhenActivated(_ =>
|
||||
{
|
||||
this.Get<TextBox>("Input").Focus();
|
||||
this.Get<TextBox>("Input").SelectAll();
|
||||
});
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using System.Reactive;
|
||||
using Artemis.Core.ScriptingProviders;
|
||||
using Artemis.UI.Shared;
|
||||
using FluentAvalonia.UI.Controls;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Validation.Extensions;
|
||||
|
||||
namespace Artemis.UI.Screens.Scripting.Dialogs;
|
||||
|
||||
public class ScriptConfigurationEditViewModel : ContentDialogViewModelBase
|
||||
{
|
||||
private string? _scriptName;
|
||||
|
||||
public ScriptConfigurationEditViewModel(ScriptConfiguration scriptConfiguration)
|
||||
{
|
||||
ScriptConfiguration = scriptConfiguration;
|
||||
Submit = ReactiveCommand.Create(ExecuteSubmit, ValidationContext.Valid);
|
||||
ScriptName = ScriptConfiguration.Name;
|
||||
|
||||
this.ValidationRule(vm => vm.ScriptName, s => !string.IsNullOrWhiteSpace(s), "Script name cannot be empty.");
|
||||
}
|
||||
|
||||
public ScriptConfiguration ScriptConfiguration { get; }
|
||||
public ReactiveCommand<Unit, Unit> Submit { get; }
|
||||
|
||||
public string? ScriptName
|
||||
{
|
||||
get => _scriptName;
|
||||
set => RaiseAndSetIfChanged(ref _scriptName, value);
|
||||
}
|
||||
|
||||
private void ExecuteSubmit()
|
||||
{
|
||||
if (ScriptName == null)
|
||||
return;
|
||||
|
||||
ScriptConfiguration.Name = ScriptName;
|
||||
ContentDialog?.Hide(ContentDialogResult.Primary);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using System.Reactive;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.ScriptingProviders;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Screens.Scripting.Dialogs;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using FluentAvalonia.UI.Controls;
|
||||
using ReactiveUI;
|
||||
using ContentDialogButton = Artemis.UI.Shared.Services.Builders.ContentDialogButton;
|
||||
|
||||
namespace Artemis.UI.Screens.Scripting;
|
||||
|
||||
public class ScriptConfigurationViewModel : ActivatableViewModelBase
|
||||
{
|
||||
private readonly IScriptingService _scriptingService;
|
||||
private readonly IWindowService _windowService;
|
||||
|
||||
public ScriptConfigurationViewModel(ScriptConfiguration scriptConfiguration, IScriptingService scriptingService, IWindowService windowService)
|
||||
{
|
||||
_scriptingService = scriptingService;
|
||||
_windowService = windowService;
|
||||
|
||||
ScriptConfiguration = scriptConfiguration;
|
||||
Script = ScriptConfiguration.Script;
|
||||
EditScriptConfiguration = ReactiveCommand.CreateFromTask<ScriptConfiguration>(ExecuteEditScriptConfiguration);
|
||||
ToggleSuspended = ReactiveCommand.Create(() => ScriptConfiguration.IsSuspended = !ScriptConfiguration.IsSuspended);
|
||||
}
|
||||
|
||||
public ScriptConfigurationViewModel(Profile profile, ScriptConfiguration scriptConfiguration, IScriptingService scriptingService, IWindowService windowService)
|
||||
: this(scriptConfiguration, scriptingService, windowService)
|
||||
{
|
||||
Profile = profile;
|
||||
}
|
||||
|
||||
public Profile? Profile { get; }
|
||||
public ScriptConfiguration ScriptConfiguration { get; }
|
||||
public Script? Script { get; }
|
||||
public ReactiveCommand<ScriptConfiguration, Unit> EditScriptConfiguration { get; }
|
||||
public ReactiveCommand<Unit, bool> ToggleSuspended { get; }
|
||||
|
||||
private async Task ExecuteEditScriptConfiguration(ScriptConfiguration scriptConfiguration)
|
||||
{
|
||||
ContentDialogResult contentDialogResult = await _windowService.CreateContentDialog()
|
||||
.WithTitle("Edit script")
|
||||
.WithViewModel(out ScriptConfigurationEditViewModel vm, ("scriptConfiguration", scriptConfiguration))
|
||||
.WithCloseButtonText("Cancel")
|
||||
.HavingPrimaryButton(b => b.WithText("Confirm").WithCommand(vm.Submit))
|
||||
.HavingSecondaryButton(b => b.WithText("Delete"))
|
||||
.WithDefaultButton(ContentDialogButton.Primary)
|
||||
.ShowAsync();
|
||||
|
||||
// Remove the script if the delete button was pressed
|
||||
if (contentDialogResult == ContentDialogResult.Secondary)
|
||||
{
|
||||
if (Profile != null)
|
||||
_scriptingService.RemoveScript(scriptConfiguration, Profile);
|
||||
else
|
||||
_scriptingService.RemoveScript(scriptConfiguration);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<controls:CoreWindow xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:controls="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
|
||||
xmlns:scripting="clr-namespace:Artemis.UI.Screens.Scripting"
|
||||
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
||||
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Scripting.ScriptsDialogView"
|
||||
x:DataType="scripting:ScriptsDialogViewModel"
|
||||
Title="ScriptsDialogView">
|
||||
<DockPanel>
|
||||
<ScrollViewer DockPanel.Dock="Left" VerticalScrollBarVisibility="Auto" Width="240">
|
||||
<StackPanel>
|
||||
<ListBox Items="{CompiledBinding ScriptConfigurations}" SelectedItem="{CompiledBinding SelectedScript}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type scripting:ScriptConfigurationViewModel}">
|
||||
<Grid ColumnDefinitions="Auto,*,Auto,Auto" RowDefinitions="*,*" Margin="4">
|
||||
<shared:ArtemisIcon Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Grid.RowSpan="2"
|
||||
Icon="{CompiledBinding ScriptConfiguration.Script.ScriptingProvider.Info.ResolvedIcon, FallbackValue=QuestionMark}"
|
||||
Width="32 "
|
||||
Height="32"
|
||||
Margin="0 0 10 0"
|
||||
VerticalAlignment="Center" />
|
||||
<TextBlock Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
VerticalAlignment="Center"
|
||||
Text="{CompiledBinding ScriptConfiguration.Name}"
|
||||
IsVisible="{CompiledBinding !ScriptConfiguration.HasChanges}" />
|
||||
<StackPanel Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
VerticalAlignment="Center"
|
||||
Orientation="Horizontal"
|
||||
IsVisible="{CompiledBinding ScriptConfiguration.HasChanges}">
|
||||
<TextBlock Text="{CompiledBinding ScriptConfiguration.Name}" FontWeight="Bold"></TextBlock>
|
||||
<TextBlock Text="*"></TextBlock>
|
||||
</StackPanel>
|
||||
<TextBlock Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
Text="{CompiledBinding ScriptConfiguration.Script.ScriptingProvider.LanguageName, FallbackValue='Unknown scripting provider'}"
|
||||
Classes="subtitle"
|
||||
FontSize="11"
|
||||
VerticalAlignment="Center" />
|
||||
|
||||
<Button Classes="icon-button icon-button-small"
|
||||
Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="2"
|
||||
ToolTip.Tip="Edit script"
|
||||
HorizontalAlignment="Right"
|
||||
Command="{CompiledBinding EditScriptConfiguration}"
|
||||
CommandParameter="{CompiledBinding ScriptConfiguration}"
|
||||
Margin="0 0 2 0">
|
||||
<avalonia:MaterialIcon Kind="Cog" />
|
||||
</Button>
|
||||
<Button Classes="icon-button icon-button-small"
|
||||
Command="{CompiledBinding ToggleSuspended}"
|
||||
Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="3"
|
||||
ToolTip.Tip="Suspend/resume script">
|
||||
<Panel>
|
||||
<avalonia:MaterialIcon Kind="EyeOff" IsVisible="{CompiledBinding ScriptConfiguration.IsSuspended}" />
|
||||
<avalonia:MaterialIcon Kind="Eye" IsVisible="{CompiledBinding !ScriptConfiguration.IsSuspended}" />
|
||||
</Panel>
|
||||
</Button>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<Button Content="Add new script"
|
||||
Margin="10"
|
||||
HorizontalAlignment="Stretch"
|
||||
Command="{CompiledBinding AddScriptConfiguration}" />
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
|
||||
<Border DockPanel.Dock="Top" Classes="router-container">
|
||||
<ContentControl Content="{CompiledBinding ScriptEditorViewModel}" />
|
||||
</Border>
|
||||
</DockPanel>
|
||||
|
||||
</controls:CoreWindow>
|
||||
@@ -0,0 +1,21 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Artemis.UI.Screens.Scripting;
|
||||
|
||||
public partial class ScriptsDialogView : ReactiveCoreWindow<ScriptsDialogViewModel>
|
||||
{
|
||||
public ScriptsDialogView()
|
||||
{
|
||||
InitializeComponent();
|
||||
#if DEBUG
|
||||
this.AttachDevTools();
|
||||
#endif
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.ScriptingProviders;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Screens.Scripting.Dialogs;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using DynamicData;
|
||||
using DynamicData.Binding;
|
||||
using FluentAvalonia.UI.Controls;
|
||||
using ReactiveUI;
|
||||
using ContentDialogButton = Artemis.UI.Shared.Services.Builders.ContentDialogButton;
|
||||
|
||||
namespace Artemis.UI.Screens.Scripting;
|
||||
|
||||
public class ScriptsDialogViewModel : DialogViewModelBase<object?>
|
||||
{
|
||||
private readonly IScriptingService _scriptingService;
|
||||
private readonly IWindowService _windowService;
|
||||
private readonly Dictionary<ScriptingProvider, IScriptEditorViewModel> _providerViewModels = new();
|
||||
private ObservableAsPropertyHelper<bool>? _hasScripts;
|
||||
private ScriptConfigurationViewModel? _selectedScript;
|
||||
private IScriptEditorViewModel? _scriptEditorViewModel;
|
||||
private ReadOnlyObservableCollection<ScriptConfigurationViewModel> _scriptConfigurations;
|
||||
|
||||
public ScriptsDialogViewModel(IScriptingService scriptingService, IWindowService windowService, IProfileService profileService, IScriptVmFactory scriptVmFactory)
|
||||
{
|
||||
_scriptingService = scriptingService;
|
||||
_windowService = windowService;
|
||||
|
||||
ScriptType = ScriptType.Global;
|
||||
ScriptingProviders = new List<ScriptingProvider>(scriptingService.ScriptingProviders);
|
||||
|
||||
AddScriptConfiguration = ReactiveCommand.CreateFromTask(ExecuteAddScriptConfiguration, Observable.Return(ScriptingProviders.Any()));
|
||||
this.WhenAnyValue(vm => vm.SelectedScript).Subscribe(s => SetupScriptEditor(s?.ScriptConfiguration));
|
||||
|
||||
// TODO: When not bound to a profile, base the contents of the UI on the ScriptingService
|
||||
}
|
||||
|
||||
public ScriptsDialogViewModel(Profile profile, IScriptingService scriptingService, IWindowService windowService, IProfileService profileService, IScriptVmFactory scriptVmFactory)
|
||||
: this(scriptingService, windowService, profileService, scriptVmFactory)
|
||||
{
|
||||
ScriptType = ScriptType.Profile;
|
||||
Profile = profile;
|
||||
|
||||
this.WhenActivated(d =>
|
||||
{
|
||||
_hasScripts = Profile.ScriptConfigurations.ToObservableChangeSet()
|
||||
.Count()
|
||||
.Select(c => c > 0)
|
||||
.ToProperty(this, vm => vm.HasScripts)
|
||||
.DisposeWith(d);
|
||||
Profile.ScriptConfigurations.ToObservableChangeSet()
|
||||
.Transform(c => scriptVmFactory.ScriptConfigurationViewModel(Profile, c))
|
||||
.Bind(out ReadOnlyObservableCollection<ScriptConfigurationViewModel> scriptConfigurationViewModels)
|
||||
.Subscribe()
|
||||
.DisposeWith(d);
|
||||
|
||||
ScriptConfigurations = scriptConfigurationViewModels;
|
||||
SelectedScript = ScriptConfigurations.FirstOrDefault();
|
||||
Disposable.Create(() => profileService.SaveProfile(Profile, false)).DisposeWith(d);
|
||||
});
|
||||
}
|
||||
|
||||
public ScriptType ScriptType { get; }
|
||||
public List<ScriptingProvider> ScriptingProviders { get; }
|
||||
public Profile? Profile { get; }
|
||||
public bool HasScripts => _hasScripts?.Value ?? false;
|
||||
|
||||
public ReadOnlyObservableCollection<ScriptConfigurationViewModel> ScriptConfigurations
|
||||
{
|
||||
get => _scriptConfigurations;
|
||||
set => RaiseAndSetIfChanged(ref _scriptConfigurations, value);
|
||||
}
|
||||
|
||||
public ScriptConfigurationViewModel? SelectedScript
|
||||
{
|
||||
get => _selectedScript;
|
||||
set => RaiseAndSetIfChanged(ref _selectedScript, value);
|
||||
}
|
||||
|
||||
public IScriptEditorViewModel? ScriptEditorViewModel
|
||||
{
|
||||
get => _scriptEditorViewModel;
|
||||
set => RaiseAndSetIfChanged(ref _scriptEditorViewModel, value);
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit, Unit> AddScriptConfiguration { get; }
|
||||
|
||||
|
||||
private void SetupScriptEditor(ScriptConfiguration? scriptConfiguration)
|
||||
{
|
||||
if (scriptConfiguration == null)
|
||||
{
|
||||
ScriptEditorViewModel = null;
|
||||
return;
|
||||
}
|
||||
|
||||
// The script is null if the provider is missing
|
||||
if (scriptConfiguration.Script == null)
|
||||
{
|
||||
ScriptEditorViewModel = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_providerViewModels.TryGetValue(scriptConfiguration.Script.ScriptingProvider, out IScriptEditorViewModel? viewModel))
|
||||
{
|
||||
viewModel = scriptConfiguration.Script.ScriptingProvider.CreateScriptEditor(ScriptType);
|
||||
_providerViewModels.Add(scriptConfiguration.Script.ScriptingProvider, viewModel);
|
||||
}
|
||||
|
||||
ScriptEditorViewModel = viewModel;
|
||||
ScriptEditorViewModel.ChangeScript(scriptConfiguration.Script);
|
||||
}
|
||||
|
||||
private async Task ExecuteAddScriptConfiguration()
|
||||
{
|
||||
await _windowService.CreateContentDialog()
|
||||
.WithTitle("Add script")
|
||||
.WithViewModel(out ScriptConfigurationCreateViewModel vm)
|
||||
.WithCloseButtonText("Cancel")
|
||||
.HavingPrimaryButton(b => b.WithText("Confirm").WithCommand(vm.Submit))
|
||||
.WithDefaultButton(ContentDialogButton.Primary)
|
||||
.ShowAsync();
|
||||
|
||||
if (vm.ScriptConfiguration == null)
|
||||
return;
|
||||
|
||||
// Add the script to the profile and instantiate it
|
||||
if (Profile != null)
|
||||
_scriptingService.AddScript(vm.ScriptConfiguration, Profile);
|
||||
else
|
||||
_scriptingService.AddScript(vm.ScriptConfiguration);
|
||||
|
||||
// Select the new script
|
||||
SelectedScript = ScriptConfigurations.LastOrDefault();
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,6 @@ using Artemis.UI.Shared;
|
||||
using Avalonia;
|
||||
using DynamicData;
|
||||
using FluentAvalonia.Styling;
|
||||
using Ninject;
|
||||
using ReactiveUI;
|
||||
using Serilog.Events;
|
||||
|
||||
@@ -28,7 +27,7 @@ namespace Artemis.UI.Screens.Settings
|
||||
private readonly IDebugService _debugService;
|
||||
private readonly FluentAvaloniaTheme _fluentAvaloniaTheme;
|
||||
|
||||
public GeneralTabViewModel(IKernel kernel, ISettingsService settingsService, IPluginManagementService pluginManagementService, IDebugService debugService)
|
||||
public GeneralTabViewModel(ISettingsService settingsService, IPluginManagementService pluginManagementService, IDebugService debugService, IGraphicsContextProvider? graphicsContextProvider = null)
|
||||
{
|
||||
DisplayName = "General";
|
||||
_settingsService = settingsService;
|
||||
@@ -38,7 +37,6 @@ namespace Artemis.UI.Screens.Settings
|
||||
List<LayerBrushProvider> layerBrushProviders = pluginManagementService.GetFeaturesOfType<LayerBrushProvider>();
|
||||
LayerBrushDescriptors = new ObservableCollection<LayerBrushDescriptor>(layerBrushProviders.SelectMany(l => l.LayerBrushDescriptors));
|
||||
GraphicsContexts = new ObservableCollection<string> {"Software"};
|
||||
IGraphicsContextProvider? graphicsContextProvider = kernel.TryGet<IGraphicsContextProvider>();
|
||||
if (graphicsContextProvider != null)
|
||||
GraphicsContexts.AddRange(graphicsContextProvider.GraphicsContextNames);
|
||||
|
||||
|
||||
Reference in new issue
Block a user