add plugin support for external preview

This commit is contained in:
Jeremy 2024-05-28 21:27:48 +10:00
parent 29c150397e
commit 666211dd4c
2 changed files with 47 additions and 0 deletions

View file

@ -88,6 +88,38 @@ namespace Flow.Launcher.Core.Plugin
}).ToArray());
}
public static async Task OpenExternalPreviewAsync(string path, bool sendFailToast = true)
{
await Task.WhenAll(AllPlugins.Select(plugin => plugin.Plugin switch
{
IAsyncExternalPreview p => p.OpenPreviewAsync(path, sendFailToast),
_ => Task.CompletedTask,
}).ToArray());
}
public static async Task CloseExternalPreviewAsync()
{
await Task.WhenAll(AllPlugins.Select(plugin => plugin.Plugin switch
{
IAsyncExternalPreview p => p.ClosePreviewAsync(),
_ => Task.CompletedTask,
}).ToArray());
}
public static async Task SwitchExternalPreviewAsync(string path, bool sendFailToast = true)
{
await Task.WhenAll(AllPlugins.Select(plugin => plugin.Plugin switch
{
IAsyncExternalPreview p => p.SwitchPreviewAsync(path, sendFailToast),
_ => Task.CompletedTask,
}).ToArray());
}
public static bool UseExternalPreview()
{
return GetPluginsForInterface<IAsyncExternalPreview>().Any(x => !x.Metadata.Disabled);
}
static PluginManager()
{
// validate user directory

View file

@ -0,0 +1,15 @@
using System.Threading.Tasks;
namespace Flow.Launcher.Plugin
{
public interface IAsyncExternalPreview: IFeatures
{
public Task TogglePreviewAsync(string path);
public Task OpenPreviewAsync(string path, bool sendFailToast = true);
public Task ClosePreviewAsync();
public Task SwitchPreviewAsync(string path, bool sendFailToast = true);
}
}