mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
fix: Make auto-update work again, the lazy way (#1592)
* fix: Make auto-update work again, the lazy way. - Move auto-update to run on the first `Notice` message for parity with the welcome message. - Add some logging in a few critical places to make things nicer. * fix overzealous IDE complaints * code-review comments - Remove stray imports that the IDE included - Remove fixme to move auto-updates (for now) * Lazy retry auto-update
This commit is contained in:
parent
3c7900ea13
commit
86b7c29e94
3 changed files with 44 additions and 12 deletions
|
|
@ -2,6 +2,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using CheapLoc;
|
||||
|
|
@ -14,9 +15,9 @@ using Dalamud.Interface.Internal;
|
|||
using Dalamud.Interface.Internal.Notifications;
|
||||
using Dalamud.Interface.Internal.Windows;
|
||||
using Dalamud.Interface.Internal.Windows.PluginInstaller;
|
||||
using Dalamud.Logging.Internal;
|
||||
using Dalamud.Plugin.Internal;
|
||||
using Dalamud.Utility;
|
||||
using Serilog;
|
||||
|
||||
namespace Dalamud.Game;
|
||||
|
||||
|
|
@ -60,6 +61,8 @@ internal class ChatHandlers : IServiceType
|
|||
// { XivChatType.Echo, Color.Gray },
|
||||
// };
|
||||
|
||||
private static readonly ModuleLog Log = new("CHATHANDLER");
|
||||
|
||||
private readonly Regex rmtRegex = new(
|
||||
@"4KGOLD|We have sufficient stock|VPK\.OM|[Gg]il for free|[Gg]il [Cc]heap|5GOLD|www\.so9\.com|Fast & Convenient|Cheap & Safety Guarantee|【Code|A O A U E|igfans|4KGOLD\.COM|Cheapest Gil with|pvp and bank on google|Selling Cheap GIL|ff14mogstation\.com|Cheap Gil 1000k|gilsforyou|server 1000K =|gils_selling|E A S Y\.C O M|bonus code|mins delivery guarantee|Sell cheap|Salegm\.com|cheap Mog|Off Code:|FF14Mog.com|使用する5%オ|[Oo][Ff][Ff] [Cc]ode( *)[:;]|offers Fantasia",
|
||||
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
|
@ -110,6 +113,7 @@ internal class ChatHandlers : IServiceType
|
|||
|
||||
private bool hasSeenLoadingMsg;
|
||||
private bool startedAutoUpdatingPlugins;
|
||||
private CancellationTokenSource deferredAutoUpdateCts = new();
|
||||
|
||||
[ServiceManager.ServiceConstructor]
|
||||
private ChatHandlers(ChatGui chatGui)
|
||||
|
|
@ -165,16 +169,19 @@ internal class ChatHandlers : IServiceType
|
|||
if (clientState == null)
|
||||
return;
|
||||
|
||||
if (type == XivChatType.Notice && !this.hasSeenLoadingMsg)
|
||||
if (type == XivChatType.Notice)
|
||||
{
|
||||
if (!this.hasSeenLoadingMsg)
|
||||
this.PrintWelcomeMessage();
|
||||
|
||||
if (!this.startedAutoUpdatingPlugins)
|
||||
this.AutoUpdatePluginsWithRetry();
|
||||
}
|
||||
|
||||
// For injections while logged in
|
||||
if (clientState.LocalPlayer != null && clientState.TerritoryType == 0 && !this.hasSeenLoadingMsg)
|
||||
this.PrintWelcomeMessage();
|
||||
|
||||
if (!this.startedAutoUpdatingPlugins)
|
||||
this.AutoUpdatePlugins();
|
||||
|
||||
#if !DEBUG && false
|
||||
if (!this.hasSeenLoadingMsg)
|
||||
return;
|
||||
|
|
@ -264,24 +271,42 @@ internal class ChatHandlers : IServiceType
|
|||
this.hasSeenLoadingMsg = true;
|
||||
}
|
||||
|
||||
private void AutoUpdatePlugins()
|
||||
private void AutoUpdatePluginsWithRetry()
|
||||
{
|
||||
var firstAttempt = this.AutoUpdatePlugins();
|
||||
if (!firstAttempt)
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
Task.Delay(30_000, this.deferredAutoUpdateCts.Token);
|
||||
this.AutoUpdatePlugins();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private bool AutoUpdatePlugins()
|
||||
{
|
||||
var chatGui = Service<ChatGui>.GetNullable();
|
||||
var pluginManager = Service<PluginManager>.GetNullable();
|
||||
var notifications = Service<NotificationManager>.GetNullable();
|
||||
|
||||
if (chatGui == null || pluginManager == null || notifications == null)
|
||||
return;
|
||||
{
|
||||
Log.Warning("Aborting auto-update because a required service was not loaded.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!pluginManager.ReposReady || !pluginManager.InstalledPlugins.Any() || !pluginManager.AvailablePlugins.Any())
|
||||
{
|
||||
// Plugins aren't ready yet.
|
||||
// TODO: We should retry. This sucks, because it means we won't ever get here again until another notice.
|
||||
return;
|
||||
Log.Warning("Aborting auto-update because plugins weren't loaded or ready.");
|
||||
return false;
|
||||
}
|
||||
|
||||
this.startedAutoUpdatingPlugins = true;
|
||||
|
||||
Log.Debug("Beginning plugin auto-update process...");
|
||||
Task.Run(() => pluginManager.UpdatePluginsAsync(true, !this.configuration.AutoUpdatePlugins, true)).ContinueWith(task =>
|
||||
{
|
||||
this.IsAutoUpdateComplete = true;
|
||||
|
|
@ -320,5 +345,7 @@ internal class ChatHandlers : IServiceType
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@ public static class ImGuiHelpers
|
|||
/// This does not necessarily mean you can call drawing functions.
|
||||
/// </summary>
|
||||
public static unsafe bool IsImGuiInitialized =>
|
||||
ImGui.GetCurrentContext() is not 0 && ImGui.GetIO().NativePtr is not null;
|
||||
ImGui.GetCurrentContext() is not (nint)0 // KW: IDEs get mad without the cast, despite being unnecessary
|
||||
&& ImGui.GetIO().NativePtr is not null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the global Dalamud scale; even available before drawing is ready.<br />
|
||||
|
|
|
|||
|
|
@ -958,7 +958,7 @@ internal partial class PluginManager : IDisposable, IServiceType
|
|||
autoUpdate ? PluginListInvalidationKind.AutoUpdate : PluginListInvalidationKind.Update,
|
||||
updatedList.Select(x => x.InternalName));
|
||||
|
||||
Log.Information("Plugin update OK.");
|
||||
Log.Information("Plugin update OK. {updateCount} plugins updated.", updatedList.Length);
|
||||
|
||||
return updatedList;
|
||||
}
|
||||
|
|
@ -1581,6 +1581,8 @@ internal partial class PluginManager : IDisposable, IServiceType
|
|||
|
||||
private void DetectAvailablePluginUpdates()
|
||||
{
|
||||
Log.Debug("Starting plugin update check...");
|
||||
|
||||
lock (this.pluginListLock)
|
||||
{
|
||||
this.updatablePluginsList.Clear();
|
||||
|
|
@ -1615,6 +1617,8 @@ internal partial class PluginManager : IDisposable, IServiceType
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
Log.Debug("Update check found {updateCount} available updates.", this.updatablePluginsList.Count);
|
||||
}
|
||||
|
||||
private void NotifyAvailablePluginsChanged()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue