mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-31 21:03:43 +01:00
refactor: clean up async logic for PluginMaster loads
This commit is contained in:
parent
bd48297745
commit
86d9f01877
5 changed files with 42 additions and 30 deletions
|
|
@ -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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -56,7 +55,7 @@ namespace Dalamud.Plugin.Internal
|
|||
/// <summary>
|
||||
/// Gets the plugin master list of available plugins.
|
||||
/// </summary>
|
||||
public ReadOnlyCollection<RemotePluginManifest> PluginMaster { get; private set; }
|
||||
public ReadOnlyCollection<RemotePluginManifest>? PluginMaster { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the initialization state of the plugin repository.
|
||||
|
|
@ -67,12 +66,12 @@ namespace Dalamud.Plugin.Internal
|
|||
/// Reload the plugin master asynchronously in a task.
|
||||
/// </summary>
|
||||
/// <returns>The new state.</returns>
|
||||
public Task ReloadPluginMasterAsync()
|
||||
public async Task ReloadPluginMasterAsync()
|
||||
{
|
||||
this.State = PluginRepositoryState.InProgress;
|
||||
this.PluginMaster = new List<RemotePluginManifest>().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<List<RemotePluginManifest>>(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue