fix plugins ui crashes
This commit is contained in:
@@ -11,7 +11,7 @@ namespace Torch.API.WebAPI.Plugin;
|
|||||||
|
|
||||||
public class LegacyPluginQuery : IPluginQuery
|
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 readonly HttpClient _client;
|
||||||
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
@@ -27,12 +27,12 @@ public class LegacyPluginQuery : IPluginQuery
|
|||||||
|
|
||||||
public async Task<PluginsResponse> QueryAll()
|
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)
|
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)
|
if (!res.IsSuccessStatusCode)
|
||||||
return null;
|
return null;
|
||||||
return await res.Content.ReadFromJsonAsync<PluginItem>();
|
return await res.Content.ReadFromJsonAsync<PluginItem>();
|
||||||
|
@@ -22,6 +22,7 @@ using Torch.Collections;
|
|||||||
using Torch.Server.Annotations;
|
using Torch.Server.Annotations;
|
||||||
using Torch.Managers;
|
using Torch.Managers;
|
||||||
using Torch.API.Managers;
|
using Torch.API.Managers;
|
||||||
|
using Torch.API.Plugins;
|
||||||
using Torch.API.WebAPI.Plugin;
|
using Torch.API.WebAPI.Plugin;
|
||||||
|
|
||||||
namespace Torch.Server.Views
|
namespace Torch.Server.Views
|
||||||
@@ -56,26 +57,28 @@ namespace Torch.Server.Views
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
var installedPlugins = pluginManager.Plugins;
|
var installedPlugins = pluginManager.Plugins;
|
||||||
BindingOperations.EnableCollectionSynchronization(Plugins, _syncLock);
|
LoadAsync(installedPlugins);
|
||||||
Task.Run(async () =>
|
|
||||||
|
MarkdownFlow.CommandBindings.Add(new CommandBinding(NavigationCommands.GoToPage, (sender, e) => OpenUri((string)e.Parameter)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void LoadAsync(IReadOnlyDictionary<Guid, ITorchPlugin> installedPlugins)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var res = await LegacyPluginQuery.Instance.QueryAll();
|
var res = await LegacyPluginQuery.Instance.QueryAll();
|
||||||
foreach (var item in res.Plugins.OrderBy(i => i.Name)) {
|
foreach (var item in res.Plugins.OrderBy(i => i.Name))
|
||||||
lock (_syncLock)
|
|
||||||
{
|
{
|
||||||
var pluginItem = item with
|
var pluginItem = item with
|
||||||
{
|
{
|
||||||
Description = item.Description.Replace("<", "<").Replace(">", ">"),
|
Description = item.Description?.Replace("<", "<").Replace(">", ">") ?? string.Empty,
|
||||||
Installed = installedPlugins.Keys.Contains(item.Id)
|
Installed = installedPlugins.Keys.Contains(item.Id)
|
||||||
};
|
};
|
||||||
Plugins.Add(pluginItem);
|
Plugins.Add(pluginItem);
|
||||||
PluginsSource.Add(pluginItem);
|
PluginsSource.Add(pluginItem);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Dispatcher.Invoke(() => PluginsList.SelectedIndex = 0);
|
PluginsList.SelectedIndex = 0;
|
||||||
CurrentDescription = "Please select a plugin...";
|
CurrentDescription = "Please select a plugin...";
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -84,9 +87,6 @@ namespace Torch.Server.Views
|
|||||||
Close();
|
Close();
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
MarkdownFlow.CommandBindings.Add(new CommandBinding(NavigationCommands.GoToPage, (sender, e) => OpenUri((string)e.Parameter)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsValidUri(string uri)
|
public static bool IsValidUri(string uri)
|
||||||
|
@@ -71,7 +71,7 @@ namespace Torch.Server.Views
|
|||||||
private void OpenFolder_OnClick(object sender, RoutedEventArgs e)
|
private void OpenFolder_OnClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (_plugins?.PluginDir != null)
|
if (_plugins?.PluginDir != null)
|
||||||
Process.Start(_plugins.PluginDir);
|
Process.Start("explorer", _plugins.PluginDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void BrowsPlugins_OnClick(object sender, RoutedEventArgs e)
|
private void BrowsPlugins_OnClick(object sender, RoutedEventArgs e)
|
||||||
|
Reference in New Issue
Block a user