using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Wabbajack.Common; using Wabbajack.DTOs; using Wabbajack.Networking.WabbajackClientApi; using Wabbajack.Paths; namespace Wabbajack.App.Blazor.State; public class StateContainer : IStateContainer { private readonly ILogger _logger; private readonly Client _client; public StateContainer(ILogger logger, Client client) { _logger = logger; _client = client; } private ModlistMetadata[] _modlists = Array.Empty(); public IEnumerable Modlists => _modlists; public async Task LoadModlistMetadata() { try { var lists = await _client.LoadLists(); _modlists = lists; return _modlists.Any(); } catch (Exception e) { _logger.LogError(e, "Exception loading Modlists"); return false; } } private readonly CustomObservable _navigationAllowedObservable = new(true); public IObservable NavigationAllowedObservable => _navigationAllowedObservable; public bool NavigationAllowed { get => _navigationAllowedObservable.Value; set => _navigationAllowedObservable.Value = value; } private readonly CustomObservable _modlistPathObservable = new(AbsolutePath.Empty); public IObservable ModlistPathObservable => _modlistPathObservable; public AbsolutePath ModlistPath { get => _modlistPathObservable.Value; set => _modlistPathObservable.Value = value; } private readonly CustomObservable _installPathObservable = new(AbsolutePath.Empty); public IObservable InstallPathObservable => _installPathObservable; public AbsolutePath InstallPath { get => _installPathObservable.Value; set => _installPathObservable.Value = value; } private readonly CustomObservable _downloadPathObservable = new(AbsolutePath.Empty); public IObservable DownloadPathObservable => _downloadPathObservable; public AbsolutePath DownloadPath { get => _downloadPathObservable.Value; set => _downloadPathObservable.Value = value; } private readonly CustomObservable _modlistObservable = new(null); public IObservable ModlistObservable => _modlistObservable; public ModList? Modlist { get => _modlistObservable.Value; set => _modlistObservable.Value = value; } private readonly CustomObservable _modlistImageObservable = new(string.Empty); public IObservable ModlistImageObservable => _modlistImageObservable; public string? ModlistImage { get => _modlistImageObservable.Value; set => _modlistImageObservable.Value = value; } private readonly CustomObservable _installStateObservable = new(InstallState.Waiting); public IObservable InstallStateObservable => _installStateObservable; public InstallState InstallState { get => _installStateObservable.Value; set => _installStateObservable.Value = value; } private readonly CustomObservable _taskBarStateObservable = new(new TaskBarState()); public IObservable TaskBarStateObservable => _taskBarStateObservable; public TaskBarState TaskBarState { get => _taskBarStateObservable.Value; set => _taskBarStateObservable.Value = value; } }