diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs index 88aef511d..08ec43cb2 100644 --- a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs +++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs @@ -135,6 +135,8 @@ internal class PluginInstallerWindow : Window, IDisposable private LoadingIndicatorKind loadingIndicatorKind = LoadingIndicatorKind.Unknown; private string verifiedCheckmarkHoveredPlugin = string.Empty; + + private string? staleDalamudNewVersion = null; /// /// Initializes a new instance of the class. @@ -292,6 +294,20 @@ internal class PluginInstallerWindow : Window, IDisposable } this.profileManagerWidget.Reset(); + + // TODO: Actually check if we are on a tag-0 version here. We might be opted into a beta but have a wrong key. + if (this.staleDalamudNewVersion == null && !Service.Get().DalamudBetaKind.IsNullOrEmpty()) + { + Service.Get().GetVersionForCurrentTrack().ContinueWith(t => + { + if (!t.IsCompletedSuccessfully) + return; + + var versionInfo = t.Result; + if (versionInfo.AssemblyVersion != Util.GetGitHash()) + this.staleDalamudNewVersion = versionInfo.AssemblyVersion; + }); + } } /// @@ -1488,8 +1504,7 @@ internal class PluginInstallerWindow : Window, IDisposable return; } - var pm = Service.Get(); - if (pm.SafeMode) + void DrawWarningIcon() { ImGuiHelpers.ScaledDummy(10); @@ -1498,15 +1513,34 @@ internal class PluginInstallerWindow : Window, IDisposable ImGuiHelpers.CenteredText(FontAwesomeIcon.ExclamationTriangle.ToIconString()); ImGui.PopFont(); ImGui.PopStyleColor(); - - var lines = Locs.SafeModeDisclaimer.Split('\n'); + } + + void DrawLinesCentered(string text) + { + var lines = text.Split('\n'); foreach (var line in lines) { ImGuiHelpers.CenteredText(line); } + } + + var pm = Service.Get(); + if (pm.SafeMode) + { + DrawWarningIcon(); + DrawLinesCentered(Locs.SafeModeDisclaimer); + + ImGuiHelpers.ScaledDummy(10); + } + + if (this.staleDalamudNewVersion != null) + { + DrawWarningIcon(); + DrawLinesCentered("A new version of Dalamud is available.\n" + + "Please restart the game to ensure compatibility with updated plugins.\n" + + $"old: {Util.GetGitHash()} new: {this.staleDalamudNewVersion}"); ImGuiHelpers.ScaledDummy(10); - ImGui.Separator(); } ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, ImGuiHelpers.ScaledVector2(1, 3)); diff --git a/Dalamud/Support/DalamudReleases.cs b/Dalamud/Support/DalamudReleases.cs new file mode 100644 index 000000000..15e851da2 --- /dev/null +++ b/Dalamud/Support/DalamudReleases.cs @@ -0,0 +1,71 @@ +using System.Diagnostics.CodeAnalysis; +using System.Threading.Tasks; + +using Dalamud.Configuration.Internal; +using Dalamud.Networking.Http; + +using Newtonsoft.Json; + +namespace Dalamud.Support; + +/// +/// Service for fetching Dalamud release information. +/// +[ServiceManager.EarlyLoadedService] +internal class DalamudReleases : IServiceType +{ + private const string VersionInfoUrl = "https://kamori.goats.dev/Dalamud/Release/VersionInfo?track={0}"; + + private readonly HappyHttpClient httpClient; + private readonly DalamudConfiguration config; + + /// + /// Initializes a new instance of the class. + /// + /// The shared HTTP client. + /// The Dalamud configuration. + [ServiceManager.ServiceConstructor] + public DalamudReleases(HappyHttpClient httpClient, DalamudConfiguration config) + { + this.httpClient = httpClient; + this.config = config; + } + + /// + /// Get the latest version info for the current track. + /// + /// The version info for the current track. + public async Task GetVersionForCurrentTrack() + { + var url = string.Format(VersionInfoUrl, [this.config.DalamudBetaKind]); + var response = await this.httpClient.SharedHttpClient.GetAsync(url); + response.EnsureSuccessStatusCode(); + var content = await response.Content.ReadAsStringAsync(); + return JsonConvert.DeserializeObject(content); + } + + [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented", Justification = "laziness")] + public class DalamudVersionInfo + { + [JsonProperty("key")] + public string? Key { get; set; } + + [JsonProperty("track")] + public string Track { get; set; } = null!; + + [JsonProperty("assemblyVersion")] + public string AssemblyVersion { get; set; } = null!; + + [JsonProperty("runtimeVersion")] + public string RuntimeVersion { get; set; } = null!; + + [JsonProperty("runtimeRequired")] + public bool RuntimeRequired { get; set; } + + [JsonProperty("supportedGameVer")] + public string SupportedGameVer { get; set; } = null!; + + [JsonProperty("isApplicableForCurrentGameVer")] + public bool IsApplicableForCurrentGameVer { get; set; } + } +}