From 4dbecb1b5a720a0b2d2c2322043ec9ec32fd60c1 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Wed, 12 Jun 2024 14:14:25 +1000 Subject: [PATCH] allow preview plugin to override the AlwaysPreview setting --- Flow.Launcher.Core/Plugin/PluginManager.cs | 12 ++++++++++- .../Interfaces/IAsyncExternalPreview.cs | 9 ++++++++ Flow.Launcher/ViewModel/MainViewModel.cs | 21 ++++++++++++------- .../Flow.Launcher.Plugin.QuickLook/Main.cs | 2 ++ 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/PluginManager.cs b/Flow.Launcher.Core/Plugin/PluginManager.cs index 837de90f12b..a827e9e7ade 100644 --- a/Flow.Launcher.Core/Plugin/PluginManager.cs +++ b/Flow.Launcher.Core/Plugin/PluginManager.cs @@ -1,4 +1,4 @@ -using Flow.Launcher.Core.ExternalPlugins; +using Flow.Launcher.Core.ExternalPlugins; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -122,6 +122,16 @@ public static bool UseExternalPreview() return GetPluginsForInterface().Any(x => !x.Metadata.Disabled); } + public static bool AllowAlwaysPreview() + { + var plugin = GetPluginsForInterface().FirstOrDefault(x => !x.Metadata.Disabled); + + if (plugin is null) + return false; + + return ((IAsyncExternalPreview)plugin.Plugin).AllowAlwaysPreview(); + } + static PluginManager() { // validate user directory diff --git a/Flow.Launcher.Plugin/Interfaces/IAsyncExternalPreview.cs b/Flow.Launcher.Plugin/Interfaces/IAsyncExternalPreview.cs index 575a422d9d9..cc4f94c569c 100644 --- a/Flow.Launcher.Plugin/Interfaces/IAsyncExternalPreview.cs +++ b/Flow.Launcher.Plugin/Interfaces/IAsyncExternalPreview.cs @@ -27,5 +27,14 @@ public interface IAsyncExternalPreview : IFeatures /// The file path to switch the preview for /// Whether to send a toast message notification on failure for the user public Task SwitchPreviewAsync(string path, bool sendFailToast = true); + + /// + /// 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. + /// + /// + public bool AllowAlwaysPreview(); } } diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 58946fc4ce0..83ff6f064c4 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading; @@ -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; } } diff --git a/Plugins/Flow.Launcher.Plugin.QuickLook/Main.cs b/Plugins/Flow.Launcher.Plugin.QuickLook/Main.cs index 3696ca434c1..4388ad3d9a0 100644 --- a/Plugins/Flow.Launcher.Plugin.QuickLook/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.QuickLook/Main.cs @@ -39,6 +39,8 @@ public async Task OpenPreviewAsync(string path, bool sendFailToast = true) public async Task> QueryAsync(Query query, CancellationToken token) => new List(); + public bool AllowAlwaysPreview() => false; + public string GetTranslatedPluginTitle() { return Context.API.GetTranslation("plugin_name");