remove QuickLook related code from flow

This commit is contained in:
Jeremy 2024-05-29 16:12:04 +10:00
parent 70e530bde3
commit 493a30e6c1
5 changed files with 3 additions and 199 deletions

View file

@ -81,8 +81,6 @@
<system:String x:Key="ShouldUsePinyinToolTip">Allows using Pinyin to search. Pinyin is the standard system of romanized spelling for translating Chinese.</system:String>
<system:String x:Key="AlwaysPreview">Always Preview</system:String>
<system:String x:Key="AlwaysPreviewToolTip">Always open preview panel when Flow activates. Press {0} to toggle preview.</system:String>
<system:String x:Key="UseQuickLook">Use QuickLook</system:String>
<system:String x:Key="UseQuickLookToolTip">Use QuickLook to preview file results.</system:String>
<system:String x:Key="shadowEffectNotAllowed">Shadow effect is not allowed while current theme has blur effect enabled</system:String>
<!-- Setting Plugin -->
@ -318,8 +316,6 @@
<!-- General Notice -->
<system:String x:Key="pleaseWait">Please wait...</system:String>
<system:String x:Key="QuickLookFail">Failed to launch QuickLook</system:String>
<system:String x:Key="QuickLookFailTips">Please check if QuickLook is running.</system:String>
<!-- Update -->
<system:String x:Key="update_flowlauncher_update_check">Checking for new update</system:String>

View file

@ -859,24 +859,6 @@
</ItemsControl>
</Border>
<Border Style="{DynamicResource SettingGroupBox}">
<ItemsControl Style="{StaticResource SettingGrid}">
<StackPanel Style="{StaticResource TextPanel}">
<TextBlock Style="{DynamicResource SettingTitleLabel}" Text="{DynamicResource UseQuickLook}" />
<TextBlock Style="{DynamicResource SettingSubTitleLabel}" Text="{DynamicResource UseQuickLookToolTip}" />
</StackPanel>
<ui:ToggleSwitch
Grid.Column="2"
FocusVisualMargin="5"
IsOn="{Binding Settings.UseExternalPreview}"
Style="{DynamicResource SideToggleSwitch}"
ToolTip="{DynamicResource UseQuickLookToolTip}" />
<TextBlock Style="{StaticResource Glyph}">
&#xe773;
</TextBlock>
</ItemsControl>
</Border>
<Border Margin="0,30,0,0" Style="{DynamicResource SettingGroupBox}">
<ItemsControl Style="{StaticResource SettingGrid}">
<StackPanel Style="{StaticResource TextPanel}">

View file

