Skip to content

Commit

Permalink
allow preview plugin to override the AlwaysPreview setting
Browse files Browse the repository at this point in the history
  • Loading branch information
jjw24 committed Jun 12, 2024
1 parent e6f0f28 commit 4dbecb1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
12 changes: 11 additions & 1 deletion Flow.Launcher.Core/Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Flow.Launcher.Core.ExternalPlugins;
using Flow.Launcher.Core.ExternalPlugins;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
Expand Down Expand Up @@ -122,6 +122,16 @@ public static bool UseExternalPreview()
return GetPluginsForInterface<IAsyncExternalPreview>().Any(x => !x.Metadata.Disabled);
}

public static bool AllowAlwaysPreview()
{
var plugin = GetPluginsForInterface<IAsyncExternalPreview>().FirstOrDefault(x => !x.Metadata.Disabled);

if (plugin is null)
return false;

return ((IAsyncExternalPreview)plugin.Plugin).AllowAlwaysPreview();
}

static PluginManager()
{
// validate user directory
Expand Down
9 changes: 9 additions & 0 deletions Flow.Launcher.Plugin/Interfaces/IAsyncExternalPreview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,14 @@ public interface IAsyncExternalPreview : IFeatures
/// <param name="path">The file path to switch the preview for</param>
/// <param name="sendFailToast">Whether to send a toast message notification on failure for the user</param>
public Task SwitchPreviewAsync(string path, bool sendFailToast = true);

/// <summary>
/// Allows the preview plugin to override the AlwaysPreview setting. Typically useful if plugin's preview does not
/// fully work well with being shown together when the query window appears with results.
/// When AlwaysPreview setting is on and this is set to false, the preview will not be shown when query
/// window appears with results, instead the internal preview will be shown.
/// </summary>
/// <returns></returns>
public bool AllowAlwaysPreview();
}
}
21 changes: 14 additions & 7 deletions Flow.Launcher/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
Expand Down Expand Up @@ -869,13 +869,20 @@ private void HideInternalPreview()

public void ResetPreview()
{
if (Settings.AlwaysPreview)
switch (Settings.AlwaysPreview)
{
ShowInternalPreview();
}
else
{
HidePreview();
case true
when PluginManager.AllowAlwaysPreview() && CanExternalPreviewSelectedResult(out var path):
OpenExternalPreview(path);
break;

case true:
ShowInternalPreview();
break;

case false:
HidePreview();
break;
}
}

Expand Down
2 changes: 2 additions & 0 deletions Plugins/Flow.Launcher.Plugin.QuickLook/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public async Task OpenPreviewAsync(string path, bool sendFailToast = true)

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

public bool AllowAlwaysPreview() => false;

public string GetTranslatedPluginTitle()
{
return Context.API.GetTranslation("plugin_name");
Expand Down

0 comments on commit 4dbecb1

Please sign in to comment.