diff --git a/Wabbajack.Common/Extensions/RxExt.cs b/Wabbajack.Common/Extensions/RxExt.cs index 20ce19f1..25ac87b2 100644 --- a/Wabbajack.Common/Extensions/RxExt.cs +++ b/Wabbajack.Common/Extensions/RxExt.cs @@ -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 DelayInitial(this IObservable source, TimeSpan delay) + { + return source.FilterSwitch( + Observable.Return(System.Reactive.Unit.Default) + .Delay(delay) + .Select(_ => true) + .StartWith(false)); + } + + public static IObservable DelayInitial(this IObservable source, TimeSpan delay, IScheduler scheduler) + { + return source.FilterSwitch( + Observable.Return(System.Reactive.Unit.Default) + .Delay(delay, scheduler) + .Select(_ => true) + .StartWith(false)); + } } } diff --git a/Wabbajack/View Models/Compilers/CompilerVM.cs b/Wabbajack/View Models/Compilers/CompilerVM.cs index 70cc770f..9a8f32e9 100644 --- a/Wabbajack/View Models/Compilers/CompilerVM.cs +++ b/Wabbajack/View Models/Compilers/CompilerVM.cs @@ -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(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"); diff --git a/Wabbajack/View Models/Compilers/MO2CompilerVM.cs b/Wabbajack/View Models/Compilers/MO2CompilerVM.cs index 44484b27..0a0d3311 100644 --- a/Wabbajack/View Models/Compilers/MO2CompilerVM.cs +++ b/Wabbajack/View Models/Compilers/MO2CompilerVM.cs @@ -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(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); + + } } }