From 666211dd4cecae901f0a5509447fc07e2a72feaa Mon Sep 17 00:00:00 2001 From: Jeremy Date: Tue, 28 May 2024 21:27:48 +1000 Subject: [PATCH 1/4] add plugin support for external preview --- Flow.Launcher.Core/Plugin/PluginManager.cs | 32 +++++++++++++++++++ .../Interfaces/IAsyncExternalPreview.cs | 15 +++++++++ 2 files changed, 47 insertions(+) create mode 100644 Flow.Launcher.Plugin/Interfaces/IAsyncExternalPreview.cs diff --git a/Flow.Launcher.Core/Plugin/PluginManager.cs b/Flow.Launcher.Core/Plugin/PluginManager.cs index f8c9a3f17..5d6751507 100644 --- a/Flow.Launcher.Core/Plugin/PluginManager.cs +++ b/Flow.Launcher.Core/Plugin/PluginManager.cs @@ -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().Any(x => !x.Metadata.Disabled); + } + static PluginManager() { // validate user directory diff --git a/Flow.Launcher.Plugin/Interfaces/IAsyncExternalPreview.cs b/Flow.Launcher.Plugin/Interfaces/IAsyncExternalPreview.cs new file mode 100644 index 000000000..9ee05b46c --- /dev/null +++ b/Flow.Launcher.Plugin/Interfaces/IAsyncExternalPreview.cs @@ -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); + } +} From 8da1313e5ff4e1a6cbe9ecb334f5262c672f71c8 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Tue, 28 May 2024 21:31:29 +1000 Subject: [PATCH 2/4] update external preview methods to use the external preview interface --- Flow.Launcher/ViewModel/MainViewModel.cs | 35 ++++++------------------ 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 050b9ff09..c408a5176 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; @@ -614,38 +614,21 @@ namespace Flow.Launcher.ViewModel } } - private async Task ToggleExternalPreviewAsync(string path) + private void OpenExternalPreview(string path, bool sendFailToast = true) { - bool success = await QuickLookHelper.ToggleQuickLookAsync(path).ConfigureAwait(false); - if (success) - { - ExternalPreviewOpen = !ExternalPreviewOpen; - } + _ = PluginManager.OpenExternalPreviewAsync(path, sendFailToast).ConfigureAwait(false); + ExternalPreviewVisible = true; } - private async Task OpenExternalPreviewAsync(string path, bool sendFailToast = true) + private void CloseExternalPreview() { - bool success = await QuickLookHelper.OpenQuickLookAsync(path, sendFailToast).ConfigureAwait(false); - if (success) - { - ExternalPreviewOpen = false; - } + _ = PluginManager.CloseExternalPreviewAsync().ConfigureAwait(false); + ExternalPreviewVisible = false; } - private async Task CloseExternalPreviewAsync() + private void SwitchExternalPreview(string path, bool sendFailToast = true) { - bool success = await QuickLookHelper.CloseQuickLookAsync().ConfigureAwait(false); - if (success) - { - ExternalPreviewOpen = false; - } - } - - private async Task SwitchExternalPreviewAsync(string path, bool sendFailToast = true) - { - // Switches preview content - // When external is off, do nothing - _ = QuickLookHelper.SwitchQuickLookAsync(path, sendFailToast).ConfigureAwait(false); + _ = PluginManager.SwitchExternalPreviewAsync(path,sendFailToast).ConfigureAwait(false); } private void ShowInternalPreview() From 587536f0f5edb5a222e66839f6818bdc71779459 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Tue, 28 May 2024 21:38:02 +1000 Subject: [PATCH 3/4] updated PreviewVisible logic to base on ResultAreaColumn size --- Flow.Launcher/ViewModel/MainViewModel.cs | 36 +++++++++++++++--------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index c408a5176..c58aa9c72 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -572,25 +572,35 @@ namespace Flow.Launcher.ViewModel public string Image => Constant.QueryTextBoxIconImagePath; public bool StartWithEnglishMode => Settings.AlwaysStartEn; - - public bool PreviewVisible { get; set; } = false; - - public int ResultAreaColumn { get; set; } = 1; - + #endregion #region Preview - // Not accurate - public bool ExternalPreviewOpen { get; set; } = false; - - [RelayCommand] - private void TogglePreview() + public bool InternalPreviewVisible { - if (PreviewVisible) + get { - // To deal with always preview - HideInternalPreview(); + if (ResultAreaColumn == ResultAreaColumnPreviewShown) + return true; + + if (ResultAreaColumn == ResultAreaColumnPreviewHidden) + return false; +#if DEBUG + throw new NotImplementedException("ResultAreaColumn should match ResultAreaColumnPreviewShown/ResultAreaColumnPreviewHidden value"); +#else + Log.Error("MainViewModel", "ResultAreaColumnPreviewHidden/ResultAreaColumnPreviewShown int value not implemented", "InternalPreviewVisible"); +#endif + return false; + } + } + + private static readonly int ResultAreaColumnPreviewShown = 1; + + private static readonly int ResultAreaColumnPreviewHidden = 3; + + public int ResultAreaColumn { get; set; } = ResultAreaColumnPreviewShown; + } else if(Settings.UseExternalPreview && CanExternalPreviewSelectedResult(out var path)) { From 53e4bbb22b327535e147d1a08be784c9aadb1ada Mon Sep 17 00:00:00 2001 From: Jeremy Date: Tue, 28 May 2024 21:41:59 +1000 Subject: [PATCH 4/4] updated internal and external preview's show and hide logic --- Flow.Launcher/MainWindow.xaml | 4 +- Flow.Launcher/MainWindow.xaml.cs | 2 +- Flow.Launcher/ViewModel/MainViewModel.cs | 107 ++++++++++++++++------- 3 files changed, 79 insertions(+), 34 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index 88e95aa69..7be2f667d 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -399,7 +399,7 @@ + Visibility="{Binding InternalPreviewVisible, Converter={StaticResource BoolToVisibilityConverter}}">