fix plugins ui crashes
This commit is contained in:
@@ -11,7 +11,7 @@ namespace Torch.API.WebAPI.Plugin;
|
||||
|
||||
public class LegacyPluginQuery : IPluginQuery
|
||||
{
|
||||
private const string BASE_URL = "https://torchapi.com/api/plugins/";
|
||||
private const string BASE_URL = "https://torchapi.com/";
|
||||
private readonly HttpClient _client;
|
||||
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
@@ -27,12 +27,12 @@ public class LegacyPluginQuery : IPluginQuery
|
||||
|
||||
public async Task<PluginsResponse> QueryAll()
|
||||
{
|
||||
return await _client.GetFromJsonAsync<PluginsResponse>("/", CancellationToken.None);
|
||||
return await _client.GetFromJsonAsync<PluginsResponse>("/api/plugins/", CancellationToken.None);
|
||||
}
|
||||
|
||||
public async Task<PluginItem> QueryOne(Guid guid)
|
||||
{
|
||||
using var res = await _client.GetAsync($"/search/{guid}");
|
||||
using var res = await _client.GetAsync($"/api/plugins/search/{guid}");
|
||||
if (!res.IsSuccessStatusCode)
|
||||
return null;
|
||||
return await res.Content.ReadFromJsonAsync<PluginItem>();
|
||||
|
@@ -22,6 +22,7 @@ using Torch.Collections;
|
||||
using Torch.Server.Annotations;
|
||||
using Torch.Managers;
|
||||
using Torch.API.Managers;
|
||||
using Torch.API.Plugins;
|
||||
using Torch.API.WebAPI.Plugin;
|
||||
|
||||
namespace Torch.Server.Views
|
||||
@@ -56,39 +57,38 @@ namespace Torch.Server.Views
|
||||
InitializeComponent();
|
||||
|
||||
var installedPlugins = pluginManager.Plugins;
|
||||
BindingOperations.EnableCollectionSynchronization(Plugins, _syncLock);
|
||||
Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var res = await LegacyPluginQuery.Instance.QueryAll();
|
||||
foreach (var item in res.Plugins.OrderBy(i => i.Name)) {
|
||||
lock (_syncLock)
|
||||
{
|
||||
var pluginItem = item with
|
||||
{
|
||||
Description = item.Description.Replace("<", "<").Replace(">", ">"),
|
||||
Installed = installedPlugins.Keys.Contains(item.Id)
|
||||
};
|
||||
Plugins.Add(pluginItem);
|
||||
PluginsSource.Add(pluginItem);
|
||||
}
|
||||
}
|
||||
|
||||
Dispatcher.Invoke(() => PluginsList.SelectedIndex = 0);
|
||||
CurrentDescription = "Please select a plugin...";
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MessageBox.Show(e.ToString(), "An Error Occurred", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
Close();
|
||||
throw;
|
||||
}
|
||||
});
|
||||
LoadAsync(installedPlugins);
|
||||
|
||||
MarkdownFlow.CommandBindings.Add(new CommandBinding(NavigationCommands.GoToPage, (sender, e) => OpenUri((string)e.Parameter)));
|
||||
}
|
||||
|
||||
private async void LoadAsync(IReadOnlyDictionary<Guid, ITorchPlugin> installedPlugins)
|
||||
{
|
||||
try
|
||||
{
|
||||
var res = await LegacyPluginQuery.Instance.QueryAll();
|
||||
foreach (var item in res.Plugins.OrderBy(i => i.Name))
|
||||
{
|
||||
var pluginItem = item with
|
||||
{
|
||||
Description = item.Description?.Replace("<", "<").Replace(">", ">") ?? string.Empty,
|
||||
Installed = installedPlugins.Keys.Contains(item.Id)
|
||||
};
|
||||
Plugins.Add(pluginItem);
|
||||
PluginsSource.Add(pluginItem);
|
||||
}
|
||||
|
||||
PluginsList.SelectedIndex = 0;
|
||||
CurrentDescription = "Please select a plugin...";
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MessageBox.Show(e.ToString(), "An Error Occurred", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
Close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsValidUri(string uri)
|
||||
{
|
||||
if (!Uri.IsWellFormedUriString(uri, UriKind.Absolute))
|
||||
|
@@ -71,7 +71,7 @@ namespace Torch.Server.Views
|
||||
private void OpenFolder_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_plugins?.PluginDir != null)
|
||||
Process.Start(_plugins.PluginDir);
|
||||
Process.Start("explorer", _plugins.PluginDir);
|
||||
}
|
||||
|
||||
private void BrowsPlugins_OnClick(object sender, RoutedEventArgs e)
|
||||
|
Reference in New Issue
Block a user