Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions ObservatoryCore/PluginManagement/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
using Observatory.Utils;
using System.Data;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO.Compression;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Loader;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Runtime.Loader;
using System.IO.Compression;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;

namespace Observatory.PluginManagement
{
Expand Down Expand Up @@ -795,6 +796,8 @@ private void ReadDirectory(DirectoryInfo directory)

private class PluginPackage
{
private static readonly Regex VersionSuffixRegEx = new("-.*$");

internal PluginPackage(string filePath, bool includeLegacyDeps = false)
{
var bundle = new PluginBundle(filePath);
Expand Down Expand Up @@ -862,7 +865,8 @@ private void ProcessPluginManifest(PluginBundle bundle)

var nameAndVersion = pluginLibraryEntry.Key.Split('/') ?? ["No Library", "0"];
PluginName = nameAndVersion.First() ?? string.Empty;
Version = new Version(nameAndVersion.Last() ?? "0");
var versionWithoutSuffx = VersionSuffixRegEx.Replace(nameAndVersion.Last() ?? "0", "");
Version = new Version(versionWithoutSuffx);

foreach (var dependency in targets.Where(t => t.Key != pluginLibraryEntry.Key))
{
Expand Down
26 changes: 23 additions & 3 deletions ObservatoryCore/UI/PluginList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ internal class PluginList : TableLayoutPanel

internal PluginList(IEnumerable<IObservatoryPlugin> plugins)
{
SuspendLayout();

ColumnCount = 7;
_title = new()
{
Expand Down Expand Up @@ -62,6 +64,7 @@ Label createHeaderLabel(string text)
int row = 2;

var enabledPlugins = GetEnabledPlugins();
List<Task> updateTasks = new();

foreach (var plugin in plugins)
{
Expand Down Expand Up @@ -162,7 +165,7 @@ Label createLineLabel(string text)
AddWithLocation(pluginEnabled, row, 5);
AddWithLocation(pluginMenu, row, 6);

Task.Run(() =>
updateTasks.Add(new Task(() =>
{
var thisRow = row;
// Check for a plugin update.
Expand Down Expand Up @@ -198,15 +201,32 @@ Label createLineLabel(string text)
var startInfo = new ProcessStartInfo(updateInfo.Url ?? "https://observatory.xjph.net") { UseShellExecute = true };
Process.Start(startInfo);
};
AddWithLocation(updateLink, GetRow(pluginStatus), 4);
var row = GetRow(pluginStatus);
Controls.Remove(pluginStatus);
AddWithLocation(updateLink, row, 4);
}
});
}));

row++;
}

ResumeLayout();

Resize += PluginList_Resize;

// Avoid blocking the main thread by running one or more update tasks.
Task.Run(() =>
{
// Run the update tasks now that we've completely laid out the plugin list -- one at a time.
// This avoids the these tasks and the main thread trigging layout passes on the underlying TableLayoutPanel
// that end up conflicting with each other causing mysterious index-out-of-bounds and null errors deep
// within the Layout engine.
foreach (var t in updateTasks)
{
t.Start();
t.Wait();
}
});
}

private void PluginList_Resize(object? sender, EventArgs e)
Expand Down