Merge pull request #557 from goatcorp/autoUpdate

AutoUpdate plugins when pluginManager is ready
This commit is contained in:
goaaats 2021-09-13 06:13:47 +02:00 committed by GitHub
commit 3985d3eadd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -106,6 +106,7 @@ namespace Dalamud.Game
private readonly DalamudLinkPayload openInstallerWindowLink; private readonly DalamudLinkPayload openInstallerWindowLink;
private bool hasSeenLoadingMsg; private bool hasSeenLoadingMsg;
private bool hasAutoUpdatedPlugins;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ChatHandlers"/> class. /// Initializes a new instance of the <see cref="ChatHandlers"/> class.
@ -181,6 +182,9 @@ namespace Dalamud.Game
if (clientState.LocalPlayer != null && clientState.TerritoryType == 0 && !this.hasSeenLoadingMsg) if (clientState.LocalPlayer != null && clientState.TerritoryType == 0 && !this.hasSeenLoadingMsg)
this.PrintWelcomeMessage(); this.PrintWelcomeMessage();
if (!this.hasAutoUpdatedPlugins)
this.AutoUpdatePlugins();
#if !DEBUG && false #if !DEBUG && false
if (!this.hasSeenLoadingMsg) if (!this.hasSeenLoadingMsg)
return; return;
@ -231,7 +235,6 @@ namespace Dalamud.Game
var configuration = Service<DalamudConfiguration>.Get(); var configuration = Service<DalamudConfiguration>.Get();
var pluginManager = Service<PluginManager>.Get(); var pluginManager = Service<PluginManager>.Get();
var dalamudInterface = Service<DalamudInterface>.Get(); var dalamudInterface = Service<DalamudInterface>.Get();
var notifications = Service<NotificationManager>.Get();
var assemblyVersion = Assembly.GetAssembly(typeof(ChatHandlers)).GetName().Version.ToString(); var assemblyVersion = Assembly.GetAssembly(typeof(ChatHandlers)).GetName().Version.ToString();
@ -261,17 +264,33 @@ namespace Dalamud.Game
configuration.Save(); configuration.Save();
} }
Task.Run(() => pluginManager.UpdatePluginsAsync(!configuration.AutoUpdatePlugins)) this.hasSeenLoadingMsg = true;
.ContinueWith(t =>
{
if (t.IsFaulted)
{
Log.Error(t.Exception, Loc.Localize("DalamudPluginUpdateCheckFail", "Could not check for plugin updates."));
} }
else
{
var updatedPlugins = t.Result;
private void AutoUpdatePlugins()
{
var chatGui = Service<ChatGui>.Get();
var configuration = Service<DalamudConfiguration>.Get();
var pluginManager = Service<PluginManager>.Get();
var notifications = Service<NotificationManager>.Get();
if (!pluginManager.ReposReady || pluginManager.InstalledPlugins.Count == 0 || pluginManager.AvailablePlugins.Count == 0)
{
// Plugins aren't ready yet.
return;
}
this.hasAutoUpdatedPlugins = true;
Task.Run(() => pluginManager.UpdatePluginsAsync(!configuration.AutoUpdatePlugins)).ContinueWith(task =>
{
if (task.IsFaulted)
{
Log.Error(task.Exception, Loc.Localize("DalamudPluginUpdateCheckFail", "Could not check for plugin updates."));
return;
}
var updatedPlugins = task.Result;
if (updatedPlugins != null && updatedPlugins.Any()) if (updatedPlugins != null && updatedPlugins.Any())
{ {
if (configuration.AutoUpdatePlugins) if (configuration.AutoUpdatePlugins)
@ -300,10 +319,7 @@ namespace Dalamud.Game
}); });
} }
} }
}
}); });
this.hasSeenLoadingMsg = true;
} }
} }
} }