Skip to content

Feature: Removed QuickLookHandler #9985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Sep 15, 2022
Merged
1 change: 0 additions & 1 deletion src/Files.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ await Task.WhenAll(
SidebarPinnedController.InitializeAsync()
);
await Task.WhenAll(
AppSettings.DetectQuickLook(),
TerminalController.InitializeAsync(),
JumpList.InitializeAsync(),
ExternalResourcesHelper.LoadOtherThemesAsync(),
Expand Down
8 changes: 4 additions & 4 deletions src/Files.App/DataModels/AppModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ public bool MultiselectEnabled
set => SetProperty(ref multiselectEnabled, value);
}

private bool isQuickLookSupported;
public bool IsQuickLookSupported
private bool isQuickLookAvailable;
public bool IsQuickLookAvailable
{
get => isQuickLookSupported;
set => SetProperty(ref isQuickLookSupported, value);
get => isQuickLookAvailable;
set => SetProperty(ref isQuickLookAvailable, value);
}

private FontFamily symbolFontFamily;
Expand Down
106 changes: 75 additions & 31 deletions src/Files.App/Helpers/QuickLookHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,79 @@
using Files.Shared.Extensions;
using System.Diagnostics;
using System;
using System.IO;
using System.IO.Pipes;
using System.Security.Principal;
using System.Threading.Tasks;
using Windows.Foundation.Collections;

namespace Files.App.Helpers
namespace Files.App.Helpers;

public static class QuickLookHelpers
{
public static class QuickLookHelpers
{
public static async Task ToggleQuickLook(IShellPage associatedInstance, bool switchPreview = false)
{
if (!App.AppModel.IsQuickLookSupported || !associatedInstance.SlimContentPage.IsItemSelected || associatedInstance.SlimContentPage.IsRenamingItem)
{
return;
}

await SafetyExtensions.IgnoreExceptions(async () =>
{
Debug.WriteLine("Toggle QuickLook");
var connection = await AppServiceConnectionHelper.Instance;

if (connection != null)
{
await connection.SendMessageAsync(new ValueSet()
{
{ "path", associatedInstance.SlimContentPage.SelectedItem.ItemPath },
{ "switch", switchPreview },
{ "Arguments", "ToggleQuickLook" }
});
}

}, App.Logger);
}
}
private const int TIMEOUT = 500;

public static async Task ToggleQuickLook(IShellPage associatedInstance, bool switchPreview = false)
{
if (!associatedInstance.SlimContentPage.IsItemSelected || associatedInstance.SlimContentPage.IsRenamingItem)
return;

App.AppModel.IsQuickLookAvailable = await DetectQuickLookAvailability();

if (App.AppModel.IsQuickLookAvailable == false)
return;

string pipeName = $"QuickLook.App.Pipe.{WindowsIdentity.GetCurrent().User?.Value}";
string message = switchPreview ? "QuickLook.App.PipeMessages.Switch" : "QuickLook.App.PipeMessages.Toggle";

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}|{associatedInstance.SlimContentPage.SelectedItem.ItemPath}");
await writer.FlushAsync();
}
catch (TimeoutException)
{
client.Close();
}
}

private static async Task<bool> DetectQuickLookAvailability()
{
static async Task<int> QuickLookServerAvailable()
{
string pipeName = $"QuickLook.App.Pipe.{WindowsIdentity.GetCurrent().User?.Value}";
string pipeSwitch = "QuickLook.App.PipeMessages.Switch";

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($"{pipeSwitch}|");
await writer.FlushAsync();

return serverInstances;
}
catch (TimeoutException)
{
client.Close();
return 0;
}
}

try
{
var result = await QuickLookServerAvailable();
App.Logger.Info($"QuickLook detected: {result != 0}");
return result != 0;
}
catch (Exception ex)
{
App.Logger.Info(ex, ex.Message);
return false;
}
}
}
24 changes: 0 additions & 24 deletions src/Files.App/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,6 @@ public SettingsViewModel()
UpdateThemeElements = new RelayCommand(() => ThemeModeChanged?.Invoke(this, EventArgs.Empty));
}

public async Task DetectQuickLook()
{
// Detect QuickLook
try
{
var connection = await AppServiceConnectionHelper.Instance;
if (connection != null)
{
var (status, response) = await connection.SendMessageForResponseAsync(new ValueSet()
{
{ "Arguments", "DetectQuickLook" }
});
if (status == AppServiceResponseStatus.Success)
{
App.AppModel.IsQuickLookSupported = response.Get("IsAvailable", defaultJson).GetBoolean();
}
}
}
catch (Exception ex)
{
App.Logger.Warn(ex, ex.Message);
}
}

private void DetectDateTimeFormat()
{
if (localSettings.Values[Constants.LocalSettings.DateTimeFormat] != null)
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Views/LayoutModes/ColumnViewBase.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ private async void FileList_SelectionChanged(object sender, SelectionChangedEven
{
SelectedItems = FileList.SelectedItems.Cast<ListedItem>().Where(x => x != null).ToList();

if (SelectedItems.Count == 1)
if (SelectedItems.Count == 1 && App.AppModel.IsQuickLookAvailable)
await QuickLookHelpers.ToggleQuickLook(ParentShellPageInstance, true);
}

Expand Down
Loading