mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
More UI tests, remove the custom message bus
This commit is contained in:
parent
4c8b1b8ecb
commit
1164cf61f3
31
Wabbajack.App.Test/AvaloniaApp.cs
Normal file
31
Wabbajack.App.Test/AvaloniaApp.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Headless;
|
||||
using Avalonia.ReactiveUI;
|
||||
using Avalonia.Threading;
|
||||
using Wabbajack.App.Views;
|
||||
|
||||
namespace Wabbajack.App.Test;
|
||||
|
||||
public static class AvaloniaApp
|
||||
{
|
||||
|
||||
public static void Stop()
|
||||
{
|
||||
var app = GetApp();
|
||||
if (app is IDisposable disposable)
|
||||
Dispatcher.UIThread.Post(disposable.Dispose);
|
||||
Dispatcher.UIThread.Post(() => app.Shutdown());
|
||||
}
|
||||
|
||||
public static MainWindow GetMainWindow() => (MainWindow) GetApp().MainWindow;
|
||||
public static IClassicDesktopStyleApplicationLifetime GetApp() =>
|
||||
(IClassicDesktopStyleApplicationLifetime) Application.Current.ApplicationLifetime;
|
||||
|
||||
public static AppBuilder BuildAvaloniaApp() =>
|
||||
AppBuilder.Configure<App>()
|
||||
.UsePlatformDetect()
|
||||
.UseReactiveUI()
|
||||
.UseHeadless();
|
||||
}
|
111
Wabbajack.App.Test/AvaloniaUiTestFramework.cs
Normal file
111
Wabbajack.App.Test/AvaloniaUiTestFramework.cs
Normal file
@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using Xunit.Sdk;
|
||||
|
||||
|
||||
|
||||
[assembly: TestFramework("Wabbajack.App.Test.AvaloniaUiTestFramework", "Wabbajack.App.Test")]
|
||||
[assembly: CollectionBehavior(CollectionBehavior.CollectionPerAssembly, DisableTestParallelization = false, MaxParallelThreads = 1)]
|
||||
namespace Wabbajack.App.Test
|
||||
{
|
||||
public class AvaloniaUiTestFramework : XunitTestFramework
|
||||
{
|
||||
public AvaloniaUiTestFramework(IMessageSink messageSink)
|
||||
: base(messageSink)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override ITestFrameworkExecutor CreateExecutor(AssemblyName assemblyName)
|
||||
=> new Executor(assemblyName, SourceInformationProvider, DiagnosticMessageSink);
|
||||
|
||||
private class Executor : XunitTestFrameworkExecutor
|
||||
{
|
||||
public Executor(
|
||||
AssemblyName assemblyName,
|
||||
ISourceInformationProvider sourceInformationProvider,
|
||||
IMessageSink diagnosticMessageSink)
|
||||
: base(
|
||||
assemblyName,
|
||||
sourceInformationProvider,
|
||||
diagnosticMessageSink)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override async void RunTestCases(IEnumerable<IXunitTestCase> testCases,
|
||||
IMessageSink executionMessageSink,
|
||||
ITestFrameworkExecutionOptions executionOptions)
|
||||
{
|
||||
executionOptions.SetValue("xunit.execution.DisableParallelization", false);
|
||||
using var assemblyRunner = new Runner(
|
||||
TestAssembly, testCases, DiagnosticMessageSink, executionMessageSink,
|
||||
executionOptions);
|
||||
|
||||
await assemblyRunner.RunAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private class Runner : XunitTestAssemblyRunner
|
||||
{
|
||||
public Runner(
|
||||
ITestAssembly testAssembly,
|
||||
IEnumerable<IXunitTestCase> testCases,
|
||||
IMessageSink diagnosticMessageSink,
|
||||
IMessageSink executionMessageSink,
|
||||
ITestFrameworkExecutionOptions executionOptions)
|
||||
: base(
|
||||
testAssembly,
|
||||
testCases,
|
||||
diagnosticMessageSink,
|
||||
executionMessageSink,
|
||||
executionOptions)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
AvaloniaApp.Stop();
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
protected override void SetupSyncContext(int maxParallelThreads)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<SynchronizationContext>();
|
||||
var thread = new Thread(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
AvaloniaApp
|
||||
.BuildAvaloniaApp()
|
||||
.AfterSetup(_ =>
|
||||
{
|
||||
tcs.SetResult(SynchronizationContext.Current);
|
||||
})
|
||||
.StartWithClassicDesktopLifetime(new string[0]);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
tcs.SetException(e);
|
||||
}
|
||||
})
|
||||
{
|
||||
IsBackground = true
|
||||
};
|
||||
thread.SetApartmentState(ApartmentState.STA);
|
||||
|
||||
thread.Start();
|
||||
|
||||
SynchronizationContext.SetSynchronizationContext(tcs.Task.Result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -2,6 +2,8 @@ using System;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Threading;
|
||||
using Wabbajack.App.Models;
|
||||
using Wabbajack.App.ViewModels;
|
||||
using Wabbajack.App.Views;
|
||||
|
||||
namespace Wabbajack.App.Test;
|
||||
|
||||
@ -37,4 +39,9 @@ public static class Extensions
|
||||
await Task.Delay(100);
|
||||
}
|
||||
}
|
||||
|
||||
public static T GetScreen<T>(this MainWindow view)
|
||||
{
|
||||
return (T) view.Contents.Content;
|
||||
}
|
||||
}
|
@ -63,12 +63,12 @@ public class GalleryItemTests
|
||||
|
||||
modList.ExecuteCommand.Execute().Subscribe().Dispose();
|
||||
|
||||
var msgs = ((SimpleMessageBus) MessageBus.Instance).Messages.TakeLast(2).ToArray();
|
||||
|
||||
/*
|
||||
var configure = msgs.OfType<StartInstallConfiguration>().First();
|
||||
Assert.Equal(modList.ModListLocation, configure.ModList);
|
||||
|
||||
var navigate = msgs.OfType<NavigateTo>().First();
|
||||
Assert.Equal(typeof(InstallConfigurationViewModel), navigate.ViewModel);
|
||||
*/
|
||||
}
|
||||
}
|
55
Wabbajack.App.Test/MainWindowTests.cs
Normal file
55
Wabbajack.App.Test/MainWindowTests.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Threading;
|
||||
using Avalonia.VisualTree;
|
||||
using Wabbajack.App.Controls;
|
||||
using Wabbajack.App.Interfaces;
|
||||
using Wabbajack.App.Screens;
|
||||
using Wabbajack.App.Views;
|
||||
using Xunit;
|
||||
|
||||
namespace Wabbajack.App.Test;
|
||||
|
||||
public class MainWindowTests
|
||||
{
|
||||
private static TimeSpan StandardDelay = new TimeSpan(250);
|
||||
|
||||
[Fact(DisplayName = "Can Open and Close MainWindow")]
|
||||
public async Task CanOpenMainApp()
|
||||
{
|
||||
var app = AvaloniaApp.GetApp();
|
||||
var window = AvaloniaApp.GetMainWindow();
|
||||
|
||||
var msv = await GoHome(window);
|
||||
msv.BrowseButton.Button.Command.Execute(null);
|
||||
msv.BrowseButton.Button.Command.Execute(null);
|
||||
|
||||
var yu = Dispatcher.UIThread;
|
||||
|
||||
await Task.Delay(StandardDelay * 4);
|
||||
|
||||
var gallery = window.GetScreen<BrowseView>();
|
||||
gallery.SearchBox.Text = "Halgaris Helper";
|
||||
await Task.Delay(StandardDelay);
|
||||
var itms = gallery.GalleryList.FindDescendantOfType<BrowseItemView>();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private async Task<ModeSelectionView> GoHome(MainWindow mainWindow)
|
||||
{
|
||||
while (mainWindow.BackButton.Command.CanExecute(null))
|
||||
{
|
||||
mainWindow.BackButton.Command.Execute(null);
|
||||
await Task.Delay(StandardDelay);
|
||||
}
|
||||
|
||||
if (mainWindow.Contents.Content is ModeSelectionView msv)
|
||||
return msv;
|
||||
|
||||
throw new Exception("Top screen is not ModeSelectionView");
|
||||
}
|
||||
}
|
@ -16,16 +16,5 @@ public class Startup
|
||||
public void Configure(ILoggerFactory loggerFactory, ITestOutputHelperAccessor accessor)
|
||||
{
|
||||
loggerFactory.AddProvider(new XunitTestOutputLoggerProvider(accessor, delegate { return true; }));
|
||||
MessageBus.Instance = new SimpleMessageBus();
|
||||
}
|
||||
}
|
||||
|
||||
public class SimpleMessageBus : IMessageBus
|
||||
{
|
||||
public List<object> Messages { get; } = new();
|
||||
|
||||
public void Send<T>(T message)
|
||||
{
|
||||
Messages.Add(message);
|
||||
}
|
||||
}
|
@ -7,6 +7,8 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="0.10.9" />
|
||||
<PackageReference Include="Avalonia.Headless" Version="0.10.9" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
|
@ -78,8 +78,8 @@ public class BrowseItemViewModel : ViewModelBase, IActivatableViewModel
|
||||
{
|
||||
if (State == ModListState.Downloaded)
|
||||
{
|
||||
MessageBus.Instance.Send(new StartInstallConfiguration(ModListLocation));
|
||||
MessageBus.Instance.Send(new NavigateTo(typeof(InstallConfigurationViewModel)));
|
||||
MessageBus.Current.SendMessage(new StartInstallConfiguration(ModListLocation));
|
||||
MessageBus.Current.SendMessage(new NavigateTo(typeof(InstallConfigurationViewModel)));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -19,8 +19,8 @@ public class InstalledListViewModel : ViewModelBase
|
||||
|
||||
Play = ReactiveCommand.Create(() =>
|
||||
{
|
||||
MessageBus.Instance.Send(new ConfigureLauncher(InstallPath));
|
||||
MessageBus.Instance.Send(new NavigateTo(typeof(LauncherViewModel)));
|
||||
MessageBus.Current.SendMessage(new ConfigureLauncher(InstallPath));
|
||||
MessageBus.Current.SendMessage(new NavigateTo(typeof(LauncherViewModel)));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
xmlns:i="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Wabbajack.App.Controls.LargeIconButton">
|
||||
<Button x:Name="Button">
|
||||
<Button x:Name="Button" x:FieldModifier="public">
|
||||
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<i:MaterialIcon x:Name="IconControl" Width="140" Height="140" />
|
||||
<TextBlock x:Name="TextBlock" HorizontalAlignment="Center" FontSize="28" FontWeight="Bold" />
|
||||
|
@ -1,50 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reactive.Disposables;
|
||||
using Avalonia.Threading;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Wabbajack.App.Messages;
|
||||
|
||||
namespace Wabbajack.App;
|
||||
|
||||
public interface IMessageBus
|
||||
{
|
||||
public void Send<T>(T message);
|
||||
}
|
||||
|
||||
public class MessageBus : IMessageBus
|
||||
{
|
||||
private readonly ILogger<MessageBus> _logger;
|
||||
private readonly IReceiverMarker[] _receivers;
|
||||
|
||||
public MessageBus(ILogger<MessageBus> logger, IEnumerable<IReceiverMarker> receivers)
|
||||
{
|
||||
Instance = this;
|
||||
_receivers = receivers.ToArray();
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public static IMessageBus Instance { get; set; }
|
||||
|
||||
public void Send<T>(T message)
|
||||
{
|
||||
AvaloniaScheduler.Instance.Schedule(message, TimeSpan.FromMilliseconds(200), (_, msg) =>
|
||||
{
|
||||
foreach (var receiver in _receivers.OfType<IReceiver<T>>())
|
||||
{
|
||||
_logger.LogInformation("Sending {msg} to {receiver}", msg, receiver);
|
||||
try
|
||||
{
|
||||
receiver.Receive(msg);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogCritical(ex, "Failed sending {msg} to {receiver}", msg, receiver);
|
||||
}
|
||||
}
|
||||
|
||||
return Disposable.Empty;
|
||||
});
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace Wabbajack.App.Messages;
|
||||
|
||||
public interface IReceiverMarker
|
||||
{
|
||||
}
|
||||
|
||||
public interface IReceiver<in T> : IReceiverMarker
|
||||
{
|
||||
public void Receive(T val);
|
||||
}
|
@ -39,7 +39,7 @@
|
||||
<TextBox
|
||||
x:Name="SearchBox"
|
||||
Width="95"
|
||||
VerticalContentAlignment="Center" />
|
||||
VerticalContentAlignment="Center" x:FieldModifier="public" />
|
||||
<CheckBox
|
||||
x:Name="ShowNSFW"
|
||||
Margin="10,0,10,0"
|
||||
@ -63,7 +63,7 @@
|
||||
</WrapPanel>
|
||||
|
||||
<ScrollViewer Grid.Row="1">
|
||||
<ItemsControl x:Name="GalleryList">
|
||||
<ItemsControl x:Name="GalleryList" x:FieldModifier="public">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<WrapPanel />
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Threading;
|
||||
@ -14,7 +15,7 @@ using Wabbajack.RateLimiter;
|
||||
|
||||
namespace Wabbajack.App.Screens;
|
||||
|
||||
public class CompilationViewModel : ViewModelBase, IReceiverMarker, IReceiver<StartCompilation>
|
||||
public class CompilationViewModel : ViewModelBase
|
||||
{
|
||||
private readonly ILogger<CompilationViewModel> _logger;
|
||||
private readonly IServiceProvider _provider;
|
||||
@ -26,13 +27,17 @@ public class CompilationViewModel : ViewModelBase, IReceiverMarker, IReceiver<St
|
||||
_logger = logger;
|
||||
_provider = provider;
|
||||
Activator = new ViewModelActivator();
|
||||
|
||||
MessageBus.Current.Listen<StartCompilation>()
|
||||
.Subscribe(Receive)
|
||||
.DisposeWith(VMDisposables);
|
||||
}
|
||||
|
||||
[Reactive] public string StatusText { get; set; } = "";
|
||||
[Reactive] public Percent StepsProgress { get; set; } = Percent.Zero;
|
||||
[Reactive] public Percent StepProgress { get; set; } = Percent.Zero;
|
||||
|
||||
public void Receive(StartCompilation val)
|
||||
private void Receive(StartCompilation val)
|
||||
{
|
||||
if (val.Settings is MO2CompilerSettings mo2)
|
||||
{
|
||||
|
@ -22,7 +22,7 @@ using Consts = Wabbajack.Compiler.Consts;
|
||||
|
||||
namespace Wabbajack.App.Screens;
|
||||
|
||||
public class CompilerConfigurationViewModel : ViewModelBase, IReceiverMarker
|
||||
public class CompilerConfigurationViewModel : ViewModelBase
|
||||
{
|
||||
private readonly DTOSerializer _dtos;
|
||||
private readonly SettingsManager _settingsManager;
|
||||
@ -94,8 +94,8 @@ public class CompilerConfigurationViewModel : ViewModelBase, IReceiverMarker
|
||||
await SaveSettingsFile();
|
||||
await _settingsManager.Save("last_compilation", SettingsOutputLocation);
|
||||
|
||||
MessageBus.Instance.Send(new StartCompilation(settings));
|
||||
MessageBus.Instance.Send(new NavigateTo(typeof(CompilationViewModel)));
|
||||
MessageBus.Current.SendMessage(new StartCompilation(settings));
|
||||
MessageBus.Current.SendMessage(new NavigateTo(typeof(CompilationViewModel)));
|
||||
}
|
||||
|
||||
private CompilerSettings GetSettings()
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Avalonia.Controls.Mixins;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using Wabbajack.App.Messages;
|
||||
@ -6,11 +7,14 @@ using Wabbajack.App.ViewModels;
|
||||
|
||||
namespace Wabbajack.App.Screens;
|
||||
|
||||
public class ErrorPageViewModel : ViewModelBase, IActivatableViewModel, IReceiver<Error>
|
||||
public class ErrorPageViewModel : ViewModelBase
|
||||
{
|
||||
public ErrorPageViewModel()
|
||||
{
|
||||
Activator = new ViewModelActivator();
|
||||
MessageBus.Current.Listen<Error>()
|
||||
.Subscribe(Receive)
|
||||
.DisposeWith(VMDisposables);
|
||||
}
|
||||
|
||||
[Reactive] public string ShortMessage { get; set; }
|
||||
@ -25,7 +29,7 @@ public class ErrorPageViewModel : ViewModelBase, IActivatableViewModel, IReceive
|
||||
|
||||
public static void Display(string prefix, Exception ex)
|
||||
{
|
||||
MessageBus.Instance.Send(new Error(prefix, ex));
|
||||
MessageBus.Instance.Send(new NavigateTo(typeof(ErrorPageViewModel)));
|
||||
MessageBus.Current.SendMessage(new Error(prefix, ex));
|
||||
MessageBus.Current.SendMessage(new NavigateTo(typeof(ErrorPageViewModel)));
|
||||
}
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reactive;
|
||||
@ -20,7 +22,7 @@ using Wabbajack.Paths.IO;
|
||||
|
||||
namespace Wabbajack.App.Screens;
|
||||
|
||||
public class LauncherViewModel : ViewModelBase, IActivatableViewModel, IReceiver<ConfigureLauncher>
|
||||
public class LauncherViewModel : ViewModelBase
|
||||
{
|
||||
private readonly ILogger<LauncherViewModel> _logger;
|
||||
|
||||
@ -32,6 +34,10 @@ public class LauncherViewModel : ViewModelBase, IActivatableViewModel, IReceiver
|
||||
PlayButton = ReactiveCommand.Create(() => { StartGame().FireAndForget(); });
|
||||
_logger = logger;
|
||||
|
||||
MessageBus.Current.Listen<ConfigureLauncher>()
|
||||
.Subscribe(v => Receive(v))
|
||||
.DisposeWith(VMDisposables);
|
||||
|
||||
this.WhenActivated(disposables =>
|
||||
{
|
||||
this.WhenAnyValue(v => v.InstallFolder)
|
||||
|
@ -17,7 +17,7 @@ using Wabbajack.Services.OSIntegrated.TokenProviders;
|
||||
|
||||
namespace Wabbajack.App.Screens;
|
||||
|
||||
public class SettingsViewModel : ViewModelBase, IReceiverMarker
|
||||
public class SettingsViewModel : ViewModelBase
|
||||
{
|
||||
private readonly Subject<AbsolutePath> _fileSystemEvents = new();
|
||||
private readonly ILogger<SettingsViewModel> _logger;
|
||||
@ -47,7 +47,7 @@ public class SettingsViewModel : ViewModelBase, IReceiverMarker
|
||||
.Select(_ => nexusProvider.HaveToken());
|
||||
|
||||
NexusLogin =
|
||||
ReactiveCommand.Create(() => { MessageBus.Instance.Send(new NavigateTo(typeof(NexusLoginViewModel))); },
|
||||
ReactiveCommand.Create(() => { MessageBus.Current.SendMessage(new NavigateTo(typeof(NexusLoginViewModel))); },
|
||||
haveNexusToken.Select(x => !x));
|
||||
NexusLogout = ReactiveCommand.Create(nexusProvider.DeleteToken, haveNexusToken.Select(x => x));
|
||||
});
|
||||
|
@ -30,7 +30,7 @@ using Wabbajack.RateLimiter;
|
||||
|
||||
namespace Wabbajack.App.ViewModels;
|
||||
|
||||
public class StandardInstallationViewModel : ViewModelBase, IReceiver<StartInstallation>
|
||||
public class StandardInstallationViewModel : ViewModelBase
|
||||
{
|
||||
private readonly DTOSerializer _dtos;
|
||||
private readonly HttpClient _httpClient;
|
||||
@ -57,6 +57,10 @@ public class StandardInstallationViewModel : ViewModelBase, IReceiver<StartInsta
|
||||
_installStateManager = manager;
|
||||
Activator = new ViewModelActivator();
|
||||
|
||||
MessageBus.Current.Listen<StartInstallation>()
|
||||
.Subscribe(Receive)
|
||||
.DisposeWith(VMDisposables);
|
||||
|
||||
this.WhenActivated(disposables =>
|
||||
{
|
||||
_slideTimer = new Timer(_ =>
|
||||
@ -214,7 +218,7 @@ public class StandardInstallationViewModel : ViewModelBase, IReceiver<StartInsta
|
||||
Image = path
|
||||
});
|
||||
|
||||
MessageBus.Instance.Send(new ConfigureLauncher(config.Install));
|
||||
MessageBus.Instance.Send(new NavigateTo(typeof(LauncherViewModel)));
|
||||
MessageBus.Current.SendMessage(new ConfigureLauncher(config.Install));
|
||||
MessageBus.Current.SendMessage(new NavigateTo(typeof(LauncherViewModel)));
|
||||
}
|
||||
}
|
@ -35,7 +35,6 @@ public static class ServiceExtensions
|
||||
public static IServiceCollection AddAppServices(this IServiceCollection services)
|
||||
{
|
||||
services.AddAllSingleton<ILoggerProvider, LoggerProvider>();
|
||||
services.AddSingleton<MessageBus>();
|
||||
services.AddSingleton<MainWindow>();
|
||||
services.AddSingleton<BrowseViewModel>();
|
||||
services.AddTransient<BrowseItemViewModel>();
|
||||
@ -64,17 +63,17 @@ public static class ServiceExtensions
|
||||
|
||||
services.AddSingleton<LogScreenViewModel>();
|
||||
services.AddSingleton<PlaySelectViewModel>();
|
||||
services.AddAllSingleton<IReceiverMarker, ErrorPageViewModel>();
|
||||
services.AddAllSingleton<IReceiverMarker, StandardInstallationViewModel>();
|
||||
services.AddAllSingleton<IReceiverMarker, InstallConfigurationViewModel>();
|
||||
services.AddAllSingleton<IReceiverMarker, CompilerConfigurationViewModel>();
|
||||
services.AddAllSingleton<IReceiverMarker, MainWindowViewModel>();
|
||||
services.AddAllSingleton<IReceiverMarker, SettingsViewModel>();
|
||||
services.AddAllSingleton<IReceiverMarker, NexusLoginViewModel>();
|
||||
services.AddAllSingleton<IReceiverMarker, LoversLabOAuthLoginViewModel>();
|
||||
services.AddAllSingleton<IReceiverMarker, VectorPlexusOAuthLoginViewModel>();
|
||||
services.AddAllSingleton<IReceiverMarker, CompilationViewModel>();
|
||||
services.AddAllSingleton<IReceiverMarker, LauncherViewModel>();
|
||||
services.AddSingleton<ErrorPageViewModel>();
|
||||
services.AddSingleton<StandardInstallationViewModel>();
|
||||
services.AddSingleton<InstallConfigurationViewModel>();
|
||||
services.AddSingleton<CompilerConfigurationViewModel>();
|
||||
services.AddSingleton<MainWindowViewModel>();
|
||||
services.AddSingleton<SettingsViewModel>();
|
||||
services.AddSingleton<NexusLoginViewModel>();
|
||||
services.AddSingleton<LoversLabOAuthLoginViewModel>();
|
||||
services.AddSingleton<VectorPlexusOAuthLoginViewModel>();
|
||||
services.AddSingleton<CompilationViewModel>();
|
||||
services.AddSingleton<LauncherViewModel>();
|
||||
|
||||
// Services
|
||||
services.AddAllSingleton<IDownloader, IDownloader<Manual>, ManualDownloader>();
|
||||
|
@ -9,7 +9,7 @@ using Wabbajack.App.Messages;
|
||||
|
||||
namespace Wabbajack.App.ViewModels;
|
||||
|
||||
public abstract class GuidedWebViewModel : ViewModelBase, IReceiverMarker
|
||||
public abstract class GuidedWebViewModel : ViewModelBase
|
||||
{
|
||||
protected ILogger _logger;
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
|
||||
using System;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls.Mixins;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Threading;
|
||||
using ReactiveUI;
|
||||
@ -21,7 +23,7 @@ using Wabbajack.Paths.IO;
|
||||
|
||||
namespace Wabbajack.App.ViewModels;
|
||||
|
||||
public class InstallConfigurationViewModel : ViewModelBase, IActivatableViewModel, IReceiver<StartInstallConfiguration>
|
||||
public class InstallConfigurationViewModel : ViewModelBase, IActivatableViewModel
|
||||
{
|
||||
private readonly DTOSerializer _dtos;
|
||||
private readonly InstallationStateManager _stateManager;
|
||||
@ -33,6 +35,11 @@ public class InstallConfigurationViewModel : ViewModelBase, IActivatableViewMode
|
||||
|
||||
_dtos = dtos;
|
||||
Activator = new ViewModelActivator();
|
||||
|
||||
MessageBus.Current.Listen<StartInstallConfiguration>()
|
||||
.Subscribe(Receive)
|
||||
.DisposeWith(VMDisposables);
|
||||
|
||||
this.WhenActivated(disposables =>
|
||||
{
|
||||
this.ValidationRule(x => x.ModListPath, p => p.FileExists(), "Wabbajack file must exist");
|
||||
@ -88,7 +95,7 @@ public class InstallConfigurationViewModel : ViewModelBase, IActivatableViewMode
|
||||
|
||||
public ViewModelActivator Activator { get; }
|
||||
|
||||
public void Receive(StartInstallConfiguration val)
|
||||
private void Receive(StartInstallConfiguration val)
|
||||
{
|
||||
ModListPath = val.ModList;
|
||||
}
|
||||
@ -108,8 +115,8 @@ public class InstallConfigurationViewModel : ViewModelBase, IActivatableViewMode
|
||||
Metadata = metadata
|
||||
}).FireAndForget();
|
||||
|
||||
MessageBus.Instance.Send(new NavigateTo(typeof(StandardInstallationViewModel)));
|
||||
MessageBus.Instance.Send(new StartInstallation(ModListPath, Install, Download, metadata));
|
||||
MessageBus.Current.SendMessage(new NavigateTo(typeof(StandardInstallationViewModel)));
|
||||
MessageBus.Current.SendMessage(new StartInstallation(ModListPath, Install, Download, metadata));
|
||||
}
|
||||
|
||||
private async Task<IBitmap> LoadModListImage(AbsolutePath path)
|
||||
|
@ -22,8 +22,7 @@ using Wabbajack.RateLimiter;
|
||||
|
||||
namespace Wabbajack.App.ViewModels;
|
||||
|
||||
public class MainWindowViewModel : ReactiveValidationObject, IActivatableViewModel, IReceiver<NavigateTo>,
|
||||
IReceiver<NavigateBack>
|
||||
public class MainWindowViewModel : ReactiveValidationObject, IActivatableViewModel, IDisposable
|
||||
{
|
||||
private readonly InstallationStateManager _manager;
|
||||
private readonly IServiceProvider _provider;
|
||||
@ -32,6 +31,8 @@ public class MainWindowViewModel : ReactiveValidationObject, IActivatableViewMod
|
||||
private readonly IEnumerable<IScreenView> _screens;
|
||||
private StatusReport[] _prevReport;
|
||||
|
||||
private CompositeDisposable VMDisposables = new();
|
||||
|
||||
public MainWindowViewModel(IEnumerable<IScreenView> screens, IEnumerable<IResource> resources,
|
||||
IServiceProvider provider,
|
||||
InstallationStateManager manager)
|
||||
@ -45,6 +46,14 @@ public class MainWindowViewModel : ReactiveValidationObject, IActivatableViewMod
|
||||
|
||||
Activator = new ViewModelActivator();
|
||||
|
||||
MessageBus.Current.Listen<NavigateTo>()
|
||||
.Subscribe(Receive)
|
||||
.DisposeWith(VMDisposables);
|
||||
|
||||
MessageBus.Current.Listen<NavigateBack>()
|
||||
.Subscribe(Receive)
|
||||
.DisposeWith(VMDisposables);
|
||||
|
||||
_resourcePoller = StartResourcePoller(TimeSpan.FromSeconds(0.25));
|
||||
|
||||
this.WhenActivated(disposables =>
|
||||
@ -103,7 +112,7 @@ public class MainWindowViewModel : ReactiveValidationObject, IActivatableViewMod
|
||||
BreadCrumbs =
|
||||
BreadCrumbs.Push((Control) _screens.First(s => s.ViewModelType == typeof(ModeSelectionViewModel)));
|
||||
|
||||
MessageBus.Instance.Send(new ConfigureLauncher(setting.Install));
|
||||
MessageBus.Current.SendMessage(new ConfigureLauncher(setting.Install));
|
||||
Receive(new NavigateTo(typeof(LauncherViewModel)));
|
||||
}
|
||||
else
|
||||
@ -137,4 +146,14 @@ public class MainWindowViewModel : ReactiveValidationObject, IActivatableViewMod
|
||||
await Task.Delay(TimeSpan.FromSeconds(0.5));
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_resourcePoller.Dispose();
|
||||
VMDisposables.Dispose();
|
||||
BackButton.Dispose();
|
||||
SettingsButton.Dispose();
|
||||
LogViewButton.Dispose();
|
||||
Activator.Dispose();
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Fizzler.Systems.HtmlAgilityPack;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ReactiveUI;
|
||||
using Wabbajack.App.Extensions;
|
||||
using Wabbajack.App.Messages;
|
||||
using Wabbajack.DTOs.Logins;
|
||||
@ -87,7 +88,7 @@ public class NexusLoginViewModel : GuidedWebViewModel
|
||||
token.ThrowIfCancellationRequested();
|
||||
await Task.Delay(500, token);
|
||||
|
||||
MessageBus.Instance.Send(new NavigateBack());
|
||||
MessageBus.Current.SendMessage(new NavigateBack());
|
||||
}
|
||||
|
||||
Instructions = "Success, saving information...";
|
||||
|
@ -1,9 +1,18 @@
|
||||
using ReactiveUI;
|
||||
using System;
|
||||
using System.Reactive.Disposables;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Validation.Helpers;
|
||||
|
||||
namespace Wabbajack.App.ViewModels;
|
||||
|
||||
public class ViewModelBase : ReactiveValidationObject, IActivatableViewModel
|
||||
public class ViewModelBase : ReactiveValidationObject, IActivatableViewModel, IDisposable
|
||||
{
|
||||
protected readonly CompositeDisposable VMDisposables = new();
|
||||
public ViewModelActivator Activator { get; protected set; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
VMDisposables.Dispose();
|
||||
Activator.Dispose();
|
||||
}
|
||||
}
|
@ -33,7 +33,7 @@
|
||||
|
||||
<Grid RowDefinitions="40, *">
|
||||
<Grid ColumnDefinitions="40, *, 40, 40, 40, 40">
|
||||
<Button Grid.Column="0" x:Name="BackButton">
|
||||
<Button Grid.Column="0" x:Name="BackButton" x:FieldModifier="public">
|
||||
<i:MaterialIcon Kind="ArrowBack" />
|
||||
</Button>
|
||||
|
||||
@ -50,12 +50,12 @@
|
||||
<i:MaterialIcon Kind="WindowMinimize" />
|
||||
</Button>
|
||||
|
||||
<Button Grid.Column="5" x:Name="CloseButton">
|
||||
<Button Grid.Column="5" x:Name="CloseButton" x:FieldModifier="public">
|
||||
<i:MaterialIcon Kind="Close" />
|
||||
</Button>
|
||||
|
||||
</Grid>
|
||||
<ContentControl Grid.Row="1" x:Name="Contents" />
|
||||
<ContentControl Grid.Row="1" x:Name="Contents" x:FieldModifier="public" />
|
||||
|
||||
</Grid>
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
<Image Margin="40,20,40,0" Source="../Assets/Wabba_Mouth.png" />
|
||||
</Viewbox>
|
||||
<Grid Grid.Row="1" ColumnDefinitions="*, *, *, *" HorizontalAlignment="Center">
|
||||
<controls:LargeIconButton Grid.Column="0" Text="Browse" Icon="CloudDownload" x:Name="BrowseButton" />
|
||||
<controls:LargeIconButton Grid.Column="0" Text="Browse" Icon="CloudDownload" x:Name="BrowseButton" x:FieldModifier="public"/>
|
||||
<controls:LargeIconButton Grid.Column="1" Text="Install" Icon="HarddiskPlus" x:Name="InstallButton" />
|
||||
<controls:LargeIconButton Grid.Column="2" Text="Compile" Icon="DatabaseImport" x:Name="CompileButton" />
|
||||
<controls:LargeIconButton Grid.Column="3" Text="Play" Icon="TelevisionPlay" x:Name="LaunchButton" />
|
||||
|
@ -16,22 +16,22 @@ public partial class ModeSelectionView : ScreenBase<ModeSelectionViewModel>
|
||||
{
|
||||
InstallButton.Button.Command = ReactiveCommand.Create(() =>
|
||||
{
|
||||
MessageBus.Instance.Send(new NavigateTo(typeof(InstallConfigurationViewModel)));
|
||||
MessageBus.Current.SendMessage(new NavigateTo(typeof(InstallConfigurationViewModel)));
|
||||
}).DisposeWith(disposables);
|
||||
|
||||
BrowseButton.Button.Command = ReactiveCommand.Create(() =>
|
||||
{
|
||||
MessageBus.Instance.Send(new NavigateTo(typeof(BrowseViewModel)));
|
||||
MessageBus.Current.SendMessage(new NavigateTo(typeof(BrowseViewModel)));
|
||||
}).DisposeWith(disposables);
|
||||
|
||||
CompileButton.Button.Command = ReactiveCommand.Create(() =>
|
||||
{
|
||||
MessageBus.Instance.Send(new NavigateTo(typeof(CompilerConfigurationViewModel)));
|
||||
MessageBus.Current.SendMessage(new NavigateTo(typeof(CompilerConfigurationViewModel)));
|
||||
}).DisposeWith(disposables);
|
||||
|
||||
LaunchButton.Button.Command = ReactiveCommand.Create(() =>
|
||||
{
|
||||
MessageBus.Instance.Send(new NavigateTo(typeof(PlaySelectViewModel)));
|
||||
MessageBus.Current.SendMessage(new NavigateTo(typeof(PlaySelectViewModel)));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -6,35 +6,35 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Models\"/>
|
||||
<AvaloniaResource Include="Assets\**"/>
|
||||
<AvaloniaXaml Remove="Assets\Wabbajack.axaml"/>
|
||||
<AvaloniaResource Include="Assets\Wabbajack.axaml"/>
|
||||
<Folder Include="Models\" />
|
||||
<AvaloniaResource Include="Assets\**" />
|
||||
<AvaloniaXaml Remove="Assets\Wabbajack.axaml" />
|
||||
<AvaloniaResource Include="Assets\Wabbajack.axaml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="0.10.8"/>
|
||||
<PackageReference Include="Avalonia.Desktop" Version="0.10.8"/>
|
||||
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.8"/>
|
||||
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.8"/>
|
||||
<PackageReference Include="CefNet.Avalonia" Version="94.0.21246.700"/>
|
||||
<PackageReference Include="DynamicData" Version="7.4.1"/>
|
||||
<PackageReference Include="Fizzler.Systems.HtmlAgilityPack" Version="1.2.1"/>
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.37"/>
|
||||
<PackageReference Include="Material.Icons.Avalonia" Version="1.0.2"/>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0-rc.2.21480.5"/>
|
||||
<PackageReference Include="ReactiveUI.Fody" Version="16.2.6"/>
|
||||
<PackageReference Include="ReactiveUI.Validation" Version="2.2.1"/>
|
||||
<PackageReference Include="XamlNameReferenceGenerator" Version="1.3.4"/>
|
||||
<PackageReference Include="Avalonia" Version="0.10.8" />
|
||||
<PackageReference Include="Avalonia.Desktop" Version="0.10.8" />
|
||||
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.8" />
|
||||
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.8" />
|
||||
<PackageReference Include="CefNet.Avalonia" Version="94.0.21246.700" />
|
||||
<PackageReference Include="DynamicData" Version="7.4.1" />
|
||||
<PackageReference Include="Fizzler.Systems.HtmlAgilityPack" Version="1.2.1" />
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.37" />
|
||||
<PackageReference Include="Material.Icons.Avalonia" Version="1.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0-rc.2.21480.5" />
|
||||
<PackageReference Include="ReactiveUI.Fody" Version="16.2.6" />
|
||||
<PackageReference Include="ReactiveUI.Validation" Version="2.2.1" />
|
||||
<PackageReference Include="XamlNameReferenceGenerator" Version="1.3.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Wabbajack.CLI\Wabbajack.CLI.csproj"/>
|
||||
<ProjectReference Include="..\Wabbajack.DTOs\Wabbajack.DTOs.csproj"/>
|
||||
<ProjectReference Include="..\Wabbajack.Installer\Wabbajack.Installer.csproj"/>
|
||||
<ProjectReference Include="..\Wabbajack.Paths\Wabbajack.Paths.csproj"/>
|
||||
<ProjectReference Include="..\Wabbajack.Services.OSIntegrated\Wabbajack.Services.OSIntegrated.csproj"/>
|
||||
<ProjectReference Include="..\Wabbajack.CLI\Wabbajack.CLI.csproj" />
|
||||
<ProjectReference Include="..\Wabbajack.DTOs\Wabbajack.DTOs.csproj" />
|
||||
<ProjectReference Include="..\Wabbajack.Installer\Wabbajack.Installer.csproj" />
|
||||
<ProjectReference Include="..\Wabbajack.Paths\Wabbajack.Paths.csproj" />
|
||||
<ProjectReference Include="..\Wabbajack.Services.OSIntegrated\Wabbajack.Services.OSIntegrated.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.AspNetCore.Mvc.Core"/>
|
||||
<Reference Include="Microsoft.AspNetCore.Mvc.Core" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Update="Screens\SettingsView.axaml.cs">
|
||||
@ -51,7 +51,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="AferBuild" AfterTargets="Build" Condition="!Exists('$(ProjectDir)$(OutDir)libcef.dll')">
|
||||
<Message Text="Downloading Cef"/>
|
||||
<Exec Command="dotnet run --project $(ProjectDir)../Wabbajack.CLI/Wabbajack.CLI.csproj -- download-cef -f $(ProjectDir)$(OutDir)"/>
|
||||
<Message Text="Downloading Cef" />
|
||||
<Exec Command="dotnet run --project $(ProjectDir)../Wabbajack.CLI/Wabbajack.CLI.csproj -- download-cef -f $(ProjectDir)$(OutDir)" />
|
||||
</Target>
|
||||
</Project>
|
||||
|
Loading…
Reference in New Issue
Block a user