Skip to content

Commit 4dbecb1

Browse files
committed
allow preview plugin to override the AlwaysPreview setting
1 parent e6f0f28 commit 4dbecb1

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Flow.Launcher.Core.ExternalPlugins;
1+
using Flow.Launcher.Core.ExternalPlugins;
22
using System;
33
using System.Collections.Concurrent;
44
using System.Collections.Generic;
@@ -122,6 +122,16 @@ public static bool UseExternalPreview()
122122
return GetPluginsForInterface<IAsyncExternalPreview>().Any(x => !x.Metadata.Disabled);
123123
}
124124

125+
public static bool AllowAlwaysPreview()
126+
{
127+
var plugin = GetPluginsForInterface<IAsyncExternalPreview>().FirstOrDefault(x => !x.Metadata.Disabled);
128+
129+
if (plugin is null)
130+
return false;
131+
132+
return ((IAsyncExternalPreview)plugin.Plugin).AllowAlwaysPreview();
133+
}
134+
125135
static PluginManager()
126136
{
127137
// validate user directory

Flow.Launcher.Plugin/Interfaces/IAsyncExternalPreview.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,14 @@ public interface IAsyncExternalPreview : IFeatures
2727
/// <param name="path">The file path to switch the preview for</param>
2828
/// <param name="sendFailToast">Whether to send a toast message notification on failure for the user</param>
2929
public Task SwitchPreviewAsync(string path, bool sendFailToast = true);
30+
31+
/// <summary>
32+
/// Allows the preview plugin to override the AlwaysPreview setting. Typically useful if plugin's preview does not
33+
/// fully work well with being shown together when the query window appears with results.
34+
/// When AlwaysPreview setting is on and this is set to false, the preview will not be shown when query
35+
/// window appears with results, instead the internal preview will be shown.
36+
/// </summary>
37+
/// <returns></returns>
38+
public bool AllowAlwaysPreview();
3039
}
3140
}

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Threading;
@@ -869,13 +869,20 @@ private void HideInternalPreview()
869869

870870
public void ResetPreview()
871871
{
872-
if (Settings.AlwaysPreview)
872+
switch (Settings.AlwaysPreview)
873873
{
874-
ShowInternalPreview();
875-
}
876-
else
877-
{
878-
HidePreview();
874+
case true
875+
when PluginManager.AllowAlwaysPreview() && CanExternalPreviewSelectedResult(out var path):
876+
OpenExternalPreview(path);
877+
break;
878+
879+
case true:
880+
ShowInternalPreview();
881+
break;
882+
883+
case false:
884+
HidePreview();
885+
break;
879886
}
880887
}
881888

Plugins/Flow.Launcher.Plugin.QuickLook/Main.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public async Task OpenPreviewAsync(string path, bool sendFailToast = true)
3939

4040
public async Task<List<Result>> QueryAsync(Query query, CancellationToken token) => new List<Result>();
4141

42+
public bool AllowAlwaysPreview() => false;
43+
4244
public string GetTranslatedPluginTitle()
4345
{
4446
return Context.API.GetTranslation("plugin_name");

0 commit comments

Comments
 (0)