diff --git a/Dalamud/Dalamud.cs b/Dalamud/Dalamud.cs index c191b3419..d7cfc33c9 100644 --- a/Dalamud/Dalamud.cs +++ b/Dalamud/Dalamud.cs @@ -250,6 +250,8 @@ namespace Dalamud try { + _ = pluginManager.SetPluginReposFromConfigAsync(false); + pluginManager.OnInstalledPluginsChanged += Troubleshooting.LogTroubleshooting; Log.Information("[T3] PM OK!"); diff --git a/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs index 9e8bcf913..1657c6597 100644 --- a/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs +++ b/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs @@ -67,7 +67,7 @@ namespace Dalamud.Interface.Internal.Windows private string errorModalMessage = string.Empty; private int updatePluginCount = 0; - private List updatedPlugins; + private List? updatedPlugins; private List pluginListAvailable = new(); private List pluginListInstalled = new(); @@ -163,7 +163,7 @@ namespace Dalamud.Interface.Internal.Windows { var pluginManager = Service.Get(); - Task.Run(pluginManager.ReloadPluginMasters); + _ = pluginManager.ReloadPluginMastersAsync(); this.updatePluginCount = 0; this.updatedPlugins = null; diff --git a/Dalamud/Interface/Internal/Windows/SettingsWindow.cs b/Dalamud/Interface/Internal/Windows/SettingsWindow.cs index e58790151..4d1ddec3e 100644 --- a/Dalamud/Interface/Internal/Windows/SettingsWindow.cs +++ b/Dalamud/Interface/Internal/Windows/SettingsWindow.cs @@ -529,7 +529,7 @@ namespace Dalamud.Interface.Internal.Windows if (this.thirdRepoListChanged) { - pluginManager.SetPluginReposFromConfig(true); + _ = pluginManager.SetPluginReposFromConfigAsync(true); this.thirdRepoListChanged = false; } @@ -602,7 +602,7 @@ namespace Dalamud.Interface.Internal.Windows configuration.Save(); - Service.Get().ReloadPluginMasters(); + _ = Service.Get().ReloadPluginMastersAsync(); } } } diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs index ae513ce85..50405778b 100644 --- a/Dalamud/Plugin/Internal/PluginManager.cs +++ b/Dalamud/Plugin/Internal/PluginManager.cs @@ -72,9 +72,7 @@ namespace Dalamud.Plugin.Internal this.PluginConfigs = new PluginConfigurations(Path.Combine(Path.GetDirectoryName(startInfo.ConfigurationPath) ?? string.Empty, "pluginConfigs")); var bannedPluginsJson = File.ReadAllText(Path.Combine(startInfo.AssetDirectory, "UIRes", "bannedplugin.json")); - this.bannedPlugins = JsonConvert.DeserializeObject(bannedPluginsJson); - - this.SetPluginReposFromConfig(false); + this.bannedPlugins = JsonConvert.DeserializeObject(bannedPluginsJson) ?? Array.Empty(); this.ApplyPatches(); } @@ -146,10 +144,12 @@ namespace Dalamud.Plugin.Internal } /// - /// Set the list of repositories to use. Should be called when the Settings window has been updated or at instantiation. + /// Set the list of repositories to use and downloads their contents. + /// Should be called when the Settings window has been updated or at instantiation. /// /// Whether the available plugins changed should be evented after. - public void SetPluginReposFromConfig(bool notify) + /// A representing the asynchronous operation. + public async Task SetPluginReposFromConfigAsync(bool notify) { var configuration = Service.Get(); @@ -162,6 +162,11 @@ namespace Dalamud.Plugin.Internal if (notify) this.NotifyAvailablePluginsChanged(); + + foreach (var repo in repos) + { + await repo.ReloadPluginMasterAsync(); + } } /// @@ -301,11 +306,15 @@ namespace Dalamud.Plugin.Internal /// /// Reload the PluginMaster for each repo, filter, and event that the list has updated. /// - public void ReloadPluginMasters() + /// A representing the asynchronous operation. + public async Task ReloadPluginMastersAsync() { - Task.WhenAll(this.Repos.Select(repo => repo.ReloadPluginMasterAsync())) - .ContinueWith(task => this.RefilterPluginMasters()) - .Wait(); + foreach (var repo in this.Repos) + { + await repo.ReloadPluginMasterAsync(); + } + + this.RefilterPluginMasters(); } /// diff --git a/Dalamud/Plugin/Internal/PluginRepository.cs b/Dalamud/Plugin/Internal/PluginRepository.cs index e05c2dea6..7e0ec8b4d 100644 --- a/Dalamud/Plugin/Internal/PluginRepository.cs +++ b/Dalamud/Plugin/Internal/PluginRepository.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Net.Http; @@ -29,8 +30,6 @@ namespace Dalamud.Plugin.Internal this.PluginMasterUrl = pluginMasterUrl; this.IsThirdParty = pluginMasterUrl != DalamudPluginsMasterUrl; this.IsEnabled = isEnabled; - - this.ReloadPluginMasterAsync(); } /// @@ -56,7 +55,7 @@ namespace Dalamud.Plugin.Internal /// /// Gets the plugin master list of available plugins. /// - public ReadOnlyCollection PluginMaster { get; private set; } + public ReadOnlyCollection? PluginMaster { get; private set; } /// /// Gets the initialization state of the plugin repository. @@ -67,12 +66,12 @@ namespace Dalamud.Plugin.Internal /// Reload the plugin master asynchronously in a task. /// /// The new state. - public Task ReloadPluginMasterAsync() + public async Task ReloadPluginMasterAsync() { this.State = PluginRepositoryState.InProgress; this.PluginMaster = new List().AsReadOnly(); - return Task.Run(async () => + try { Log.Information($"Fetching repo: {this.PluginMasterUrl}"); using var client = new HttpClient(); @@ -80,6 +79,12 @@ namespace Dalamud.Plugin.Internal var data = await response.Content.ReadAsStringAsync(); var pluginMaster = JsonConvert.DeserializeObject>(data); + + if (pluginMaster == null) + { + throw new Exception("Deserialized PluginMaster was null."); + } + pluginMaster.Sort((pm1, pm2) => pm1.Name.CompareTo(pm2.Name)); // Set the source for each remote manifest. Allows for checking if is 3rd party. @@ -89,19 +94,15 @@ namespace Dalamud.Plugin.Internal } this.PluginMaster = pluginMaster.AsReadOnly(); - }).ContinueWith(task => + + Log.Debug($"Successfully fetched repo: {this.PluginMasterUrl}"); + this.State = PluginRepositoryState.Success; + } + catch (Exception ex) { - if (task.IsCompletedSuccessfully) - { - Log.Debug($"Successfully fetched repo: {this.PluginMasterUrl}"); - this.State = PluginRepositoryState.Success; - } - else - { - Log.Error(task.Exception, $"PluginMaster failed: {this.PluginMasterUrl}"); - this.State = PluginRepositoryState.Fail; - } - }); + Log.Error(ex, $"PluginMaster failed: {this.PluginMasterUrl}"); + this.State = PluginRepositoryState.Fail; + } } } }