Some compiler VM startup optimizations

This commit is contained in:
Justin Swanson 2019-11-14 22:54:34 -06:00
parent 80f96433bc
commit 52517dc3e4
3 changed files with 48 additions and 20 deletions

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
@ -184,5 +184,23 @@ namespace Wabbajack
return (prev, i);
});
}
public static IObservable<T> DelayInitial<T>(this IObservable<T> source, TimeSpan delay)
{
return source.FilterSwitch(
Observable.Return(System.Reactive.Unit.Default)
.Delay(delay)
.Select(_ => true)
.StartWith(false));
}
public static IObservable<T> DelayInitial<T>(this IObservable<T> source, TimeSpan delay, IScheduler scheduler)
{
return source.FilterSwitch(
Observable.Return(System.Reactive.Unit.Default)
.Delay(delay, scheduler)
.Select(_ => true)
.StartWith(false));
}
}
}

View File

@ -1,4 +1,4 @@
using Microsoft.WindowsAPICodePack.Dialogs;
using Microsoft.WindowsAPICodePack.Dialogs;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using System;
@ -45,6 +45,8 @@ namespace Wabbajack
// Swap to proper sub VM based on selected type
this._Compiler = this.WhenAny(x => x.SelectedCompilerType)
// Delay so the initial VM swap comes in immediately, subVM comes right after
.DelayInitial(TimeSpan.FromMilliseconds(50), RxApp.MainThreadScheduler)
.Select<ModManager, ISubCompilerVM>(type =>
{
switch (type)
@ -64,6 +66,8 @@ namespace Wabbajack
.ToProperty(this, nameof(this.CurrentModlistSettings));
this._Image = this.WhenAny(x => x.CurrentModlistSettings.ImagePath.TargetPath)
// Delay so the initial VM swap comes in immediately, image comes right after
.DelayInitial(TimeSpan.FromMilliseconds(50), RxApp.MainThreadScheduler)
.Select(path =>
{
if (string.IsNullOrWhiteSpace(path)) return UIUtils.BitmapImageFromResource("Wabbajack.Resources.Banner_Dark.png");

View File

@ -1,4 +1,4 @@
using ReactiveUI;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using System;
using System.Collections.Generic;
@ -78,23 +78,6 @@ namespace Wabbajack
})
.ToProperty(this, nameof(this.MOProfile));
// If Mo2 folder changes and download location is empty, set it for convenience
this.WhenAny(x => x.Mo2Folder)
.Where(x => Directory.Exists(x))
.Subscribe(x =>
{
try
{
var tmp_compiler = new Compiler(this.Mo2Folder);
this.DownloadLocation.TargetPath = tmp_compiler.MO2DownloadsFolder;
}
catch (Exception ex)
{
Utils.Log($"Error setting default download location {ex}");
}
})
.DisposeWith(this.CompositeDisposable);
// Wire missing Mo2Folder to signal error state for Modlist Location
this.ModlistLocation.AdditionalError = this.WhenAny(x => x.Mo2Folder)
.Select<string, IErrorResponse>(moFolder =>
@ -188,6 +171,29 @@ namespace Wabbajack
// Save to property
.ObserveOnGuiThread()
.ToProperty(this, nameof(this.ModlistSettings));
// If Mo2 folder changes and download location is empty, set it for convenience
this.WhenAny(x => x.Mo2Folder)
.DelayInitial(TimeSpan.FromMilliseconds(100))
.Where(x => Directory.Exists(x))
.FilterSwitch(
this.WhenAny(x => x.DownloadLocation.Exists)
.Invert())
.Subscribe(x =>
{
try
{
var tmp_compiler = new Compiler(this.Mo2Folder);
this.DownloadLocation.TargetPath = tmp_compiler.MO2DownloadsFolder;
}
catch (Exception ex)
{
Utils.Log($"Error setting default download location {ex}");
}
})
.DisposeWith(this.CompositeDisposable);
}
}
}