Refactor WPF startup to accept commandline inputs

This commit is contained in:
Halgari 2022-10-14 15:11:09 -06:00
parent 725e75e0f5
commit 2b33aeb7d9

View File

@ -27,15 +27,14 @@ namespace Wabbajack
/// </summary> /// </summary>
public partial class App public partial class App
{ {
private readonly IServiceProvider _serviceProvider; private IHost _host;
private readonly IHost _host;
public App() private void OnStartup(object sender, StartupEventArgs e)
{ {
WebView2AutoInstaller.CheckAndInstallAsync(false, false).Wait(); WebView2AutoInstaller.CheckAndInstallAsync(false, false).Wait();
RxApp.MainThreadScheduler = new DispatcherScheduler(Dispatcher.CurrentDispatcher); RxApp.MainThreadScheduler = new DispatcherScheduler(Dispatcher.CurrentDispatcher);
_host = Host.CreateDefaultBuilder(Array.Empty<string>()) _host = Host.CreateDefaultBuilder(e.Args)
.ConfigureLogging(AddLogging) .ConfigureLogging(AddLogging)
.ConfigureServices((host, services) => .ConfigureServices((host, services) =>
{ {
@ -43,7 +42,12 @@ namespace Wabbajack
}) })
.Build(); .Build();
_serviceProvider = _host.Services; RxApp.MainThreadScheduler.Schedule(0, (_, _) =>
{
var mainWindow = _host.Services.GetRequiredService<MainWindow>();
mainWindow!.Show();
return Disposable.Empty;
});
} }
private void AddLogging(ILoggingBuilder loggingBuilder) private void AddLogging(ILoggingBuilder loggingBuilder)
@ -121,15 +125,7 @@ namespace Wabbajack
return services; return services;
} }
private void OnStartup(object sender, StartupEventArgs e)
{
RxApp.MainThreadScheduler.Schedule(0, (_, _) =>
{
var mainWindow = _serviceProvider.GetRequiredService<MainWindow>();
mainWindow!.Show();
return Disposable.Empty;
});
}
private void OnExit(object sender, ExitEventArgs e) private void OnExit(object sender, ExitEventArgs e)
{ {