Skip to content

Commit 666211d

Browse files
committed
add plugin support for external preview
1 parent 29c1503 commit 666211d

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,38 @@ public static async Task ReloadDataAsync()
8888
}).ToArray());
8989
}
9090

91+
public static async Task OpenExternalPreviewAsync(string path, bool sendFailToast = true)
92+
{
93+
await Task.WhenAll(AllPlugins.Select(plugin => plugin.Plugin switch
94+
{
95+
IAsyncExternalPreview p => p.OpenPreviewAsync(path, sendFailToast),
96+
_ => Task.CompletedTask,
97+
}).ToArray());
98+
}
99+
100+
public static async Task CloseExternalPreviewAsync()
101+
{
102+
await Task.WhenAll(AllPlugins.Select(plugin => plugin.Plugin switch
103+
{
104+
IAsyncExternalPreview p => p.ClosePreviewAsync(),
105+
_ => Task.CompletedTask,
106+
}).ToArray());
107+
}
108+
109+
public static async Task SwitchExternalPreviewAsync(string path, bool sendFailToast = true)
110+
{
111+
await Task.WhenAll(AllPlugins.Select(plugin => plugin.Plugin switch
112+
{
113+
IAsyncExternalPreview p => p.SwitchPreviewAsync(path, sendFailToast),
114+
_ => Task.CompletedTask,
115+
}).ToArray());
116+
}
117+
118+
public static bool UseExternalPreview()
119+
{
120+
return GetPluginsForInterface<IAsyncExternalPreview>().Any(x => !x.Metadata.Disabled);
121+
}
122+
91123
static PluginManager()
92124
{
93125
// validate user directory
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Threading.Tasks;
2+
3+
namespace Flow.Launcher.Plugin
4+
{
5+
public interface IAsyncExternalPreview: IFeatures
6+
{
7+
public Task TogglePreviewAsync(string path);
8+
9+
public Task OpenPreviewAsync(string path, bool sendFailToast = true);
10+
11+
public Task ClosePreviewAsync();
12+
13+
public Task SwitchPreviewAsync(string path, bool sendFailToast = true);
14+
}
15+
}

0 commit comments

Comments
 (0)