mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Workshop - Implemented workshop installation, layout selection and removal
This commit is contained in:
1 parent
dad6a56238
commit
28edabae89
23 files changed
+226
-168
No files matched your search
@@ -1,6 +1,7 @@
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Providers;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Artemis.UI.Shared.Services.Builders;
|
||||
@@ -11,11 +12,12 @@ public class CustomLayoutViewModel : ViewModelBase, ILayoutProviderViewModel
|
||||
{
|
||||
private readonly CustomPathLayoutProvider _layoutProvider;
|
||||
|
||||
public CustomLayoutViewModel(IWindowService windowService, INotificationService notificationService, CustomPathLayoutProvider layoutProvider)
|
||||
public CustomLayoutViewModel(IWindowService windowService, INotificationService notificationService, IDeviceService deviceService, CustomPathLayoutProvider layoutProvider)
|
||||
{
|
||||
_layoutProvider = layoutProvider;
|
||||
_windowService = windowService;
|
||||
_notificationService = notificationService;
|
||||
_deviceService = deviceService;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -32,11 +34,13 @@ public class CustomLayoutViewModel : ViewModelBase, ILayoutProviderViewModel
|
||||
private readonly IWindowService _windowService;
|
||||
|
||||
private readonly INotificationService _notificationService;
|
||||
private readonly IDeviceService _deviceService;
|
||||
|
||||
public void ClearCustomLayout()
|
||||
{
|
||||
_layoutProvider.ConfigureDevice(Device, null);
|
||||
|
||||
Save();
|
||||
|
||||
_notificationService.CreateNotification()
|
||||
.WithMessage("Cleared imported layout.")
|
||||
.WithSeverity(NotificationSeverity.Informational);
|
||||
@@ -52,7 +56,8 @@ public class CustomLayoutViewModel : ViewModelBase, ILayoutProviderViewModel
|
||||
if (files?.Length > 0)
|
||||
{
|
||||
_layoutProvider.ConfigureDevice(Device, files[0]);
|
||||
|
||||
Save();
|
||||
|
||||
_notificationService.CreateNotification()
|
||||
.WithTitle("Imported layout")
|
||||
.WithMessage($"File loaded from {files[0]}")
|
||||
@@ -64,5 +69,12 @@ public class CustomLayoutViewModel : ViewModelBase, ILayoutProviderViewModel
|
||||
public void Apply()
|
||||
{
|
||||
_layoutProvider.ConfigureDevice(Device, null);
|
||||
Save();
|
||||
}
|
||||
|
||||
private void Save()
|
||||
{
|
||||
_deviceService.SaveDevice(Device);
|
||||
_deviceService.LoadDeviceLayout(Device);
|
||||
}
|
||||
}
|
||||
+11
-1
@@ -1,5 +1,6 @@
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Providers;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Shared;
|
||||
|
||||
namespace Artemis.UI.Screens.Device.Layout.LayoutProviders;
|
||||
@@ -7,10 +8,12 @@ namespace Artemis.UI.Screens.Device.Layout.LayoutProviders;
|
||||
public class DefaultLayoutViewModel : ViewModelBase, ILayoutProviderViewModel
|
||||
{
|
||||
private readonly DefaultLayoutProvider _layoutProvider;
|
||||
private readonly IDeviceService _deviceService;
|
||||
|
||||
public DefaultLayoutViewModel(DefaultLayoutProvider layoutProvider)
|
||||
public DefaultLayoutViewModel(DefaultLayoutProvider layoutProvider, IDeviceService deviceService)
|
||||
{
|
||||
_layoutProvider = layoutProvider;
|
||||
_deviceService = deviceService;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -28,5 +31,12 @@ public class DefaultLayoutViewModel : ViewModelBase, ILayoutProviderViewModel
|
||||
public void Apply()
|
||||
{
|
||||
_layoutProvider.ConfigureDevice(Device);
|
||||
Save();
|
||||
}
|
||||
|
||||
private void Save()
|
||||
{
|
||||
_deviceService.SaveDevice(Device);
|
||||
_deviceService.LoadDeviceLayout(Device);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Providers;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Shared;
|
||||
|
||||
namespace Artemis.UI.Screens.Device.Layout.LayoutProviders;
|
||||
@@ -7,10 +8,12 @@ namespace Artemis.UI.Screens.Device.Layout.LayoutProviders;
|
||||
public class NoneLayoutViewModel : ViewModelBase, ILayoutProviderViewModel
|
||||
{
|
||||
private readonly NoneLayoutProvider _layoutProvider;
|
||||
private readonly IDeviceService _deviceService;
|
||||
|
||||
public NoneLayoutViewModel(NoneLayoutProvider layoutProvider)
|
||||
public NoneLayoutViewModel(NoneLayoutProvider layoutProvider, IDeviceService deviceService)
|
||||
{
|
||||
_layoutProvider = layoutProvider;
|
||||
_deviceService = deviceService;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -28,5 +31,12 @@ public class NoneLayoutViewModel : ViewModelBase, ILayoutProviderViewModel
|
||||
public void Apply()
|
||||
{
|
||||
_layoutProvider.ConfigureDevice(Device);
|
||||
Save();
|
||||
}
|
||||
|
||||
private void Save()
|
||||
{
|
||||
_deviceService.SaveDevice(Device);
|
||||
_deviceService.LoadDeviceLayout(Device);
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,45 @@
|
||||
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:services="clr-namespace:Artemis.WebClient.Workshop.Services;assembly=Artemis.WebClient.Workshop"
|
||||
xmlns:layoutProviders="clr-namespace:Artemis.UI.Screens.Device.Layout.LayoutProviders"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Device.Layout.LayoutProviders.WorkshopLayoutView">
|
||||
x:Class="Artemis.UI.Screens.Device.Layout.LayoutProviders.WorkshopLayoutView"
|
||||
x:DataType="layoutProviders:WorkshopLayoutViewModel">
|
||||
<StackPanel ClipToBounds="False">
|
||||
<Border Classes="card-separator" />
|
||||
<StackPanel>
|
||||
<TextBlock Text="Current layout" />
|
||||
<TextBlock Classes="subtitle" FontSize="12" Text="Loading the layout from a workshop entry" TextWrapping="Wrap" />
|
||||
</StackPanel>
|
||||
<Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
|
||||
<StackPanel Grid.Row="1" Grid.Column="0">
|
||||
<TextBlock Text="Current layout" />
|
||||
<TextBlock Classes="subtitle" FontSize="12" Text="Loading the layout from a workshop entry" TextWrapping="Wrap" />
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Row="1" Grid.Column="1" VerticalAlignment="Center">
|
||||
<StackPanel.Styles>
|
||||
<Style Selector="ComboBox.layoutProvider /template/ ContentControl#ContentPresenter">
|
||||
<Setter Property="ContentTemplate">
|
||||
<Setter.Value>
|
||||
<DataTemplate x:DataType="services:InstalledEntry">
|
||||
<TextBlock Text="{CompiledBinding Name}" TextWrapping="Wrap" MaxWidth="350" />
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</StackPanel.Styles>
|
||||
<ComboBox Classes="layoutProvider"
|
||||
Width="350"
|
||||
SelectedItem="{CompiledBinding SelectedEntry}"
|
||||
ItemsSource="{CompiledBinding Entries}"
|
||||
PlaceholderText="Select an installed layout">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate x:DataType="services:InstalledEntry">
|
||||
<StackPanel>
|
||||
<TextBlock Text="{CompiledBinding Name}" TextWrapping="Wrap" MaxWidth="350" />
|
||||
<TextBlock Classes="subtitle" Text="{CompiledBinding Author}" TextWrapping="Wrap" MaxWidth="350" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Device.Layout.LayoutProviders;
|
||||
|
||||
public partial class WorkshopLayoutView : UserControl
|
||||
public partial class WorkshopLayoutView : ReactiveUserControl<WorkshopLayoutViewModel>
|
||||
{
|
||||
public WorkshopLayoutView()
|
||||
{
|
||||
|
||||
+37
-4
@@ -1,17 +1,33 @@
|
||||
using Artemis.Core;
|
||||
using System.Collections.ObjectModel;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reactive.Disposables;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Providers;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.WebClient.Workshop;
|
||||
using Artemis.WebClient.Workshop.Providers;
|
||||
using Artemis.WebClient.Workshop.Services;
|
||||
using PropertyChanged.SourceGenerator;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Device.Layout.LayoutProviders;
|
||||
|
||||
public class WorkshopLayoutViewModel : ViewModelBase, ILayoutProviderViewModel
|
||||
public partial class WorkshopLayoutViewModel : ActivatableViewModelBase, ILayoutProviderViewModel
|
||||
{
|
||||
[Notify] private InstalledEntry? _selectedEntry;
|
||||
private readonly WorkshopLayoutProvider _layoutProvider;
|
||||
private readonly IDeviceService _deviceService;
|
||||
|
||||
public WorkshopLayoutViewModel(WorkshopLayoutProvider layoutProvider)
|
||||
public WorkshopLayoutViewModel(WorkshopLayoutProvider layoutProvider, IWorkshopService workshopService, IDeviceService deviceService)
|
||||
{
|
||||
_layoutProvider = layoutProvider;
|
||||
_deviceService = deviceService;
|
||||
Entries = new ObservableCollection<InstalledEntry>(workshopService.GetInstalledEntries().Where(e => e.EntryType == EntryType.Layout));
|
||||
|
||||
this.WhenAnyValue(vm => vm.SelectedEntry).Subscribe(ApplyEntry);
|
||||
this.WhenActivated((CompositeDisposable _) => SelectedEntry = Entries.FirstOrDefault(e => e.EntryId.ToString() == Device.LayoutSelection.Parameter));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -19,6 +35,8 @@ public class WorkshopLayoutViewModel : ViewModelBase, ILayoutProviderViewModel
|
||||
|
||||
public ArtemisDevice Device { get; set; } = null!;
|
||||
|
||||
public ObservableCollection<InstalledEntry> Entries { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Name => "Workshop";
|
||||
|
||||
@@ -28,6 +46,21 @@ public class WorkshopLayoutViewModel : ViewModelBase, ILayoutProviderViewModel
|
||||
/// <inheritdoc />
|
||||
public void Apply()
|
||||
{
|
||||
_layoutProvider.ConfigureDevice(Device);
|
||||
_layoutProvider.ConfigureDevice(Device, null);
|
||||
Save();
|
||||
}
|
||||
|
||||
private void ApplyEntry(InstalledEntry? entry)
|
||||
{
|
||||
if (entry == null || Device.LayoutSelection.Parameter == entry.EntryId.ToString())
|
||||
return;
|
||||
_layoutProvider.ConfigureDevice(Device, entry);
|
||||
Save();
|
||||
}
|
||||
|
||||
private void Save()
|
||||
{
|
||||
_deviceService.SaveDevice(Device);
|
||||
_deviceService.LoadDeviceLayout(Device);
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ public class EntryReleasesViewModel : ViewModelBase
|
||||
return;
|
||||
|
||||
IEntryInstallationHandler installationHandler = _factory.CreateHandler(Entry.EntryType);
|
||||
EntryInstallResult result = await installationHandler.InstallAsync(Entry, Entry.LatestRelease.Id, new Progress<StreamProgress>(), cancellationToken);
|
||||
EntryInstallResult result = await installationHandler.InstallAsync(Entry, Entry.LatestRelease, new Progress<StreamProgress>(), cancellationToken);
|
||||
if (result.IsSuccess)
|
||||
_notificationService.CreateNotification().WithTitle($"{Entry.EntryType.Humanize(LetterCasing.Sentence)} installed").WithSeverity(NotificationSeverity.Success).Show();
|
||||
else
|
||||
|
||||
Reference in new issue
Block a user