pi: show a warning if a non-release dalamud version is outdated

This commit is contained in:
goat 2024-07-08 20:57:47 +02:00
parent baa875f516
commit 10f9f0b37b
2 changed files with 110 additions and 5 deletions

View file

@ -136,6 +136,8 @@ internal class PluginInstallerWindow : Window, IDisposable
private string verifiedCheckmarkHoveredPlugin = string.Empty;
private string? staleDalamudNewVersion = null;
/// <summary>
/// Initializes a new instance of the <see cref="PluginInstallerWindow"/> class.
/// </summary>
@ -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<DalamudConfiguration>.Get().DalamudBetaKind.IsNullOrEmpty())
{
Service<DalamudReleases>.Get().GetVersionForCurrentTrack().ContinueWith(t =>
{
if (!t.IsCompletedSuccessfully)
return;
var versionInfo = t.Result;
if (versionInfo.AssemblyVersion != Util.GetGitHash())
this.staleDalamudNewVersion = versionInfo.AssemblyVersion;
});
}
}
/// <inheritdoc/>
@ -1488,8 +1504,7 @@ internal class PluginInstallerWindow : Window, IDisposable
return;
}
var pm = Service<PluginManager>.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<PluginManager>.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));

View file

@ -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;
/// <summary>
/// Service for fetching Dalamud release information.
/// </summary>
[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;
/// <summary>
/// Initializes a new instance of the <see cref="DalamudReleases"/> class.
/// </summary>
/// <param name="httpClient">The shared HTTP client.</param>
/// <param name="config">The Dalamud configuration.</param>
[ServiceManager.ServiceConstructor]
public DalamudReleases(HappyHttpClient httpClient, DalamudConfiguration config)
{
this.httpClient = httpClient;
this.config = config;
}
/// <summary>
/// Get the latest version info for the current track.
/// </summary>
/// <returns>The version info for the current track.</returns>
public async Task<DalamudVersionInfo> 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<DalamudVersionInfo>(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; }
}
}