mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
remove QuickLook plugin test project
This commit is contained in:
parent
25963ea2d9
commit
7f31fefe98
8 changed files with 21 additions and 474 deletions
|
|
@ -5,18 +5,17 @@ MinimumVisualStudioVersion = 10.0.40219.1
|
|||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Flow.Launcher", "Flow.Launcher\Flow.Launcher.csproj", "{DB90F671-D861-46BB-93A3-F1304F5BA1C5}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{0B9DE348-9361-4940-ADB6-F5953BFFCCEC} = {0B9DE348-9361-4940-ADB6-F5953BFFCCEC}
|
||||
{403B57F2-1856-4FC7-8A24-36AB346B763E} = {403B57F2-1856-4FC7-8A24-36AB346B763E}
|
||||
{4792A74A-0CEA-4173-A8B2-30E6764C6217} = {4792A74A-0CEA-4173-A8B2-30E6764C6217}
|
||||
{5043CECE-E6A7-4867-9CBE-02D27D83747A} = {5043CECE-E6A7-4867-9CBE-02D27D83747A}
|
||||
{588088F4-3262-4F9F-9663-A05DE12534C3} = {588088F4-3262-4F9F-9663-A05DE12534C3}
|
||||
{59BD9891-3837-438A-958D-ADC7F91F6F7E} = {59BD9891-3837-438A-958D-ADC7F91F6F7E}
|
||||
{758F3331-8D38-49F9-913C-60A18A8AEF3B} = {758F3331-8D38-49F9-913C-60A18A8AEF3B}
|
||||
{9B130CC5-14FB-41FF-B310-0A95B6894C37} = {9B130CC5-14FB-41FF-B310-0A95B6894C37}
|
||||
{A3DCCBCA-ACC1-421D-B16E-210896234C26} = {A3DCCBCA-ACC1-421D-B16E-210896234C26}
|
||||
{C21BFF9C-2C99-4B5F-B7C9-A5E6DDDB37B0} = {C21BFF9C-2C99-4B5F-B7C9-A5E6DDDB37B0}
|
||||
{F9C4C081-4CC3-4146-95F1-E102B4E10A5F} = {F9C4C081-4CC3-4146-95F1-E102B4E10A5F}
|
||||
{FDB3555B-58EF-4AE6-B5F1-904719637AB4} = {FDB3555B-58EF-4AE6-B5F1-904719637AB4}
|
||||
{F9C4C081-4CC3-4146-95F1-E102B4E10A5F} = {F9C4C081-4CC3-4146-95F1-E102B4E10A5F}
|
||||
{59BD9891-3837-438A-958D-ADC7F91F6F7E} = {59BD9891-3837-438A-958D-ADC7F91F6F7E}
|
||||
{C21BFF9C-2C99-4B5F-B7C9-A5E6DDDB37B0} = {C21BFF9C-2C99-4B5F-B7C9-A5E6DDDB37B0}
|
||||
{9B130CC5-14FB-41FF-B310-0A95B6894C37} = {9B130CC5-14FB-41FF-B310-0A95B6894C37}
|
||||
{FDED22C8-B637-42E8-824A-63B5B6E05A3A} = {FDED22C8-B637-42E8-824A-63B5B6E05A3A}
|
||||
{A3DCCBCA-ACC1-421D-B16E-210896234C26} = {A3DCCBCA-ACC1-421D-B16E-210896234C26}
|
||||
{5043CECE-E6A7-4867-9CBE-02D27D83747A} = {5043CECE-E6A7-4867-9CBE-02D27D83747A}
|
||||
{403B57F2-1856-4FC7-8A24-36AB346B763E} = {403B57F2-1856-4FC7-8A24-36AB346B763E}
|
||||
{588088F4-3262-4F9F-9663-A05DE12534C3} = {588088F4-3262-4F9F-9663-A05DE12534C3}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Flow.Launcher.Test", "Flow.Launcher.Test\Flow.Launcher.Test.csproj", "{FF742965-9A80-41A5-B042-D6C7D3A21708}"
|
||||
|
|
@ -72,8 +71,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Flow.Launcher.Plugin.Plugin
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Flow.Launcher.Plugin.WindowsSettings", "Plugins\Flow.Launcher.Plugin.WindowsSettings\Flow.Launcher.Plugin.WindowsSettings.csproj", "{5043CECE-E6A7-4867-9CBE-02D27D83747A}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Flow.Launcher.Plugin.QuickLook", "plugins\Flow.Launcher.Plugin.QuickLook\Flow.Launcher.Plugin.QuickLook.csproj", "{758F3331-8D38-49F9-913C-60A18A8AEF3B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
|
@ -84,19 +81,8 @@ Global
|
|||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Release|x64.Build.0 = Release|Any CPU
|
||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Release|x86.Build.0 = Release|Any CPU
|
||||
{FF742965-9A80-41A5-B042-D6C7D3A21708}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FF742965-9A80-41A5-B042-D6C7D3A21708}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FF742965-9A80-41A5-B042-D6C7D3A21708}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{FF742965-9A80-41A5-B042-D6C7D3A21708}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{FF742965-9A80-41A5-B042-D6C7D3A21708}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
|
|
@ -119,6 +105,18 @@ Global
|
|||
{8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|x64.Build.0 = Release|Any CPU
|
||||
{8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|x86.Build.0 = Release|Any CPU
|
||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Release|x64.Build.0 = Release|Any CPU
|
||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Release|x86.Build.0 = Release|Any CPU
|
||||
{4FD29318-A8AB-4D8F-AA47-60BC241B8DA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4FD29318-A8AB-4D8F-AA47-60BC241B8DA3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4FD29318-A8AB-4D8F-AA47-60BC241B8DA3}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
|
|
@ -288,18 +286,6 @@ Global
|
|||
{5043CECE-E6A7-4867-9CBE-02D27D83747A}.Release|x64.Build.0 = Release|Any CPU
|
||||
{5043CECE-E6A7-4867-9CBE-02D27D83747A}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{5043CECE-E6A7-4867-9CBE-02D27D83747A}.Release|x86.Build.0 = Release|Any CPU
|
||||
{758F3331-8D38-49F9-913C-60A18A8AEF3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{758F3331-8D38-49F9-913C-60A18A8AEF3B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{758F3331-8D38-49F9-913C-60A18A8AEF3B}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{758F3331-8D38-49F9-913C-60A18A8AEF3B}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{758F3331-8D38-49F9-913C-60A18A8AEF3B}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{758F3331-8D38-49F9-913C-60A18A8AEF3B}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{758F3331-8D38-49F9-913C-60A18A8AEF3B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{758F3331-8D38-49F9-913C-60A18A8AEF3B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{758F3331-8D38-49F9-913C-60A18A8AEF3B}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{758F3331-8D38-49F9-913C-60A18A8AEF3B}.Release|x64.Build.0 = Release|Any CPU
|
||||
{758F3331-8D38-49F9-913C-60A18A8AEF3B}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{758F3331-8D38-49F9-913C-60A18A8AEF3B}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
@ -317,7 +303,6 @@ Global
|
|||
{588088F4-3262-4F9F-9663-A05DE12534C3} = {3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87}
|
||||
{4792A74A-0CEA-4173-A8B2-30E6764C6217} = {3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87}
|
||||
{5043CECE-E6A7-4867-9CBE-02D27D83747A} = {3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87}
|
||||
{758F3331-8D38-49F9-913C-60A18A8AEF3B} = {3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {F26ACB50-3F6C-4907-B0C9-1ADACC1D0DED}
|
||||
|
|
|
|||
|
|
@ -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.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Library</OutputType>
|
||||
<TargetFramework>net7.0-windows</TargetFramework>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<Nullable>warnings</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<!--<OutputPath>\Output\Debug\Plugins\Flow.Launcher.Plugin.QuickLook</OutputPath>-->
|
||||
<OutputPath>..\..\Output\Debug\Plugins\Flow.Launcher.Plugin.QuickLook</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<!--<OutputPath>\Output\Release\Plugins\Flow.Launcher.Plugin.QuickLook</OutputPath>-->
|
||||
<OutputPath>..\..\Output\Release\Plugins\Flow.Launcher.Plugin.QuickLook</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!--<PackageReference Include="Flow.Launcher.Plugin" Version="4.3.0" />-->
|
||||
<ProjectReference Include="..\..\Flow.Launcher.Plugin\Flow.Launcher.Plugin.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="plugin.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<Content Include="Images\*.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Languages\en.xaml" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="Languages\en.xaml">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Images\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -1,154 +0,0 @@
|
|||
using System;
|
||||
using System.IO.Pipes;
|
||||
using System.IO;
|
||||
using System.Security.Principal;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Flow.Launcher.Plugin.QuickLook.Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Adapted from Files
|
||||
/// https://github.com/files-community/Files/blob/ad33c75c53382fcb9b16fa9cd66ae5399f3dff0b/src/Files.App/Helpers/QuickLookHelpers.cs
|
||||
/// </summary>
|
||||
internal static class QuickLookHelper
|
||||
{
|
||||
private static readonly IPublicAPI api = Main.Context.API;
|
||||
|
||||
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 e)
|
||||
{
|
||||
client.Close();
|
||||
api.LogException($"{nameof(QuickLookHelper)}", "QuickLook timeout", e);
|
||||
return false;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
api.LogException($"{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();
|
||||
api.LogException($"{nameof(QuickLookHelper)}", "QuickLook connection timeout", e);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var result = await QuickLookServerAvailable();
|
||||
return result != 0;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
api.LogException($"{nameof(QuickLookHelper)}", "QuickLook unavailable", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void ShowQuickLookUnavailableToast()
|
||||
{
|
||||
if (lastNotificationTime.AddSeconds(10) < DateTime.Now)
|
||||
{
|
||||
api.ShowMsgError(api.GetTranslation("quicklook_failed_to_launch"), api.GetTranslation("quicklook_fail_tips"));
|
||||
lastNotificationTime = DateTime.Now;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 40 KiB |
|
|
@ -1,14 +0,0 @@
|
|||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:system="clr-namespace:System;assembly=mscorlib">
|
||||
|
||||
<!-- Plugin Infos -->
|
||||
<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>
|
||||
<system:String x:Key="quicklook_fail_tips">Please check if QuickLook is running.</system:String>
|
||||
|
||||
</ResourceDictionary>
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Flow.Launcher.Plugin.QuickLook.Helpers;
|
||||
|
||||
namespace Flow.Launcher.Plugin.QuickLook
|
||||
{
|
||||
public class Main : IAsyncPlugin, IAsyncExternalPreview, IPluginI18n
|
||||
{
|
||||
internal static PluginInitContext Context { get; set; }
|
||||
|
||||
public Task InitAsync(PluginInitContext context)
|
||||
{
|
||||
Context = context;
|
||||
|
||||
// prompt quicklook install if not found?
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task TogglePreviewAsync(string path)
|
||||
{
|
||||
await QuickLookHelper.ToggleQuickLookAsync(path).ConfigureAwait(false);
|
||||
}
|
||||
public async Task ClosePreviewAsync()
|
||||
{
|
||||
await QuickLookHelper.CloseQuickLookAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task SwitchPreviewAsync(string path, bool sendFailToast = true)
|
||||
{
|
||||
await QuickLookHelper.SwitchQuickLookAsync(path, sendFailToast).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task OpenPreviewAsync(string path, bool sendFailToast = true)
|
||||
{
|
||||
await QuickLookHelper.OpenQuickLookAsync(path, sendFailToast).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
public string GetTranslatedPluginDescription()
|
||||
{
|
||||
return Context.API.GetTranslation("plugin_description");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
{
|
||||
"ID": "e6a13bf1-5op9-2b96-a7fd-130b7vdt3d14",
|
||||
"ActionKeywords": [ "*" ],
|
||||
"Name": "QuickLook",
|
||||
"Description": "Use QuickLook to preview files",
|
||||
"Author": "Flow Launcher",
|
||||
"Version": "1.0.0",
|
||||
"Language": "csharp",
|
||||
"Website": "https://github.com/Flow-Launcher/Flow.Launcher.Plugin.QuickLook",
|
||||
"ExecuteFileName": "Flow.Launcher.Plugin.QuickLook.dll",
|
||||
"IcoPath": "Images\\app.png"
|
||||
}
|
||||
Loading…
Reference in a new issue