Skip to content

Commit

Permalink
Show the release history in the extension update message box for each…
Browse files Browse the repository at this point in the history
… released version
  • Loading branch information
Reavert committed Apr 13, 2024
1 parent 236209e commit 6d52975
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions VisualStudioDiscordRPC.Shared/PackageController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using VisualStudioDiscordRPC.Shared.Nests;
using VisualStudioDiscordRPC.Shared.Utils;
using Newtonsoft.Json;
using System.Collections.Generic;

namespace VisualStudioDiscordRPC.Shared
{
Expand Down Expand Up @@ -54,7 +55,7 @@ public void Init()

if (updateNotificationsEnabled)
{
DisplayVersionUpdateMessage(currentExtensionVersion);
DisplayVersionUpdateMessage(previousVersion, currentExtensionVersion);
}
}
}
Expand Down Expand Up @@ -146,42 +147,47 @@ private void ApplySettings()
_discordRpcController.SetPlug<SecondButtonNest>(_plugService.GetPlugById<BaseButtonPlug>(secondButtonPlug));
}

private void DisplayVersionUpdateMessage(string version)
private void DisplayVersionUpdateMessage(string previousVersion, string currentVersion)
{
var releaseNotes = ReadReleaseNotesOfVersionRange(previousVersion, currentVersion);
var updateTextBuilder = new StringBuilder();
updateTextBuilder.AppendLine(string.Format(ConstantStrings.NewVersionNotification, version));

ReleaseNote currentVersionReleaseNote = ReadReleaseNoteOfVersion(version);
if (currentVersionReleaseNote != null)
updateTextBuilder.AppendLine(string.Format(ConstantStrings.NewVersionNotification, currentVersion));

foreach (var releaseNote in releaseNotes)
{
updateTextBuilder.AppendLine();
updateTextBuilder.AppendLine("Release notes: ");
updateTextBuilder.AppendLine($"Release notes of {releaseNote.Version}:");

string notesText = string.Join("\n",
currentVersionReleaseNote.Notes.Select(note => $" - {note}"));
string notesText = string.Join("\n",
releaseNote.Notes.Select(note => $" - {note}"));
updateTextBuilder.AppendLine(notesText);
}

MessageBox.Show(updateTextBuilder.ToString(), "Visual Studio Discord RPC Update",
MessageBoxButton.OK, MessageBoxImage.Information);
}

private ReleaseNote ReadReleaseNoteOfVersion(string version)
private List<ReleaseNote> ReadReleaseNotesOfVersionRange(string startVersionString, string endVersionString)
{
var result = new List<ReleaseNote>();

string releaseNotePath = PathHelper.GetPackageInstallationPath("RELEASE_NOTES.txt");
string releaseNotesText = File.ReadAllText(releaseNotePath);

var releaseNotesParser = new ReleaseNotesParser(releaseNotesText);

var startVersion = new Version(startVersionString);
var endVersion = new Version(endVersionString);

while (releaseNotesParser.ReadReleaseNote(out ReleaseNote releaseNote))
{
if (releaseNote.Version == version)
{
return releaseNote;
}
var version = new Version(releaseNote.Version);
if (version > startVersion && version <= endVersion)
result.Add(releaseNote);
}

return null;
return result;
}
}
}

0 comments on commit 6d52975

Please sign in to comment.