From e8f8ad61b5da51ac325e837f5ed721f81b892674 Mon Sep 17 00:00:00 2001 From: Raymond Date: Sun, 12 Sep 2021 21:04:33 -0400 Subject: [PATCH] AutoUpdate plugins when pluginManager is ready --- Dalamud/Game/ChatHandlers.cs | 66 ++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/Dalamud/Game/ChatHandlers.cs b/Dalamud/Game/ChatHandlers.cs index 78dc3fc63..a3bb09e06 100644 --- a/Dalamud/Game/ChatHandlers.cs +++ b/Dalamud/Game/ChatHandlers.cs @@ -106,6 +106,7 @@ namespace Dalamud.Game private readonly DalamudLinkPayload openInstallerWindowLink; private bool hasSeenLoadingMsg; + private bool hasAutoUpdatedPlugins; /// /// Initializes a new instance of the class. @@ -181,6 +182,9 @@ namespace Dalamud.Game if (clientState.LocalPlayer != null && clientState.TerritoryType == 0 && !this.hasSeenLoadingMsg) this.PrintWelcomeMessage(); + if (!this.hasAutoUpdatedPlugins) + this.AutoUpdatePlugins(); + #if !DEBUG && false if (!this.hasSeenLoadingMsg) return; @@ -253,7 +257,6 @@ namespace Dalamud.Game var configuration = Service.Get(); var pluginManager = Service.Get(); var dalamudInterface = Service.Get(); - var notifications = Service.Get(); var assemblyVersion = Assembly.GetAssembly(typeof(ChatHandlers)).GetName().Version.ToString(); @@ -283,31 +286,47 @@ namespace Dalamud.Game configuration.Save(); } - Task.Run(() => pluginManager.UpdatePluginsAsync(!configuration.AutoUpdatePlugins)) - .ContinueWith(t => + this.hasSeenLoadingMsg = true; + } + + private void AutoUpdatePlugins() + { + var chatGui = Service.Get(); + var configuration = Service.Get(); + var pluginManager = Service.Get(); + var notifications = Service.Get(); + + if (!pluginManager.ReposReady || pluginManager.InstalledPlugins.Count == 0 || pluginManager.AvailablePlugins.Count == 0) { - if (t.IsFaulted) + // Plugins aren't ready yet. + return; + } + + this.hasAutoUpdatedPlugins = true; + + Task.Run(() => pluginManager.UpdatePluginsAsync(!configuration.AutoUpdatePlugins)).ContinueWith(task => + { + if (task.IsFaulted) { - Log.Error(t.Exception, Loc.Localize("DalamudPluginUpdateCheckFail", "Could not check for plugin updates.")); + Log.Error(task.Exception, Loc.Localize("DalamudPluginUpdateCheckFail", "Could not check for plugin updates.")); + return; } - else + + var updatedPlugins = task.Result; + if (updatedPlugins != null && updatedPlugins.Any()) { - var updatedPlugins = t.Result; - - if (updatedPlugins != null && updatedPlugins.Any()) + if (configuration.AutoUpdatePlugins) { - if (configuration.AutoUpdatePlugins) - { - pluginManager.PrintUpdatedPlugins(updatedPlugins, Loc.Localize("DalamudPluginAutoUpdate", "Auto-update:")); - notifications.AddNotification(Loc.Localize("NotificationUpdatedPlugins", "{0} of your plugins were updated.").Format(updatedPlugins.Count), Loc.Localize("NotificationAutoUpdate", "Auto-Update"), NotificationType.Info); - } - else - { - var data = Service.Get(); + pluginManager.PrintUpdatedPlugins(updatedPlugins, Loc.Localize("DalamudPluginAutoUpdate", "Auto-update:")); + notifications.AddNotification(Loc.Localize("NotificationUpdatedPlugins", "{0} of your plugins were updated.").Format(updatedPlugins.Count), Loc.Localize("NotificationAutoUpdate", "Auto-Update"), NotificationType.Info); + } + else + { + var data = Service.Get(); - chatGui.PrintChat(new XivChatEntry - { - Message = new SeString(new List() + chatGui.PrintChat(new XivChatEntry + { + Message = new SeString(new List() { new TextPayload(Loc.Localize("DalamudPluginUpdateRequired", "One or more of your plugins needs to be updated. Please use the /xlplugins command in-game to update them!")), new TextPayload(" ["), @@ -318,14 +337,11 @@ namespace Dalamud.Game new UIForegroundPayload(0), new TextPayload("]"), }), - Type = XivChatType.Urgent, - }); - } + Type = XivChatType.Urgent, + }); } } }); - - this.hasSeenLoadingMsg = true; } } }