From dc3da38c3408655e0f5fa56ad1815fefe15f042a Mon Sep 17 00:00:00 2001 From: ema Date: Mon, 17 Nov 2025 04:17:00 +0800 Subject: [PATCH] Add blocked file type handling to viewer Updates the InsvBlocker plugin to mark files as blocked and sets a blocked message in the viewer window. The viewer now displays a message for blocked file types instead of attempting to preview them. --- QuickLook.Common | 2 +- .../QuickLook.Plugin.InsvBlocker/Plugin.cs | 27 +++++-------------- QuickLook/ViewerWindow.Actions.cs | 13 +++++++++ 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/QuickLook.Common b/QuickLook.Common index ffda897..709f26f 160000 --- a/QuickLook.Common +++ b/QuickLook.Common @@ -1 +1 @@ -Subproject commit ffda8978fad9525e18f5d0c3e74d482cc764d48c +Subproject commit 709f26fa389b62f685a48e97f6ba33ca217a035e diff --git a/QuickLook.Plugin/QuickLook.Plugin.InsvBlocker/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.InsvBlocker/Plugin.cs index 9dafc70..ddfe213 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.InsvBlocker/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.InsvBlocker/Plugin.cs @@ -45,31 +45,16 @@ public class Plugin : IViewer public void Prepare(string path, ContextObject context) { - // Set a minimal window size (1x1 pixels) to make the window as small as possible - // This window will be closed immediately in View() before becoming visible - context.PreferredSize = new Size { Width = 1, Height = 1 }; + // Set Ignore to true to display "blocked" in the preview window + context.IsBlocked = true; + context.Title = $"[BLOCKED] {Path.GetFileName(path)}"; + context.PreferredSize = new Size(400, 200); } public void View(string path, ContextObject context) { - // Create an empty text block as content (required to avoid errors) - var textBlock = new TextBlock - { - Text = "", - Visibility = Visibility.Collapsed - }; - context.ViewerContent = textBlock; - context.IsBusy = false; - - // Close the window immediately using Send priority for immediate execution - // This prevents the window from becoming visible to the user - Application.Current?.Dispatcher?.BeginInvoke(new Action(() => - { - if (context.Source is Window window) - { - window.Close(); - } - }), DispatcherPriority.Send); + // This should not be called since Ignore is set to true in Prepare + // But if called, do nothing } public void Cleanup() diff --git a/QuickLook/ViewerWindow.Actions.cs b/QuickLook/ViewerWindow.Actions.cs index db3a85f..e133a19 100644 --- a/QuickLook/ViewerWindow.Actions.cs +++ b/QuickLook/ViewerWindow.Actions.cs @@ -201,6 +201,19 @@ public partial class ViewerWindow return; } + if (ContextObject.IsBlocked) + { + ContextObject.ViewerContent = new System.Windows.Controls.TextBlock + { + Text = "This file type is blocked.", + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + FontSize = 14, + }; + ContextObject.IsBusy = false; + return; + } + SetOpenWithButtonAndPath(); // Revert UI changes