From d8e625f481c3ec0761cd0613c2b999932d13521d Mon Sep 17 00:00:00 2001 From: AL <26797547+Al12rs@users.noreply.github.com> Date: Tue, 28 May 2024 12:53:54 +0200 Subject: [PATCH 1/2] Run an ingest on startup if active profile --- .../LeftMenu/Items/ApplyControlViewModel.cs | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/NexusMods.App.UI/LeftMenu/Items/ApplyControlViewModel.cs b/src/NexusMods.App.UI/LeftMenu/Items/ApplyControlViewModel.cs index 3cd177c2c2..a841a466c7 100644 --- a/src/NexusMods.App.UI/LeftMenu/Items/ApplyControlViewModel.cs +++ b/src/NexusMods.App.UI/LeftMenu/Items/ApplyControlViewModel.cs @@ -24,12 +24,13 @@ public class ApplyControlViewModel : AViewModel, IApplyC private readonly LoadoutId _loadoutId; private readonly GameInstallation _gameInstallation; + + private bool _isFirstLoad = true; [Reactive] private Abstractions.Loadouts.Loadout.Model NewestLoadout { get; set; } [Reactive] private LoadoutId LastAppliedLoadoutId { get; set; } [Reactive] private LoadoutWithTxId LastAppliedWithTxId { get; set; } - - [Reactive] bool CanApply { get; set; } = true; + [Reactive] private bool CanApply { get; set; } = true; public ReactiveCommand ApplyCommand { get; } public ReactiveCommand ShowApplyDiffCommand { get; } @@ -142,6 +143,18 @@ public ApplyControlViewModel(LoadoutId loadoutId, IServiceProvider serviceProvid .OnUI() .BindToVM(this, vm => vm.ApplyButtonText) .DisposeWith(disposables); + + // Perform an ingest on first load: + Observable.Return(0) + .Select(async _ => + { + if (_isFirstLoad && LastAppliedWithTxId.Id.Equals(_loadoutId)) + await Ingest(); + _isFirstLoad = false; + } + ) + .SubscribeWithErrorLogging() + .DisposeWith(disposables); } ); } @@ -155,4 +168,13 @@ await Task.Run(async () => }); } + private async Task Ingest() + { + await Task.Run(async () => + { + var loadout = _conn.Db.Get(_loadoutId); + await _applyService.Ingest(loadout.Installation); + }); + } + } From 1059b4343189e925ce4227e7982e0fe25c32aa8e Mon Sep 17 00:00:00 2001 From: AL <26797547+Al12rs@users.noreply.github.com> Date: Tue, 28 May 2024 14:12:14 +0200 Subject: [PATCH 2/2] Use Task run and refactor code --- .../LeftMenu/Items/ApplyControlViewModel.cs | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/NexusMods.App.UI/LeftMenu/Items/ApplyControlViewModel.cs b/src/NexusMods.App.UI/LeftMenu/Items/ApplyControlViewModel.cs index a841a466c7..dd9521a771 100644 --- a/src/NexusMods.App.UI/LeftMenu/Items/ApplyControlViewModel.cs +++ b/src/NexusMods.App.UI/LeftMenu/Items/ApplyControlViewModel.cs @@ -145,16 +145,7 @@ public ApplyControlViewModel(LoadoutId loadoutId, IServiceProvider serviceProvid .DisposeWith(disposables); // Perform an ingest on first load: - Observable.Return(0) - .Select(async _ => - { - if (_isFirstLoad && LastAppliedWithTxId.Id.Equals(_loadoutId)) - await Ingest(); - _isFirstLoad = false; - } - ) - .SubscribeWithErrorLogging() - .DisposeWith(disposables); + Task.Run(FirstLoadIngest); } ); } @@ -168,13 +159,17 @@ await Task.Run(async () => }); } - private async Task Ingest() + private async Task FirstLoadIngest() { - await Task.Run(async () => + if (_isFirstLoad) { - var loadout = _conn.Db.Get(_loadoutId); - await _applyService.Ingest(loadout.Installation); - }); + _isFirstLoad = false; + + if (LastAppliedWithTxId.Id.Equals(_loadoutId)) + { + var loadout = _conn.Db.Get(_loadoutId); + await _applyService.Ingest(loadout.Installation); + } + } } - }