@ -1,153 +0,0 @@
// Adapted from Files
// https://github.com/files-community/Files/blob/ad33c75c53382fcb9b16fa9cd66ae5399f3dff0b/src/Files.App/Helpers/QuickLookHelpers.cs
using System;
using System.IO.Pipes;
using System.IO;
using System.Security.Principal;
using System.Threading.Tasks;
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Core.Resource;
namespace Flow.Launcher.Plugin.Explorer.Helper
{
internal static class QuickLookHelper
{
private const int TIMEOUT = 500;
private static DateTime lastNotificationTime = DateTime.MinValue;
private static readonly string pipeName = $"QuickLook.App.Pipe.{WindowsIdentity.GetCurrent().User?.Value}";
private static readonly string pipeMessageSwitch = "QuickLook.App.PipeMessages.Switch";
private static readonly string pipeMessageToggle = "QuickLook.App.PipeMessages.Toggle";
private static readonly string pipeMessageClose = "QuickLook.App.PipeMessages.Close";
private static readonly string pipeMessageInvoke = "QuickLook.App.PipeMessages.Invoke";
/// <summary>
/// Toggle QuickLook
/// </summary>
/// <param name="path">File path to preview</param>
/// <param name="sendFailToast">Send toast when fails.</param>
/// <returns></returns>
public static async Task<bool> ToggleQuickLookAsync(string path, bool sendFailToast = true)
{
if (string.IsNullOrEmpty(path))
return false;
bool success = await SendQuickLookPipeMsgAsync(pipeMessageToggle, path);
if (sendFailToast && !success)
{
//ShowQuickLookUnavailableToast();
}
return success;
}
public static async Task<bool> CloseQuickLookAsync()
{
bool success = await SendQuickLookPipeMsgAsync(pipeMessageClose);
return success;
}
public static async Task<bool> OpenQuickLookAsync(string path, bool sendFailToast = true)
{
if (string.IsNullOrEmpty(path))
return false;
bool success = await SendQuickLookPipeMsgAsync(pipeMessageInvoke, path);
if (sendFailToast && !success)
{
//ShowQuickLookUnavailableToast();
}
return success;
}
/// <summary>
/// Switch QuickLook to preview another file if it's on
/// </summary>
/// <param name="path">File path to preview</param>
/// <param name="sendFailToast">Send notification if fail</param>
/// <returns></returns>
public static async Task<bool> SwitchQuickLookAsync(string path, bool sendFailToast = true)
{
if (string.IsNullOrEmpty(path))
return false;
bool success = await SendQuickLookPipeMsgAsync(pipeMessageSwitch, path);
if (sendFailToast && !success)
{
//ShowQuickLookUnavailableToast();
}
return success;
}
private static async Task<bool> SendQuickLookPipeMsgAsync(string message, string arg = "")
{
await using var client = new NamedPipeClientStream(".", pipeName, PipeDirection.Out);
try
{
await client.ConnectAsync(TIMEOUT);
await using var writer = new StreamWriter(client);
await writer.WriteLineAsync($"{message}|{arg}");
await writer.FlushAsync();
}
catch (TimeoutException)
{
client.Close();
Log.Error($"{nameof(QuickLookHelper)}", "QuickLook timeout");
return false;
}
catch (Exception e)
{
Log.Exception($"{nameof(QuickLookHelper)}", "QuickLook error", e);
return false;
}
return true;
}
public static async Task<bool> DetectQuickLookAvailabilityAsync()
{
static async Task<int> QuickLookServerAvailable()
{
await using var client = new NamedPipeClientStream(".", pipeName, PipeDirection.Out);
try
{
await client.ConnectAsync(TIMEOUT);
var serverInstances = client.NumberOfServerInstances;
await using var writer = new StreamWriter(client);
await writer.WriteLineAsync($"{pipeMessageSwitch}|");
await writer.FlushAsync();
return serverInstances;
}
catch (TimeoutException e)
{
client.Close();
Log.Exception($"{nameof(QuickLookHelper)}", "QuickLook connection timeout", e);
return 0;
}
}
try
{
var result = await QuickLookServerAvailable();
return result != 0;
}
catch (Exception e)
{
Log.Exception($"{nameof(QuickLookHelper)}", "QuickLook unavailable", e);
return false;
}
}
private static void ShowQuickLookUnavailableToast()
{
if (lastNotificationTime.AddSeconds(10) < DateTime.Now)
{
//Notification.Show(InternationalizationManager.Instance.GetTranslation("QuickLookFail"),
// InternationalizationManager.Instance.GetTranslation("QuickLookFailTips"));
lastNotificationTime = DateTime.Now;
}
}
}
}

View file

@ -14,7 +14,7 @@ using Flow.Launcher.Plugin.Explorer.Exceptions;
namespace Flow.Launcher.Plugin.Explorer
{
public class Main : ISettingProvider, IAsyncPlugin, IContextMenu, IPluginI18n, IAsyncExternalPreview
public class Main : ISettingProvider, IAsyncPlugin, IContextMenu, IPluginI18n
{
internal static PluginInitContext Context { get; set; }
@ -87,27 +87,6 @@ namespace Flow.Launcher.Plugin.Explorer
}
}
public async Task TogglePreviewAsync(string path)
{
bool success = await QuickLookHelper.ToggleQuickLookAsync(path).ConfigureAwait(false);
}
public async Task ClosePreviewAsync()
{
bool success = await QuickLookHelper.CloseQuickLookAsync().ConfigureAwait(false);
}
public async Task SwitchPreviewAsync(string path, bool sendFailToast = true)
{
// Switches preview content
// When external is off, do nothing
_ = QuickLookHelper.SwitchQuickLookAsync(path, sendFailToast).ConfigureAwait(false);
}
public async Task OpenPreviewAsync(string path, bool sendFailToast = true)
{
bool success = await QuickLookHelper.OpenQuickLookAsync(path, sendFailToast).ConfigureAwait(false);
}
public string GetTranslatedPluginTitle()
{
return Context.API.GetTranslation("plugin_explorer_plugin_name");

View file

@ -4,8 +4,8 @@
xmlns:system="clr-namespace:System;assembly=mscorlib">
<!-- Plugin Infos -->
<system:String x:Key="plugin_name">Explorer</system:String>
<system:String x:Key="plugin_description">Find and manage files and folders via Windows Search or Everything</system:String>
<system:String x:Key="plugin_name">QuickLook</system:String>
<system:String x:Key="plugin_description">Use QuickLook to preview files</system:String>
<!-- Notifications -->
<system:String x:Key="quicklook_failed_to_launch">Failed to launch QuickLook</system:String>