mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Plugins - Separated VMs into folders
Plugins - Added help pages
This commit is contained in:
1 parent
2f270c9c03
commit
b59e898dd3
29 files changed
+350
-43
No files matched your search
@@ -0,0 +1,22 @@
|
||||
<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:prerequisites="clr-namespace:Artemis.UI.Screens.Plugins.Prerequisites"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Plugins.Prerequisites.PluginPrerequisiteActionView"
|
||||
x:DataType="prerequisites: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,12 @@
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace Artemis.UI.Screens.Plugins.Prerequisites;
|
||||
|
||||
public partial class PluginPrerequisiteActionView : UserControl
|
||||
{
|
||||
public PluginPrerequisiteActionView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Shared;
|
||||
|
||||
namespace Artemis.UI.Screens.Plugins.Prerequisites;
|
||||
|
||||
public class PluginPrerequisiteActionViewModel : ViewModelBase
|
||||
{
|
||||
public PluginPrerequisiteActionViewModel(PluginPrerequisiteAction action)
|
||||
{
|
||||
Action = action;
|
||||
}
|
||||
|
||||
public PluginPrerequisiteAction Action { get; }
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<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:prerequisites="clr-namespace:Artemis.UI.Screens.Plugins.Prerequisites"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Plugins.Prerequisites.PluginPrerequisiteView"
|
||||
x:DataType="prerequisites: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 Classes="subtitle" 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,12 @@
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Plugins.Prerequisites;
|
||||
|
||||
public partial class PluginPrerequisiteView : ReactiveUserControl<PluginPrerequisiteViewModel>
|
||||
{
|
||||
public PluginPrerequisiteView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Shared;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Plugins.Prerequisites;
|
||||
|
||||
public class PluginPrerequisiteViewModel : ActivatableViewModelBase
|
||||
{
|
||||
private readonly ObservableAsPropertyHelper<int> _activeStepNumber;
|
||||
private readonly ObservableAsPropertyHelper<bool> _busy;
|
||||
private readonly bool _uninstall;
|
||||
|
||||
private PluginPrerequisiteActionViewModel? _activeAction;
|
||||
|
||||
private bool _installing;
|
||||
private bool _isMet;
|
||||
private bool _uninstalling;
|
||||
|
||||
public PluginPrerequisiteViewModel(PluginPrerequisite pluginPrerequisite, bool uninstall)
|
||||
{
|
||||
_uninstall = uninstall;
|
||||
|
||||
PluginPrerequisite = pluginPrerequisite;
|
||||
Actions = new ObservableCollection<PluginPrerequisiteActionViewModel>(!_uninstall
|
||||
? PluginPrerequisite.InstallActions.Select(a => new PluginPrerequisiteActionViewModel(a))
|
||||
: PluginPrerequisite.UninstallActions.Select(a => new PluginPrerequisiteActionViewModel(a)));
|
||||
|
||||
_busy = this.WhenAnyValue(x => x.Installing, x => x.Uninstalling, (i, u) => i || u).ToProperty(this, x => x.Busy);
|
||||
_activeStepNumber = this.WhenAnyValue(x => x.ActiveAction, a => Actions.IndexOf(a!) + 1).ToProperty(this, x => x.ActiveStepNumber);
|
||||
|
||||
this.WhenActivated(d =>
|
||||
{
|
||||
PluginPrerequisite.PropertyChanged += PluginPrerequisiteOnPropertyChanged;
|
||||
Disposable.Create(() => PluginPrerequisite.PropertyChanged -= PluginPrerequisiteOnPropertyChanged).DisposeWith(d);
|
||||
});
|
||||
|
||||
// Could be slow so take it off of the UI thread
|
||||
Task.Run(() => IsMet = PluginPrerequisite.IsMet());
|
||||
}
|
||||
|
||||
public ObservableCollection<PluginPrerequisiteActionViewModel> Actions { get; }
|
||||
|
||||
public PluginPrerequisiteActionViewModel? ActiveAction
|
||||
{
|
||||
get => _activeAction;
|
||||
set => RaiseAndSetIfChanged(ref _activeAction, value);
|
||||
}
|
||||
|
||||
public PluginPrerequisite PluginPrerequisite { get; }
|
||||
|
||||
public bool Installing
|
||||
{
|
||||
get => _installing;
|
||||
set => RaiseAndSetIfChanged(ref _installing, value);
|
||||
}
|
||||
|
||||
public bool Uninstalling
|
||||
{
|
||||
get => _uninstalling;
|
||||
set => RaiseAndSetIfChanged(ref _uninstalling, value);
|
||||
}
|
||||
|
||||
public bool IsMet
|
||||
{
|
||||
get => _isMet;
|
||||
set => RaiseAndSetIfChanged(ref _isMet, value);
|
||||
}
|
||||
|
||||
public bool Busy => _busy.Value;
|
||||
public int ActiveStepNumber => _activeStepNumber.Value;
|
||||
|
||||
public async Task Install(CancellationToken cancellationToken)
|
||||
{
|
||||
if (Busy)
|
||||
return;
|
||||
|
||||
Installing = true;
|
||||
try
|
||||
{
|
||||
await PluginPrerequisite.Install(cancellationToken);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Installing = false;
|
||||
IsMet = PluginPrerequisite.IsMet();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Uninstall(CancellationToken cancellationToken)
|
||||
{
|
||||
if (Busy)
|
||||
return;
|
||||
|
||||
Uninstalling = true;
|
||||
try
|
||||
{
|
||||
await PluginPrerequisite.Uninstall(cancellationToken);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Uninstalling = false;
|
||||
IsMet = PluginPrerequisite.IsMet();
|
||||
}
|
||||
}
|
||||
|
||||
private void PluginPrerequisiteOnPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(PluginPrerequisite.CurrentAction))
|
||||
ActivateCurrentAction();
|
||||
}
|
||||
|
||||
private void ActivateCurrentAction()
|
||||
{
|
||||
PluginPrerequisiteActionViewModel? activeAction = Actions.FirstOrDefault(i => i.Action == PluginPrerequisite.CurrentAction);
|
||||
if (activeAction == null)
|
||||
return;
|
||||
|
||||
ActiveAction = activeAction;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user